Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMI270 accel data anomily

    BMI270 accel data anomily


    Hello all, I am experiencing a couple of anomalies in the data read from BMI270 using the reference API.

    1) The accelerometer data is out by a factor of 4.

    2) The timestamp data always reads 0.

    Please take a look at the following code and output and see if you can spot what I am missing:


    static int8_t BMI270_sensor_config(struct bmi2_dev *bmi2_dev)

    int8_t rslt = BMI2_OK;
    struct bmi2_sens_config config[2];

    config[0].type = BMI2_ACCEL;
    config[0].cfg.acc.odr = BMI2_ACC_ODR_100HZ;
    config[0].cfg.acc.range = BMI2_ACC_RANGE_2G;
    config[0].cfg.acc.bwp = BMI2_ACC_NORMAL_AVG4;
    config[0].cfg.acc.filter_perf = BMI2_PERF_OPT_MODE;
    config[1].type = BMI2_GYRO;
    config[1].cfg.gyr.odr = BMI2_GYR_ODR_100HZ;
    config[1].cfg.gyr.range = BMI2_GYR_RANGE_2000;
    config[1].cfg.gyr.bwp = BMI2_GYR_NORMAL_MODE;
    config[1].cfg.gyr.filter_perf = BMI2_PERF_OPT_MODE;
    config[1].cfg.gyr.noise_perf = BMI2_POWER_OPT_MODE;

    if(rslt = BMI2_OK) bmi2_set_sensor_config(config, 2, bmi2_dev);

    return rslt;


    struct bmi2_sensor_data sensor_data[2];

    sensor_data[0].type = BMI2_ACCEL;
    sensor_data[1].type = BMI2_GYRO;

    bmi2_get_sensor_data(sensor_data, 2, &bmi270_dev);

    /*Converting lsb to meter per second squared for 16 bit accelerometer at 2G range. */
    test_x = lsb_to_mps2(sensor_data[0].sens_data.acc.x, 2, bmi270_dev.resolution); // bmi270_dev.resolution=16
    test_y = lsb_to_mps2(sensor_data[0].sens_data.acc.y, 2, bmi270_dev.resolution);
    test_z = lsb_to_mps2(sensor_data[0].sens_data.acc.z, 2, bmi270_dev.resolution);

    test_g = sqrt(test_x*test_x + test_y*test_y + test_z*test_z);

    #define GRAVITY_EARTH (9.80665f)

    static float lsb_to_mps2(int16_t val, float g_range, uint8_t bit_width)
    float half_scale = ((float)(1 << bit_width) / 2.0f);
    return (GRAVITY_EARTH * val * g_range) / half_scale;

    OUTPUT (sensor stationary):

    sensor_data[0].sens_data.acc.x =
    sensor_data[0].sens_data.acc.y = 358
    sensor_data[0].sens_data.acc.z = 4104
    sensor_data[0].sens_data.acc.virt_sens_time = 0

    sensor_data[1].sens_data.gyr.x = 3
    sensor_data[1].sens_data.gyr.y = -2
    sensor_data[1].sens_data.gyr.z = 3
    sensor_data[0].sens_data.gyr.virt_sens_time = 0

    test_x = 0.208894104
    test_y = 0.211288303
    test_z = 2.45405674
    test_g = 2.47197771

    1) I would expect: test_g = GRAVITY_EARTH , however it seems: test_g = GRAVITY_EARTH/4 .The gyro data seems to be correct.

    2) I can get the correct timestamp data by reading the SENSORTIME registers directly.

    What is the most efficiant way to read gyro, accel and timestamp data together?

    Any help would be much appreciated!

    4 REPLIES 4

    Community Moderator
    Community Moderator

    The virt_sens_time is only used in FIFO data unpack. 

    In read sensor data function you called,  this parameter is not feed with any valid data.   So your print out is 0. 

    I suggest you to read the sensor time register directly.

    To convert the lsb to g,  i suggest you following our API example:

    lsb_per_g = (uint16_t)(power(2, dev->resolution) / (2 * range));

    Then use the lsb value get from read sensor data to devided by lsb_per_g to get g value on each axis.


    Many thanks for your reply Vincent, and for clearing up part (2) of the problem. It’s pretty straight forward to read all the accel, gyro and timestamp data directly in one burst, so maybe I’ll just do that.

    I will use the method for converting lsb to g to highlight again part (1) of the problem

    config[0].cfg.acc.range = BMI2_ACC_RANGE_2G; the sensitivity is 16384 LSB/g
    (This can be worked out using the given equation, and is also found on p13 of the data-sheet).

    Converting accel data gives
    x = 355/16384 = 0.02166748046875 g
    y = 358/16384 = 0.0218505859375 g
    z = 4104/16384 = 0.25048828125 g

    magnitude = sqrt(x*x + y*y + z*z) = 0.25237136695

    This shows clearly that the accelerometer readings are 1/4 of what would be expected.

    Any ideas?

    It seems the issue is with my BMI270_sensor_config .
    I noticed that changing the range made no difference to the data, so after configuring the accelerometer seperately (as in the accel.c example provided with the API), the data now seems correct.



    I got the same issue with you, the accelerometer data is out by a factor of 4

    and  changing the range made no difference to the data.

    Do you still remember how you finally fix this issue?

    I am using and the accel.c example and still got this problem.

    My post is here