Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    Unable to initialize BMI270

    Unable to initialize BMI270

    liamsm
    Member

    Hello,

    I  am running into issues with the BMI270 API. I'm following the accel.c example provided in the repository. My program never returns from bmi270_init function. Unfortunately I don't have access to proper debugging equipment on my current platform, but I've narrowed it down to occuring somewhere in the bmi2_soft_reset function. I am able to communicate with the device using my user-defined read/write functions and read the correct chip_id from them. I've attached the relevant code below. Any advice appreciated.

    Thanks,

    Liam

    uint8_t rslt;

    struct bmi2_dev bmi2_dev;

    rslt = bmi2_interface_selection(&bmi2_dev);
    SerialUSB.println(rslt);

    //test read chip_id
    uint8_t dev_addr = BMI2_I2C_PRIM_ADDR;
    bmi2_dev.intf_ptr = &dev_addr;
    struct bmi2_dev *bmi_ptr = &bmi2_dev;
    uint8_t data = 0;
    user_i2c_reg_read(0x0, &data, 1, bmi_ptr->intf_ptr);
    SerialUSB.println(data,HEX);

    //init function, never returns 😞
    rslt = bmi270_init(&bmi2_dev);
    SerialUSB.println(rslt);
    delay(500);

     

    User read/write functions:

    /*!
    * @brief This function is for writing the sensor's registers through I2C bus.
    */
    int8_t user_i2c_reg_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    uint8_t addr = *(uint32_t*)intf_ptr;
    Wire.beginTransmission(addr);
    Wire.write(reg_addr);
    for(uint16_t i = 0; i < length; i ++)
    Wire.write(reg_data[i]);
    Wire.endTransmission();
    return(0);

    /* Write to registers using I2C. Return 0 for a successful execution. */
    return 0;
    }

    /*!
    * @brief This function is for reading the sensor's registers through I2C bus.
    */
    int8_t user_i2c_reg_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t length, void *intf_ptr)
    {
    uint8_t addr = *(uint32_t*)intf_ptr;
    Wire.beginTransmission(addr);
    Wire.write(reg_addr);
    if(Wire.endTransmission() != 0) return 0;
    Wire.requestFrom(addr, (uint8_t) length);
    for(uint16_t i = 0; i < length; i ++)
    {
    reg_data[i] = Wire.read();
    }
    Wire.endTransmission();

    /* Read from registers using I2C. Return 0 for a successful execution. */
    return 0;
    }

     

    2 REPLIES 2

    Minhwan
    Community Moderator
    Community Moderator

    Hello, 

     

    If you can't read register 0x00 for chip id, it's highly related to i2c interface itself. 

    Sorry, I can't give you much information unless you don't have data log like logic analyzer :(. 

    Thanks, 

    Hi Minhwan,

    I think you misread my post. I AM able to communicate with the chip and get the correct chip ID (0x24) from register 0x00 using the user_i2c_reg_read function included above.

    Liam

    Edit: The issue had to do with my delay functions, resolved now.

    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