The described I2C protocol for reading a specific register (on page 7 of the datasheet) is different of what we expect in general. Instead of writing the register address and then use a RESTART on I2C bus the protocol should be:
but neither respectfull to the datasheet nor working (0xFF instead of 0x00 i think)
I'm not seeing in the Wire library if there is a method of requesting to read a register value. I find requestFrom() method with 5 arguments but it's not working because it still use the "write register address then read" approch.
Do you think it's a limitation of the Wire library ? Is this kind of reading protocol I2C compliant ?
This is how I read one byte from, for example, the MPU-6050:
Wire.beginTransmission(MPU_addr);
Wire.write(0x43); // starting with register 0x43 (GYRO_XOUT_H)
Wire.endTransmission(false);
Wire.requestFrom(MPU_addr, 1); // request a total of 1 byte
byte result = Wire.read();
Useful guide to the Arduino Wire library:
More generally, to read N bytes, I use this function. Note that it does not check for N bytes received. See the discussion in the link above for an explanation.
// utility routines for Wire
// get N bytes of data, starting from address "reg"
void I2C_get(uint8_t I2Caddr, uint8_t reg, uint8_t * buf, uint8_t N) {
Wire.beginTransmission(I2Caddr);
Wire.write(reg);
Wire.endTransmission(false);
Wire.requestFrom(I2Caddr, N);
while (Wire.available()) *buf++ = Wire.read();
}
Hello, thanks for your reply. Yes this is the way i'm dealing with dozens of I2C slaves successfully. This one and also this one (same ?) https://www.kinet-ic.com/uploads/KTD2026-7-04h.pdf performs differently.