Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 load init using I2C

    BMI270 load init using I2C

    gmorten
    New Poster

    I'm not able to successfully load init data into BMI270 chip using the code below. Since maximum bytes is 255, I load 32 bytes at the time. I get 0x02 as a result from reading 0x21 (status). I do not have any available SPI ports.

    These are the first register readouts:

    24200010000000000000000000000000000000000000000026960101000000000002adff00008000800
    242000100000000000000000000000000000000000000000fcc40100000000000002310000008000800
    242000100000000000000000000000000000000000000000c7f30100000000000002310000008000800
    242000100000000000000000000000000000000000000000a222020000000000000200800000800080
    2420001000000000000000000000000000000000000000007551020000000000000200800000800080

    Any obvious errors? Greatful for any hints or trixes.

    uint16_t i;
    uint16_t j;
    uint32_t err_code;
    uint8_t d[33];
    uint32_t addr;

    nrf_delay_us(500);
    bmi270_write(BMI2_PWR_CONF_ADDR, 0x00); // Power on
    nrf_delay_us(500);

    bmi270_write(BMI2_CMD_REG_ADDR, 0xb6); // Reset
    nrf_delay_ms(500);

    bmi270_write(BMI2_INIT_CTRL_ADDR, 0x00); // init start
    nrf_delay_us(500);

    for(i = 0; i < 256; i++)
    {
    bmi270_write(BMI2_INIT_ADDR_0, 0);
    bmi270_write(BMI2_INIT_ADDR_1, i);

    d[0] = BMI2_INIT_DATA_ADDR;
    addr = i << 5;
    for(j = 0; j < 32; j++)
    {
    d[j+1] = bmi270_config_file[addr + j];
    }

    err_code = nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, d, 33, false);
    nrf_delay_us(500);
    }

    nrf_delay_ms(500);
    bmi270_write(BMI2_INIT_CTRL_ADDR, 0x01);
    nrf_delay_ms(500);

    bmi270_write(BMI2_PWR_CONF_ADDR, 0x00); // Power on
    nrf_delay_us(500);
    bmi270_write(BMI2_PWR_CTRL_ADDR, 0x0e); // Accelerometer and gyroscope on
    nrf_delay_us(500);
    bmi270_write(BMI2_FIFO_CONFIG_1_ADDR, 0x00); // FIFO off
    nrf_delay_us(500);

    bmi270_write(BMI2_PWR_CTRL_ADDR, 0x0e); // Accelerometer and gyroscope on
    bmi270_write(BMI2_ACC_CONF_ADDR, 0xbb); // Performance, Avg32, 100Hz
    bmi270_write(BMI2_ACC_RANGE_ADDR,0x00); // Range +- 2g
    bmi270_write(BMI2_GYR_CONF_ADDR, 0xcb); // Performance, normal operation, 200Hz
    bmi270_write(BMI2_GYR_RANGE_ADDR, 0x04); // Gyre range +- 125dps
    bmi270_write(BMI2_FIFO_DOWNS_ADDR, 0x00); // Filtering off
    bmi270_write(BMI2_FIFO_CONFIG_1_ADDR, 0xd0); // Store acc and Gyro in FIFO

    7 REPLIES 7

    This is working for me now:

    uint16_t i;
    uint16_t j;
    uint32_t err_code;
    uint8_t d[33];
    uint32_t addr;

    nrf_delay_us(1000);
    bmi270_write(BMI2_CMD_REG_ADDR, 0xb6); // Reset
    nrf_delay_ms(500);

    bmi270_write(BMI2_PWR_CONF_ADDR, 0x00); // Power on
    nrf_delay_us(500);

    bmi270_write(BMI2_INIT_CTRL_ADDR, 0x00); // init start
    nrf_delay_us(500);

    for(i = 0; i < 256; i++)
    {
    bmi270_write(BMI2_INIT_ADDR_0, 0);
    bmi270_write(BMI2_INIT_ADDR_1, i);

    d[0] = BMI2_INIT_DATA_ADDR;
    addr = i << 5;
    for(j = 0; j < 32; j++)
    {
    d[j+1] = bmi270_config_file[addr + j];
    }

    err_code = nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, d, 33, false);
    nrf_delay_us(500);
    }

    nrf_delay_ms(500);
    bmi270_write(BMI2_INIT_CTRL_ADDR, 0x01);

    while((bmi270_read(BMI2_INTERNAL_STATUS_ADDR) & 0x07) != 0x01)
    {
    nrf_delay_us(1000);
    }
    bmi270_write(BMI2_PWR_CONF_ADDR, 0x04); // Power on
    bmi270_write(BMI2_PWR_CTRL_ADDR, 0x0e); // Accelerometer and gyroscope on
    bmi270_write(BMI2_ACC_CONF_ADDR, 0xb9); // Performance, Avg128, 200Hz
    bmi270_write(BMI2_ACC_RANGE_ADDR,0x00); // Range +- 2g
    bmi270_write(BMI2_GYR_CONF_ADDR, 0xc9); // Performance, normal operation, 200 Hz
    bmi270_write(BMI2_GYR_RANGE_ADDR, 0x03); // Gyre range +- 250 dps

    Thanks for your fast response, I was surprised you answered even with this post beeing over 3 years old.

    Sorry to ask again, but regarding your code how does your bmi270_write() function look like?
    I am still a beginner in this area and not sure if the BMI270 would be a good IMU to start with in my situation, but I explained my problem in detail over here:
    https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI270-I2C-with-Raspberry-Pi-3B/m-p/7214...
    Sadly didn't get enough help to resolve this issue. (which is understandable with that much text to read)

    I saw in another post of yours in here that you defined i2c_reg_read() and i2c_reg_write() as well as delay_us() and changed the dev struct. So according to this I figure that you were using the officlal BMI270-Sensor-API on github?

    In short I wanted to manually write the Bytes of the bmi270_config_file to the BMI2_INIT_CTRL_ADDR to load the config because I didn't have any success setting up the BMI270-Sensor-API on their git with COINES. So in total I would only use two files: base.cpp and bmi2_defs.h.
    My question is what else would need to be done if not just i2cReadByteData() in while() or for() loop to load the values of the config file for example?


    Regards


    uint8_t bmi270_read(uint8_t reg)
    {
    uint8_t d;
    (void)nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, &reg, 1, true);
    (void)nrf_drv_twi_rx(&m_twi, BMI2_I2C_PRIM_ADDR, &d, 1);
    return d;
    }


    void bmi270_write(uint8_t reg, uint8_t data)
    {
    uint8_t r[2];

    r[0] = reg;
    r[1] = data;

    (void)nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, r, 2, false);

    }

    The setup in last post will give interrupt. Interrupt handler is:

    void data_ready_interrupt(nrf_drv_gpiote_pin_t pin, nrf_gpiote_polarity_t action)
    {
    int16_t dta[6];
    int16_t accx;
    int16_t accy;
    int16_t accz;
    int16_t gyrox;
    int16_t gyroy;
    int16_t gyroz;

    dta[0] = 0x0c;
    (void)nrf_drv_twi_tx(&m_twi, BMI2_I2C_PRIM_ADDR, (uint8_t *)dta, 1, true);
    (void)nrf_drv_twi_rx(&m_twi, BMI2_I2C_PRIM_ADDR, (uint8_t *)dta, 12);

    accx = *(dta + 0);
    gyrox = *(dta + 3);
    accy = *(dta + 1);
    gyroy = *(dta + 4);
    accz = *(dta + 2);
    gyroz = *(dta + 5);

    }

    Main loop:

    while(1);

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist