Hi,
I am checking the i2c protocol with nRF Connect SDK and Zephyr through VSCode.
I created a very simple example where I push a button on the nRF52840 DK and I get the ID of an IMU sensor which is 0xEA.
When I use the i2c_write_dt() and i2c_read_dt() functions, I get the ID as expected (first code):
LED TOGGLE
Who Am I: EA
uint8_t wArray[1] = {0x00}; // Register address to read from uint8_t rBuff = 0x00; // Buffer to store the read value uint8_t a = 0; a = i2c_write_dt(&m_i2c, wArray, 1); if (a != 0) { printk("I2C write failed with error %d\n", a); } a = i2c_read_dt(&m_i2c, &rBuff, 1); if (a != 0) { printk("I2C read failed with error %d\n", a); } printk("Who Am I: %X\n", rBuff);
when I use the i2c_write_read_dt(), I get an error from the function
LED TOGGLE
I2C error 251
Who Am I: 0
uint8_t wBuff[1] = {0x00}; uint8_t rBuff = 0x00; uint8_t a = 0; a = i2c_write_read_dt(&m_i2c, wBuff, sizeof(wBuff), &rBuff, sizeof(rBuff)); if(a!= 0){printk("I2C error %d\n", a);} printk("Who Am I: %X\n", rBuff[0]);
Shouldn't the two cases work the same way? Am I missing something?
Thank you!