Reading data from LSM6DS33 , I2C

Edyta Bosacka <edyta.bosacka@...>
 

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);
    if(err){
        printk("I2C transfer error");
    }
    printk("I am: %s \n"data[0]);

Join users@lists.zephyrproject.org to automatically receive all group messages.