Re: Reading data from LSM6DS33 , I2C

Adam Podogrocki


WHO_AM_I_REG should be the third parameter, not forth.


On Thu, 23 Jul 2020 at 16:47, Lawrence King <lawrence.king@...> wrote:

Hi Edyta


Your code doesn’t show what value you used for I2C_ADDR. You will not get an ACK on the I2C bus if you have the wrong I2C addr for the LSM3DS33. Without an ACK, you get a bus error.


I think your I2C_ADDR should be 0x6B.


The WHO_AM_I register in the  LSM3DS33 is 0x0F, not 0xF0.


Lawrence King

Principal Developer



From: users@... <users@...> On Behalf Of Edyta Bosacka
Sent: Thursday, July 23, 2020 9:35 AM
To: users@...
Subject: [Zephyr-users] Reading data from LSM6DS33 , I2C


I am trying to get Who I am data from accelerometer LSM6DS33, but I cannot receive them.  I' m getting this error: I2C transfer errorI am: 0. What can be the reason of this? 


#define LSM6DS33_XG_WHO_AM_I_ADDR                            0xF0


static int i2c_read_byte(struct device *i2c_dev_0uint8_t *datauint32_t num_bytesuint16_t addr ){


    uint8_t wr_addr;

    struct i2c_msg msgs[2];


    /*Register addres*/

    wr_addr = addr;


    /*Setup I2C messages*/


    /*Send the address to read*/

    msgs[0].buf = &wr_addr;

    msgs[0].len = 1U;

    msgs[0].flags = I2C_MSG_WRITE;


    /*read from device*/

    msgs[1].buf = data;

    msgs[1].len = num_bytes;

    msgs[1].flags = I2C_MSG_READ | I2C_MSG_STOP;


    return i2c_transfer(i2c_dev_0, &msgs[0],2I2C_ADDR);





//Read Who i am

    data[0] = 0x00;

    int err = i2c_read_byte(i2c_dev_0, &data[0], 1LSM6DS33_XG_WHO_AM_I_ADDR);


        printk("I2C transfer error");


    printk("I am: %s \n"data[0]);


Join to automatically receive all group messages.