Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI160 & STM32 Strange Behaviour - Sensor Succesfully Inits but Accel and Gyro Reads are always zero

    DroneKid
    Member

    BMI160 & STM32 Strange Behaviour - Sensor Succesfully Inits but Accel and Gyro Reads are always zero

    Hello,

    I am trying to use the BMI160 sensor with my STM32G474 Nucleo board. I am working over I2C. I wrote the Read - Write and DelayUS functions.

    I successfully init the sensor. It returns 0 as "rslt", which means everything is fine according to this library. After that, when I configure Accel and Gyro, rslt still returns 0.

    But I am constantly reading 0 from gyro and accel. Also, sometimes I get -7 error after configuring Accel and Gyro. I guess my ODR/BW settings for Accel and Gyro are not working. How can I set the correct ODR/BW and datarate?

    I'm posting the code I'm using, below. In addition to the standard BMI160 library, I write two more codes to be able to use library:

    • common_porting = Holds I2C Read - Write and DelayUs functions
    • bmi160_wrapper = The code I wrote to use Bosch's standard library with common_porting. In the Main() function, I call the BMI160_init() function directly in this code, for example, to initialize the BMI160.

    commom_porting.c:

    common_porting.jpg

     

    bmi160_wrapper.c:

    wrapper_1.jpgwrapper_2.jpg

     

     

     

    8 REPLIES 8
    André
    Established Member

    Re: BMI160 & STM32 Strange Behaviour - Sensor Succesfully Inits but Accel and Gyro Reads are alw

    You are polling the BMX160 via the I2C?

    if so you need  to check the data ready bit int_drdy_en in INT_EN[1] 0x51 register to check if data has arrived

    DroneKid
    Member

    Re: BMI160 & STM32 Strange Behaviour - Sensor Succesfully Inits but Accel and Gyro Reads are alw

    Yes, it came to my mind to check the Interrupts because I have always worked this way in other IMUs. Also, I'm currentlu using it via I2C.

    When I couldn't find a sample on BMI160, I tried to read it directly, but I guess it didn't work.

    Also, when I enter the following configuration settings for Accel and Gyro, the library gives an error of -7 which means "BMI160_E_GYRO_ODR_BW_INVALID". Here are my current settings:

     

     

    /* Select the Output data rate, range of accelerometer sensor */
    sensor.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ;
    
    sensor.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
    
    sensor.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4;
    
    /* Select the power mode of accelerometer sensor */
    sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
    
    /* Select the Output data rate, range of Gyroscope sensor */
    sensor.gyro_cfg.odr = BMI160_GYRO_ODR_3200HZ;
    
    sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS;
    
    sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE;
    
    /* Select the power mode of Gyroscope sensor */
    sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
    
    /* Set the sensor configuration */
    rslt = bmi160_set_sens_conf(&sensor);

     

     

     

    How should my settings be?

    BSTRobin
    Community Moderator

    Re: BMI160 & STM32 Strange Behaviour - Sensor Succesfully Inits but Accel and Gyro Reads are alw

    Hi DroneKid,

    You could refer attached example code on STM32, modify your code and test it again.

    André
    Established Member

    Re: BMI160 & STM32 Strange Behaviour - Sensor Succesfully Inits but Accel and Gyro Reads are alw

    use the same code plus read the answer on my question posting on to check for the data ready bit before fetching the data.

    I would not write your own driver because there are many things you need to consider interfacing correctly with the BMX160, see the bmx160 driver. It is quite  tricky to fully understand the datasheet to know exactly how you must interface. 

     

     

    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