Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    Correct way to configure BMI160.

    Established Member

    Correct way to configure BMI160.

    Hi Bosch sensortec community

    I am using BMI160 IMU in 4 wire SPI in my application. The way I am following to configure the sensor is like below: (indicated here)

    void Initialize_BMI160(void)
    struct bmi160_dev sensor;
    /* You may assign a chip select identifier to be handled later */ = 0;
    sensor.interface = BMI160_SPI_INTF; = user_spi_read;
    sensor.write = user_spi_write;
    sensor.delay_ms = user_delay_ms;

    rslt = bmi160_init(&sensor);
    /* After the above function call, accel_cfg and gyro_cfg parameters in the device
    structure are set with default values, found in the datasheet of the sensor */
    /*********Configuring the acc/gyro*************/
    // int8_t rslt = BMI160_OK;

    /* 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; = BMI160_ACCEL_BW_NORMAL_AVG4;
    /* 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; = BMI160_GYRO_BW_NORMAL_MODE;

    /* Select the power mode */
    sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
    sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;

    /* Set the Power mode */
    rslt = bmi160_set_power_mode(&sensor);

    /* Set the sensor configuration */
    rslt = bmi160_set_sens_conf(&sensor);


    I don't see the proper behaviour on MISO pin. The questions I have:

    1- Did I configure the sensor correctly? In other words, do I need any other registers to be configured?

    2- The SPI clock for my application is 750 kHz. Is there a restriction for the SPI clock?

    I'd appreciate it if you can help me!



    4 REPLIES 4
    Occasional Contributor

    Re: Correct way to configure BMI160.

    Here are some suggestions for your question:

    1.   Did I configure the sensor correctly? In other words, do I need any other registers to be configured?

    ------ From code level, the sensor is configured correctly. If you still cannot get the proper behavior on MISO pin. Following points can be reviewed:

            a.)   Make sure that the sensor is correctly wired in SPI bus.

            b.)   In the bmi160_init function, one step is to check chip id, did you get the correct chip id 0Xd0, if yes, MISO pin works well. If not, please measure the SPI bus via logic analyzer or oscilloscope..

    2.   The SPI clock for my application is 750 kHz. Is there a restriction for the SPI clock?

    ----- no minimum SPI clock limitation but just maximum supported SPI clock 10MHz

    Established Member

    Re: Correct way to configure BMI160.

    Thanks so much for your response.

    On 2, you are mentioning that the chip_id should be 0xD0, right? But on the Bosch sensortec github, bmi160_init in the bmi160.c fiile, the chip_id is assigned to zero. The code is provided in below. Is my understanding correct? If so, why in the code, the chip_id is assigned equal to zer?

    Thanks very much!


    int8_t bmi160_init(struct bmi160_dev *dev)
    int8_t rslt;
    uint8_t data;
    uint8_t try = 3;

    /* Null-pointer check */
    rslt = null_ptr_check(dev);

    /* Dummy read of 0x7F register to enable SPI Interface
    * if SPI is used */
    if ((rslt == BMI160_OK) && (dev->interface == BMI160_SPI_INTF))
    rslt = bmi160_get_regs(BMI160_SPI_COMM_TEST_ADDR, &data, 1, dev);
    if (rslt == BMI160_OK)
    /* Assign chip id as zero */
    dev->chip_id = 0;
    while ((try--) && (dev->chip_id != BMI160_CHIP_ID))
    /* Read chip_id */
    rslt = bmi160_get_regs(BMI160_CHIP_ID_ADDR, &dev->chip_id, 1, dev);
    if ((rslt == BMI160_OK) && (dev->chip_id == BMI160_CHIP_ID))
    dev->any_sig_sel = BMI160_BOTH_ANY_SIG_MOTION_DISABLED;

    /* Soft reset */
    rslt = bmi160_soft_reset(dev);
    rslt = BMI160_E_DEV_NOT_FOUND;

    return rslt;

    Community Moderator
    Community Moderator

    Re: Correct way to configure BMI160.

    The variable is set to zero first, then the chip ID is read.

    The chip ID is fixed and cannot be set.


    Re: Correct way to configure BMI160.

    BMI160 ID IS 0xd1.