Skip to content

Help with I2C Read for LSM303DLHC #223

Answered by BVX486
BVX486 asked this question in Course Qeustions
Discussion options

You must be logged in to vote

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

    if (len > 1)
        reg |= I2C_AUTO_INCREMENT;
    i2c_cmd_handle_t cmd = i2c_cmd_link_create();                        // Create…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by BVX486
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant