03-30-2022 03:10 PM
Hello,
I am trying to use the BMI160 sensor with my STM32G474 Nucleo board. I am working over I2C. I wrote the Read - Write and DelayUS functions.
I successfully init the sensor. It returns 0 as "rslt", which means everything is fine according to this library. After that, when I configure Accel and Gyro, rslt still returns 0.
But I am constantly reading 0 from gyro and accel. Also, sometimes I get -7 error after configuring Accel and Gyro. I guess my ODR/BW settings for Accel and Gyro are not working. How can I set the correct ODR/BW and datarate?
I'm posting the code I'm using, below. In addition to the standard BMI160 library, I write two more codes to be able to use library:
commom_porting.c:
bmi160_wrapper.c:
03-30-2022 04:05 PM
You are polling the BMX160 via the I2C?
if so you need to check the data ready bit int_drdy_en in INT_EN[1] 0x51 register to check if data has arrived
03-30-2022 04:19 PM - edited 03-30-2022 04:21 PM
Yes, it came to my mind to check the Interrupts because I have always worked this way in other IMUs. Also, I'm currentlu using it via I2C.
When I couldn't find a sample on BMI160, I tried to read it directly, but I guess it didn't work.
Also, when I enter the following configuration settings for Accel and Gyro, the library gives an error of -7 which means "BMI160_E_GYRO_ODR_BW_INVALID". Here are my current settings:
/* 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 power mode of accelerometer sensor */
sensor.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;
/* 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 of Gyroscope sensor */
sensor.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
/* Set the sensor configuration */
rslt = bmi160_set_sens_conf(&sensor);
How should my settings be?
03-30-2022 04:33 PM
03-30-2022 04:34 PM
use the same code plus read the answer on my question posting on to check for the data ready bit before fetching the data.
I would not write your own driver because there are many things you need to consider interfacing correctly with the BMX160, see the bmx160 driver. It is quite tricky to fully understand the datasheet to know exactly how you must interface.