Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMI160 Best Way to Read Sensor Data at Constant Rate

    DroneKid
    Established Member

    BMI160 Best Way to Read Sensor Data at Constant Rate

    I'm using BMI160 IMU with STM32 microcontroller. I have wrote everything, from wrappers for implementing API to sensor fusion algorithms to process raw IMU data. 

    But for precise operation, I need to get new sensor data at a constant rate. Since I shouldn't skip any new sensor readings, my read will be equal to sensors ODR rate. Which is 1600 Hz.

    My current Accel and Gyro settings are below:

     

        sensor.accel_cfg.odr = BMI160_ACCEL_ODR_1600HZ; 
        sensor.accel_cfg.range = BMI160_ACCEL_RANGE_4G;
    
    
        /* Select the power mode of accelerometer sensor */
        sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
        sensor.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4;
    
        /* Select the Output data rate, range of Gyroscope sensor */
        sensor.gyro_cfg.odr = BMI160_GYRO_ODR_1600HZ; 
        sensor.gyro_cfg.range = BMI160_GYRO_RANGE_500_DPS; 
    
        /* Select the power mode of Gyroscope sensor */
        sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
        sensor.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE; 

     

     

    And my current interrupt settings are:

        /* Select the Interrupt channel/pin */
        int_config.int_channel = BMI160_INT_CHANNEL_1;// Interrupt channel/pin 1
    
        /* Select the Interrupt type */
        int_config.int_type = BMI160_ACC_GYRO_DATA_RDY_INT;// Choosing Any motion interrupt
        /* Select the interrupt channel/pin settings */
        int_config.int_pin_settg.output_en = BMI160_ENABLE;// Enabling interrupt pins to act as output pin
        int_config.int_pin_settg.output_mode = BMI160_DISABLE;// Choosing push-pull mode for interrupt pin
        int_config.int_pin_settg.output_type = BMI160_DISABLE;// Choosing active low output
        int_config.int_pin_settg.edge_ctrl = BMI160_ENABLE;// Choosing edge triggered output
        int_config.int_pin_settg.input_en = BMI160_DISABLE;// Disabling interrupt pin to act as input
        int_config.int_pin_settg.latch_dur = BMI160_LATCH_DUR_NONE;// non-latched output
    
        /* Set the Any-motion interrupt */
        rslt = bmi160_set_int_config(&int_config, &sensor); /* sensor is an instance of the structure bmi160_dev  */

     

    So, what type of interrupt routine should I implement? 

     

    Thank you for your answers. 

    3 REPLIES 3
    BSTRobin
    Community Moderator

    Re: BMI160 Best Way to Read Sensor Data at Constant Rate

    Hi DroneKid,

    You could implement interrupt routine like this:
    struct bmi160_dev bmi160dev;
    struct bmi160_sensor_data accel;
    struct bmi160_sensor_data gyro;

    void BMI160Interrupt(void)
    {
    int8_t rslt = BMI160_OK;
    struct bmi160_dev *dev;
    volatile union bmi160_int_status int_status;

    dev = &bmi160dev;

    memset(int_status.data, 0x00, sizeof(int_status.data));
    bmi160_get_int_status(BMI160_INT_STATUS_ALL, &int_status, dev);
    PDEBUG("data: 0x%02X, 0x%02X, 0x%02X, 0x%02X\r\n", int_status.data[0], int_status.data[1], int_status.data[2], int_status.data[3]);

    if(int_status.bit.drdy)
    {
    /* To read both Accel and Gyro data */
    bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL), &accel, &gyro, dev);
    }
    }

    DroneKid
    Established Member

    Re: BMI160 Best Way to Read Sensor Data at Constant Rate

    @BSTRobin thank you for your answer. I have one more question.

     

    My interrupt settings of BMI160 were set as I shared in the initial post. With these settings, I turned on the sensor and looked at the physical interrupt pin with an oscilloscope, and I saw a square wave whose frequency was close to 1600 Hz, which is the ODR value I chose.

     

    My question is when new data arrives, does the square wave go high or low? 

     

    BSTRobin
    Community Moderator

    Re: BMI160 Best Way to Read Sensor Data at Constant Rate

    Hi DroneKid,

    According to your interrupt setting code, the interrupt is triggered by the falling edge.

    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