Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    BMX160 gyro data is zero

    BMX160 gyro data is zero

    sidjur
    New Poster

    Hi,

    I would like to use the BMX160 with my STM32 MCU. Unfortunately, I am getting always zero for the gyro data. The chip id is changed to #define BMI160_CHIP_ID UINT8_C(0xD8) and the return value for the bmi160_init and bmi160_set_sens_conf is BMI160_OK.

    I have no clue where the mistake could be.

    acc.x =-1413, acc.y=236, acc.z=16734, sensortime=5340

    gyro.x=0, gyro.y=0;gyro.z=0, sensortime=5340

    // Edit: I am able to get the gyro data with the FIFO example https://github.com/BoschSensortec/BMI160_driver/wiki/How-to-use-an-auxiliary-sensor-or-magnetometer-.... 

     

     

     

     

    main()
    {
    ...
    // Initialization
           bmi.id = 0;
           bmi.interface = BMI160_SPI_INTF;
           bmi.read = bm_spi_read;
           bmi.write = bm_spi_write;
           bmi.delay_ms = HAL_Delay;
     
           rslt=bmi160_init(&bmi);
     
           /* Select the Output data rate, range of accelerometer sensor */
           bmi.accel_cfg.odr = BMI160_ACCEL_ODR_50HZ;
           bmi.accel_cfg.range = BMI160_ACCEL_RANGE_2G;
           bmi.accel_cfg.bw = BMI160_ACCEL_BW_NORMAL_AVG4;
           bmi.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
     
           /* Select the Output data rate, range of Gyroscope sensor */
           bmi.gyro_cfg.odr = BMI160_GYRO_ODR_50HZ;
           bmi.gyro_cfg.range = BMI160_GYRO_RANGE_500_DPS;
           bmi.gyro_cfg.bw = BMI160_GYRO_BW_NORMAL_MODE;
           bmi.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
     
           /* Set the sensor configuration */
           rslt = bmi160_set_sens_conf(&bmi);
          
           struct bmi160_sensor_data acc;
           struct bmi160_sensor_data gyro;
     
           /* To read only Gyro data */
           bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL | BMI160_TIME_SEL), &acc, &gyro, &bmi);
     ....
    }
     
     
    #define SPI_BUFF_SZ (1024+1)
    #define COMM_DELAY 10
     
    int8_t bm_spi_read(uint8_t dev_addr, uint8_t reg_addr, uint8_t* data, uint16_t len) {
           UNUSED(dev_addr);
     
           if (len > (SPI_BUFF_SZ - 1)) {
                  Error_Handler();
           }
     
           uint8_t rxarr[SPI_BUFF_SZ] = { reg_addr };
           HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET);
           HAL_StatusTypeDef status = HAL_SPI_TransmitReceive(&hspi2, rxarr, rxarr, len + 1, COMM_DELAY);
          
           HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET);
           memcpy(data, rxarr + 1, len);
           return (status == HAL_OK ? BMI160_OK : BMI160_E_COM_FAIL);
          
          
    }
     
     
     
    int8_t bm_spi_write(uint8_t dev_addr, uint8_t reg_addr, const uint8_t *data, uint16_t len) {
           UNUSED(dev_addr);
     
           if (len > (SPI_BUFF_SZ - 1)) {
                  Error_Handler();
           }
     
           uint8_t txarr[SPI_BUFF_SZ] = { reg_addr };
           memcpy(txarr + 1, data, len);
           HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_RESET);
           HAL_StatusTypeDef status = HAL_SPI_Transmit(&hspi2, txarr, len + 1, COMM_DELAY);
           HAL_GPIO_WritePin(SPI2_CS_GPIO_Port, SPI2_CS_Pin, GPIO_PIN_SET);
           return (status == HAL_OK ? BMI160_OK : BMI160_E_COM_FAIL);
    }

     

     

     

     

    Regards,

     

    2 REPLIES 2

    o_o
    Contributor
    For SPI reads, the register address bit #7 must be set to '1'. See this other post for an example: https://community.bosch-sensortec.com/t5/MEMS-sensors-forum/BMI160-correct-way-of-reading-accelerome...

    Also, with SPI, we recommend that you do a dummy transaction so that the protocol auto-selection switches from i2c to SPI mode.

    o_o

    Dear sidjur
    Can I ask you how you use STM32 to read the CHIPID of BMX160
    Can you share your CODE

    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