I bought a BMX160 shuttleboard and connected it to master chip via 4-wire SPI. By following the instructions in the data sheet I was able to setup and read the data from accelerometer and gyroscope. Unfortunately I wasn't able to do the same with magnetometer. The readings from magnetometer constantly return zeros. What is the procedure for configuring magnetometer and fetching data? Is the procedure described in table 16, section 18.104.22.168.3 of BMX160 data sheet enough? I fetched the data by reading data registers (0x04-0x0B) described in section 2.11.4.
Magnetometer configuration code:
Magnetometer fetch data code:
uint8_t data; //X-axis read_spi(0x05, &data); //MSB *mag_x = data; *mag_x = *mag_x << 8; read_spi(0x04, &data); //LSB *mag_x |= data; //Y-axis read_spi(0x07, &data); //MSB *mag_y = data; *mag_y = *mag_y << 8; read_spi(0x06, &data); //LSB *mag_y |= data; //Z-axis read_spi(0x09, &data); //MSB *mag_z = data; *mag_z = *mag_z << 8; read_spi(0x08, &data); //LSB *mag_z |= data; //RHALL read_spi(0x0B, &data); //MSB *rhall = data; *rhall = *rhall << 8; read_spi(0x0A, &data); //LSB *rhall |= data;
Solved! Go to Solution.
We provide free to use drivers on our official GitHub page. For BMX160, please use the BMI160 driver, and follow the sample code to initialize and read magnetometer data: https://github.com/BoschSensortec/BMI160_driver
thank you for your answer. I cloned BMI160 and BMM150 driver from Github. In addition, I used the information provided on the Github page and in this answer. I successfully obtained readings from accelerometer and gyroscope. That was expected as the register structure in BMI160 and BMX160 is more or less the same. Unfortunately I didn't have much success with magnetometer. If I understood correctly, the idea is to use BMI160 and BMM150 driver and fetch all three sensors through BMI160 driver. Is this correct? I did notice that the register list differs in BMX160 and BMM150. For example, BMM150 has magnetometer data in registers 0x42-0x49, while BMX160 in 0x04-0x0B. I don't quite understand how I should fetch magnetometer data from BMX160 with BMM150 driver. I tried the code mentioned on Github, but didn't have much luck with magnetometer. I also tried this code, but still no result.
Is the code supposed to work as is, or are some changes necessary? It's worth mentioning that I did adapt the code to 4-wire SPI. Please excuse my ignorance if I'm missing something obvious here.
BMX160 is nothing other than a BMM150 connected to the auxiliary interface of a BMI160, but packed in a single device (this is why the part is 0.12mm thicker)
Therefore it needs to first turn on the internal magnetometer using indirect addressing, then you need to program it to fetch the rights registers to place it in the memory map or FIFO. Luckily this whole procedure is handled in the driver.
For use with the data register see example in the readme file here:
There is also a FIFO-based example here: