BNO055 I2C operation problem

User avatar
maksyuki
Posts: 1
Joined: Tue Feb 05, 2019 3:25 am

BNO055 I2C operation problem

Postby maksyuki » Wed Mar 13, 2019 12:22 pm

Hi, I recently use the sensor BNO055 and cannot read right data from it by using I2C driver of esp32-idf(version:3.1.3). But when I use the Adafruit BNO055 example(arduino 3rd party library provide) and arduino-esp32 library to compile and flash the program by using Arduino IDE, the right data can be read. The hardware and circuit connection is same, so I think the hardware have no problem. I read the BNO055's datasheet and I find it support I2C clock stretching operation. To find the error, I write the test codes which read the BNO055 device chip id using arduino-esp32 library and esp32-idf(version:3.13) respectively. First, the right read timing sequence by using arduino-esp32 library is as shown below:
arduino_i2c_1.png
arduino_i2c_1.png (11.89 KiB) Viewed 94 times
Second, the I2C config code using esp32-idf(version:3.1.3) is as shown below:

Code: Select all

    i2c_config_t conf;
    conf.mode             = I2C_MODE_MASTER;
    conf.sda_io_num       = sda_pin; //sda_pin is 21
    conf.sda_pullup_en    = GPIO_PULLUP_ENABLE;
    conf.scl_io_num       = scl_pin; //scl_pin is 22
    conf.scl_pullup_en    = GPIO_PULLUP_ENABLE;
    conf.master.clk_speed = clk_frq; //clk_frq is 100000
    i2c_param_config(i2c_port, &conf); //i2c_port=I2C_NUM_1
    i2c_driver_install(i2c_port, conf.mode, I2C_NUM1_MASTER_RX_BUF_DISABLE, I2C_NUM1_MASTER_TX_BUF_DISABLE, 0); //i2c_port=I2C_NUM_1
the I2C read BNO055 CHIP ID register code is as shown below:

Code: Select all

    int32_t ret_test = 0;
    uint8_t BNO055_ADDR = 0x28;
    uint8_t BNO055_CHIP_ID = 0x00;
    uint8_t tmp_data = 0x00;

    i2c_cmd_handle_t cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, BNO055_ADDR << 1, MASTER_EN_CHECK_ACK); //MASTER_EN_CHECK_ACK=1
    i2c_master_write_byte(cmd, BNO055_CHIP_ID, MASTER_EN_CHECK_ACK); //MASTER_EN_CHECK_ACK=1
    i2c_master_stop(cmd);
    ret_test = i2c_master_cmd_begin(I2C_NUM1_MASTER_PORT_GPIO, cmd, 1000 / portTICK_RATE_MS); //I2C_NUM1_MASTER_PORT_GPIO=I2C_NUM_1

    cmd = i2c_cmd_link_create();
    i2c_master_start(cmd);
    i2c_master_write_byte(cmd, (BNO055_ADDR<<1) + 1, MASTER_EN_CHECK_ACK); //MASTER_EN_CHECK_ACK=1
    i2c_master_read_byte(cmd, &tmp_data, 0x01);
    i2c_master_stop(cmd);
    ret_test = i2c_master_cmd_begin(I2C_NUM1_MASTER_PORT_GPIO, cmd, 1000 / portTICK_RATE_MS); //I2C_NUM1_MASTER_PORT_GPIO=I2C_NUM_1
    i2c_cmd_link_delete(cmd);
    if(ret_test == ESP_OK)
    {
        printf("the BNO055 id is %#X\n", tmp_data);
    }
    else
    {
        printf("the BNO055 timeout!!!\n");
    }
the error read timing sequence by using esp32-idf(version:3.13) is as shown below:
esp32_i2c_1.png
esp32_i2c_1.png (8.67 KiB) Viewed 94 times
I find the error timing sequence doesn't write the register address after the completion of writing device address. But I don't know what can lead to this error. Please give me some advice if someone have some success over this. Thanks.

Return to “ESP32 IDF”

Who is online

Users browsing this forum: Google [Bot] and 16 guests