I've just finished implementing a successful read from an ADXL345 accelerometer from a PIC microcontroller (dsPIC33) using i2c. All I've achieved so far is reading the device ID correctly, which is a single byte.
Anyone that has used the ADXL345 before will know that to read data from any of the axis, X, Y, or Z, is broken into two bytes, 'DATAX0' and 'DATAX1' for example. The datasheet also specifically states 'To ensure data coherency, it is recommended that multibyte reads are used to retrieve data from the ADXL345', so the two bytes per axis need to be collected together.
My question is, with i2c, how do I do this when the two bytes per axis are represented by two different registers?
The image above shows the process needed for i2c transmission. To read from the accelerometer we're looking at the bottom two graphs, and the datasheet quote I've pasted above is suggesting I used the bottom graph (multiple-Byte), but as I've said the two bytes have two different register values (0x32 and 0x33 for DATAX0 and DATAX1 respectively).
How do I get data from one axis in one grab? The only way I see doing this is a single-byte read with one register address, then doing it again with the second register address, then concating the two together to get the one axis data.
This question also applies to collecting data from a variety of different devices on the same i2c bus, which will also have different registers.
Cheers!
You just do a 2-byte read at 0x32, and the device will put the values from 0x32 and 0x33 in its response.