Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMX160 magnetometer problem

    BMX160 magnetometer problem

    Established Member


    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 of BMX160 data sheet enough? I fetched the data by reading data registers (0x04-0x0B) described in  section 2.11.4.

    Magnetometer configuration code:


    write_spi(0x7E, 0x19);
    write_spi(0x4C, 0x80);
    write_spi(0x4F, 0x01);
    write_spi(0x4E, 0x4B);
    write_spi(0x4F, 0x01);
    write_spi(0x4E, 0x51);
    write_spi(0x4F, 0x0E);
    write_spi(0x4E, 0x52);
    write_spi(0x4F, 0x02);
    write_spi(0x4E, 0x4C);
    write_spi(0x4D, 0x42);
    write_spi(0x44, 0x05);
    write_spi(0x4C, 0x00);
    write_spi(0x7E, 0x1A);


    Magnetometer fetch data code:


    uint8_t data;
    read_spi(0x05, &data); //MSB
    *mag_x = data;
    *mag_x = *mag_x << 8;
    read_spi(0x04, &data); //LSB
    *mag_x |= data;
    read_spi(0x07, &data); //MSB
    *mag_y = data;
    *mag_y = *mag_y << 8;
    read_spi(0x06, &data); //LSB
    *mag_y |= data;
    read_spi(0x09, &data); //MSB
    *mag_z = data;
    *mag_z = *mag_z << 8;
    read_spi(0x08, &data); //LSB
    *mag_z |= data;
    read_spi(0x0B, &data); //MSB
    *rhall = data;
    *rhall = *rhall << 8;
    read_spi(0x0A, &data); //LSB
    *rhall |= data;


    Kind regards,

    Marko Njirjak

    8 REPLIES 8


    Hi Marko,

    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:

    Established Member


    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.

    Kind regards,

    Marko Njirjak

    I am having the same problem. I can read the accelerometer and gyro without issue, but the magnetometer is outputting zeroes to the data registers.

    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: