I am trying to read the magnetometer data off the ST LIS3MDL using the pigpio library I2C library in C++, which requires me to read multiple consecutive registers. Each register is a byte, and each axis is 2 bytes, so I need to read 6 bytes from consecutive registers (OUT_X_L, OUT_X_H...).
I can write single and multiple bytes and read a single byte, but my read from these 6 consecutive registers seem to never update, i.e. they print the exact same data read after read. My arduino code shows that the data should update frequently so my sensor is not toast ( I have also changed up multiple sensors already). I have narrowed it down (maybe) to the fact that reading multiple bytes from the LIS3MDL requires the code to send a master-acknowledge upon receiving each byte (reference pg 18 in datasheet):
1. so does pigpio I2C C library send a master acknowledge upon receiving each byte, either on i2cReadDevice / i2cReadByte and all the other i2cRead.... functions?
2. Likewise, does anyone have any code to share / or any pointers for my code below on how to read the LIS3MDL mag registers (multiple consecutive byte reads)?
int handle, temp;
handle = i2cOpen(1, m_Address, 0);
// assert MSB to auto-increment register address
temp = i2cWriteByte(handle, OUT_X_L | 0x80); //
i2cSwitchCombined(1); // repeated start ON
temp = i2cReadDevice(handle, buf, 6); // read six bytes: xlm, xhm, ylm, yhm, zlm, zhm
i2cSwitchCombined(0); // repeated start OFF
temp = i2cClose(handle);
// combine lo and high bytes
m_Mag.x = (int16_t)( (buf << 8) | buf);
m_Mag.y = (int16_t)( (buf << 8) | buf);
m_Mag.z = (int16_t)( (buf << 8) | buf);