Help with I2C Read for LSM303DLHC #223
-
The following is the table for the transaction. The ESP32 is setup as a master. The code I have written is shown below. The problem I am facing is that although I am able to read the slave addresses, I cannot read or write to the registers correctly. I receive invalid data when I try to read or write to the registers. Would someone be able to suggest anything to help perform the successful read? Thank you very much in advance CODE FOR I2C READ |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I answered my own question here. Using the i2ctools.c example, I was able to successfully read and write to device. For anyone interested, the code is shown below: dev->addr is the address of the accelerometer (0x19), and when shifted one to the left, sets the address for the ACCELEROMETER_READ and ACCELEROMETER_WRITE commands as 0x33 and 0x32 respectively. I2C READ
I2C WRITE
|
Beta Was this translation helpful? Give feedback.
I answered my own question here. Using the i2ctools.c example, I was able to successfully read and write to device. For anyone interested, the code is shown below:
dev->addr is the address of the accelerometer (0x19), and when shifted one to the left, sets the address for the ACCELEROMETER_READ and ACCELEROMETER_WRITE commands as 0x33 and 0x32 respectively.
I2C_AUTO_INCREMENT is a macro defined as 0x80, because as mentioned in the datasheet, when the MSB of a register is set, the registers will autoincrement when performing read or write commands.
I2C READ