Hi all,
I can´t find anything else about this, so I am not sure if it has already been talked about.
I can't use the i2c_master library to write and read from specific registers from slave devices, there is no field to write the register address on the i2c_master's API's. On the other hand, I2C legacy has a way to write to specific register by simply including the register address inside the handle created using i2c_cmd_link_create(), but from the documentation it is said that the legacy driver is deprecated and will be removed in the future, so it's not a good option for me.
My question is, is there a way to use the i2c_master library's API to write to specific register on a slave device, or do i need to stick to the legacy driver and just import it in my projects on newer versions of the IDE from old versions of the IDE?
Thanks in advance
Michael
i2c_master and I2C legacy
-
MicroController
- Posts: 2673
- Joined: Mon Oct 17, 2022 7:38 pm
- Location: Europe, Germany
Re: i2c_master and I2C legacy
You can just include the register to write to as the first byte of the data you pass to i2c_master_transmit(), like
Code: Select all
uint8_t write_buffer[2];
write_buffer[0] = registerNumber;
write_buffer[1] = byteToWrite;
esp_err_t r = i2c_master_transmit(myDevice, write_buffer, sizeof(write_buffer), portMAX_DELAY);
Who is online
Users browsing this forum: Bytespider, Google [Bot], trendictionbot and 6 guests