Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    Where is the example that works for getting the magnetometer data?

    Where is the example that works for getting the magnetometer data?

    New Poster

    I am working on BMX160 using I2C, I can get the data of Accel  but can't get any valid Magnetometer data. I found that almost all the examples using bmm150 to get this data. and , but I found some defines in bmm150_def.h are not the same as the datasheet of BMX160. For example : 

    #define BMM150_REG_CHIP_ID                        UINT8_C(0x40)
    it should be 0x00

    #define BMM150_CHIP_ID                            UINT8_C(0x32)
    it should be 0xD8

    I am worrying about it doesn't work. 
    6 REPLIES 6

    Community Moderator
    Community Moderator



    Please check my zip file. 

    You can check the bmx160_read_sensor_data example and modified bmi160 code. 


    Thank you for you help,Minhwan. I will transplant it to my platform and check it today.

    Hi Minhwan,
    I am not sure if the magetometer data I got  are correct or not.

    After I put the codes into my platform, it seems that the initialization is good, but I can't get the correct data from this codes(froom fifo), but I can read the datas from registers 0x04 to 0x17, and the data changed every time I read. the data of   accelerometer are correct for sure. But I am not sure if the data of the magetometer are correct or not. I have 2 BMX160 at the same place and they looks so different.   

    The data  of the first one looks strange.  I turned the BMX160 to different directions but the number of z always negative, from -170 to - 550, most of the time are -200 to -300.  and the number of y is always positive,  from 200 to 1700, most of the time 700-1200.the number of  x looks good, change a lot  when I turn it to different direction, from -159 to +1500.

    The data of another are different. z from -200 to + 100, y from -200 to +1500, x  from -200 to +1500.  

    here are the data at the same direction at the same time almost at the same place. ('point' and 'face'  are different faces of our product,they are 90 degree )
    point to south ,  face up:                     #1,   993,   1665, -501          #2,   849,  1145,   -245
    point to south ,  face down:               #1,  1001, 329,    -247          #2,   945,  505,     103
    point to north ,  face up                       #1,  249,   1697,   -463         #2,     89,   1433,  -203 
    point to north ,  face down                #1,  249,      289,     -291        #2,  113,   -135,   -45
    point up face south                              #1,  1433,  1449,    -389        #2,  1273, 1145,  -77
    point up face north                              #1,  1433,      625,    -379       #2,  1337,    193,   -39
    point down face south                        #1, -183,      1153,   -493       #2,   -335,  1001,  -177 
    point down face north                        #1,  -167,        593,    -323       #2,  -263,     329,  -15

    data change a little when put it to the same direction.

    Community Moderator
    Community Moderator

    Hi tangtingzhu, 


    I'm gonna check it and back to you.