I have a BMI160 IMU which gives a good reading for the axis parallel to gravity (1G or -1G), but a changing value of about 2G or -2G for the axes that should show 0G. This is true for all axes, I've tried rotating the IMU.
I'm reading the IMU with an STM32F4 Discovery board via SPI. To my understanding, the IMU outputs data for the accelerometer in 2 bytes, with LSB being first. Inside these bytes, the bits are in MSB format. So a reading of 0111 0010 1111 1101 should be 64 882 in decimal (flipped to 1111 1101 0111 0010) and equate to about 19.23 m/s^2 or 1.96 G. I know the exact bits moving in the SPI data line, since I've read it with a logic analyzer to check.
BMI160 settings: power mode is "normal", and ACC_CONF register is "0x2B": no undersampling, normal filter mode (3dB cutoff frequency), and a data rate of 800 Hz. I've also tried 100 Hz and 1600 Hz. Baud rate for SPI is 156,250 Hz, I've tried higher too (for example 1,250,000 Hz).
I know the BMI160 works well, because I have a Bosch Application board and Development Desktop program, which output a nice running graph of good-looking data for all axes. I've also tried a different BMI160 and different STM32 board.
I suspect the problem is somewhere in how I either initialize the board, or how I read the SPI, but where exactly?
Datasheet for BMI160: https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf