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:
You are polling the BMX160 via the I2C?
if so you need to check the data ready bit int_drdy_en in INT_EN 0x51 register to check if data has arrived
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?
You could refer attached example code on STM32, modify your code and test it again.
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.