-
• #2
Not all I2C devices automatically increment the address like that - take a look at the datasheet...
Edit: Ahha! Here, pg 33, second paragraph:
In order to read multiple bytes, it is necessary to assert the most significant bit of the subaddress field. In other words, SUB(7) must be equal to 1 while SUB(6-0) represents the address of first register to be read.
And in sparkfun's code that's just what they do:
void LSM9DS0::I2CreadBytes(uint8_t address, uint8_t subAddress, uint8_t * dest, uint8_t count) { Wire.beginTransmission(address); // Initialize the Tx buffer // Next send the register to be read. OR with 0x80 to indicate multi-read. Wire.write(subAddress | 0x80); // Put slave register address in Tx buffer Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive uint8_t i = 0; Wire.requestFrom(address, count); // Read bytes from slave register address while (Wire.available()) { dest[i++] = Wire.read(); // Put read results in the Rx buffer } }
-
• #3
Hi,
after my post I re-read the docs to verify that the LSM9DS0 is capable of block reading. Yes it is, but I overlooked something. The MSB of the register to read must be 1 for auto incrementing the address. I will give this a try later and add another post. :)
Thank you.
Edit: hehe you were faster :D
Hi everyone,
Im currently writing a module for Sparkfuns LSM9DS0 9DOF IMU. The IMU is properly wired and works as expected. After some configuration I try to read 6 Bytes from register OUT_X_L_A (0x28). My code looks like the following:
result is an Int8Array of size 6, but it contains 6 equal values. More specific: its the value from OUT_X_L_A and all other registers (OUT_X_L_A+1, OUT_X_L_A+n) won't be read. Something like [ 13, 13, 13, 13, 13, 13 ] instead of [ 13, 28, 90, 54, 77, 1 ].
I have seen many modules for other I2C devices that work this way, but if I do:
it works...Does anyone have an advice for me?
Best regards
otbe
EDIT: Im using a espruino pico with 1v80 firmware. The LSM9DS0 should be capable to send multiple bytes.