Here is what you can do to verify your code.
In your initialization function, you can configure BMI160 as below.
Write value of 0x11 to register 0x7E; // set ACC to normal mode, by default ACC is +/-2g full scale range and 100Hz ODR
Delay 5ms; // the max time of 3.8ms from datasheet
Write value of 0x15 to register 0x7E; // optional, set GYR to normal mode, by default GYR is +/-2000dps full scale range and 100Hz ODR
Delay 80ms; // the max time of 80ms from datasheet
unsigned char value = read register 0x03;
If (value == 0x14) then it means both ACC and GYR are in normal mode now
In your loop function for example you can burst read BMI160 data registers from 0x0C to 0x17 total 12 bytes in one single I2C transaction at 1s time interval. Then you can plot Ax, Ay, Az values on the terminal to see if you can get about 16384 integer when you place any axis pointing to sky and about -16384 integer when any axis is pointing to ground.
If yes, then you can change BMI160 ACC full scale range to +/-8g by writing the value of 0x08 to register 0x41 and then repeat the above steps. You should get about 4096 integer when you place any axis pointing to sky and about -4096 integer when any axis is pointing to ground.
Hello @FAE_CA1 ,
Thanks again for showing me the method. I have written the code based on your instructions, and it worked, but when I went back to the self-test code, the accelerometer value changed back to the same old wrong value. I am unable to preserve the calibration data. Am I missing something, or, by mistake, have I overwritten the calibration data? I would appreciate it greatly if you could tell me how to keep the calibration data intact.
BMI160 self-test is to check if the ACC and GYR work properly or not after BMI160 is soldered on the PCB board. You said that you are able to get correct values from ACC and GYR from my instructions above. Then you don't need to go back to self-test. If you do, then please perform a soft-reset by writing value of 0xB6 to register 0x7E and then delay 100ms so that BMI160 goes back to default state. Then you can configure BMI160 again to get sensor data.
I am not sure what you mean by calibration data. You will not have access to the BMI160 calibration parameters in each sensor's NVM. But if you want to do a quick inline calibration, then please see the attached "How to perform BMI160 inline calibration ver1.1.pdf".