Bosch Sensortec Community

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

    Correct way to configure BMI160.

    Correct way to configure BMI160.

    SaberKazemi1992
    Established Member

    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 */
    sensor.id = 0;
    sensor.interface = BMI160_SPI_INTF;
    sensor.read = 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;
    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_3200HZ;
    sensor.gyro_cfg.range = BMI160_GYRO_RANGE_2000_DPS;
    sensor.gyro_cfg.bw = 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!

    Thanks

    Saber

    4 REPLIES 4

    shellywang
    Occasional Contributor

    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

    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!

    Saber

    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);
    }
    else
    {
    rslt = BMI160_E_DEV_NOT_FOUND;
    }
    }

    return rslt;
    }

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

    The chip ID is fixed and cannot be set.

    o_o

    BMI160 ID IS 0xd1.

    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