Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 
    SOLVED

    BMX160 Magnetometer data not changing

    Community Moderator

    Re: BMX160 Magnetometer data not changing


    @o_o wrote:

    **PS: Handytech's code incorrectly sets the burst length to 1 byte, it should be 8 bytes.


    To shortly comment about this::

    • In Setup Mode (or manual mode) of the Magnetometer interface:
      • The number of data bytes in each (burst) read transaction on the bus is indeed defined by aux_rd_burst_len. But in case the number of bytes requested is larger than aux_rd_burst_len, I believe the sensor API handles that and generates the necessary amout of smaller transactions.
      • The number of data bytes in each write transaction is always 1 (i.e. no burst write is supported, regardless of aux_rd_burst_len).
    • In Data Mode of the Magnetometer interface:
      • Reading of the data is always done in a single I2C burst read operation with a fixed length of 8 bytes (for the BMM150/BMX160 this corresponds to MAG_[X-Z] and RHALL registers).

    Based on the above, one could reduce the amount of transactions to the magnetometer during the initialization by setting aux_rd_burst_len to 8 bytes, but I believe my code snippet using the official sensor API should work anyhow?

    Established Member

    Re: BMX160 Magnetometer data not changing

    Hi o_o

    Thanks for highlighting this incorrect write regiter. My burst write function was not incrementing the regiter.
    I've fixed this and can confirm that the init I2C write traces are identical to yours.

    I changed my code to poll the drdy_acc and drdy_mag bits (currently at 1sec intervals). Both are set correctly.
    When I read the ACC and MAG data, the ACC data changes as expected.
    The MAG data only updates correctly for 2 read cycles. After that the data goes to some bogus value and doesn't change.

    I've outputted the BMM150 registers. Here are the I2C traces and register outputs when reading the registers:

    // BMM150 Registers READ [REG: DATA]
    // Read Reg: 0x4A
    IC2_W: add:68 reg:4d data:4a
    IC2_R: add:68 reg:04 len:08 data: c9 00 69 00 af 00 4d 69
    4a: c9
    // Read Reg: 0x4B & 0x4C
    IC2_W: add:68 reg:4d data:4b
    IC2_R: add:68 reg:04 len:08 data: 00 01 06 3f 07 00 00 07
    4b: 00
    4c: 01
    // Read Reg: 0x4D - 0x50
    IC2_W: add:68 reg:4d data:4d
    IC2_R: add:68 reg:04 len:08 data: 01 06 3f 07 00 00 07 1a
    4d: 01
    4e: 06
    4f: 3f
    50: 07
    // Read Reg: 0x51 & 0x52
    IC2_W: add:68 reg:4d data:51
    IC2_R: add:68 reg:04 len:08 data: 3f 07 00 00 07 1a ff 00
    51: 3f
    52: 07

     

    Any thoughts on why the MAG data is only valid for 2 read cycles?

    Community Moderator
    Community Moderator

    Re: BMX160 Magnetometer data not changing

    Hi rdehart,

    I believe that your trace is incorrect, and that every read is actually the result of the previous command. This would make way more sense, and align with the expected register values.

    My initial debug step, would be to confirm the accuracy of your delay function. There is an important delay in the API to wait for the i2c transaction to happen.

    Did you confirm the accuracy of your millisecond delay function ?

    o_o
    Established Member

    Re: BMX160 Magnetometer data not changing

    Hi o_o

    I used my delay function to toggle a GPO & measure with a scope. My delay function was incorrect.
    I corrected the delay function and confirmed the GPO toggle.

    Tested the MAG output data again and I am getting this result: 1 measurements with sensible data, then no change.
    What is interesting is that the ACC data is still responding as expected.
    It seems that the issue is isolated to the BMM150 part of the BMX160 sensor only.

    I wanted to check if there was some hidden info in the BMM150's register data to give a clue as to what if happening.
    I read & print the BMM150 registers before every ACC & MAG data is read. What I saw does not make sense to me.
    It appears that on the first read of MAG data no longer gives valid data.
    Here are some of my observations from the BMM150 register printouts:

    • Power Control Bit turns on & off between some reads
    • Self Test turns on & off between some reads
    • Opmode settings fluctuate between some reads (NORMAL & SLEEP modes). FORCED mode, is never detected, eventhough it is setup as such
    • REPXY changes between some reads
    • REPZ changes between some reads

     

    Just to check I am not misunderstanding, can the BMM150 registers be read at any time?

     

    Just to ensure there isn't something weird with my setup, here is the I2C trace of my latest test setup

     

    BMX160 init:
    IC2_R: add:68 reg:00 len:01 data: d8
    IC2_W: add:68 reg:7e data:b6
    bmi160_init:0
    
    IC2_R: add:68 reg:00 len:01 data: d8
    
    chipID:d8
    IC2_W: add:68 reg:7e data:19
    IC2_R: add:68 reg:6b len:01 data: 00
    IC2_W: add:68 reg:6b data:20
    IC2_R: add:68 reg:4c len:01 data: 80
    IC2_W: add:68 reg:4b data:20
    IC2_W: add:68 reg:4c data:83
    bmi160_aux_init:0
    
    IC2_W: add:68 reg:4d data:4b
    IC2_R: add:68 reg:04 len:08 data: 01 06 3f 07 00 00 07 1a
    IC2_W: add:68 reg:4f data:01
    IC2_W: add:68 reg:4e data:4b
    IC2_W: add:68 reg:4d data:40
    IC2_R: add:68 reg:04 len:08 data: 32 05 11 01 79 00 db ff
    IC2_W: add:68 reg:4d data:5d
    IC2_R: add:68 reg:04 len:08 data: 00 00 00 50 84 00 00 1e
    IC2_W: add:68 reg:4d data:62
    IC2_R: add:68 reg:04 len:08 data: 00 00 1e 1e 03 00 f2 02
    IC2_W: add:68 reg:4d data:68
    IC2_R: add:68 reg:04 len:08 data: f2 02 58 56 cd 1a 00 00
    IC2_W: add:68 reg:4d data:70
    IC2_R: add:68 reg:04 len:08 data: fd 1d ff ff ff ff ff ff
    bmm150_init:0
    
    IC2_W: add:68 reg:4d data:40
    IC2_R: add:68 reg:04 len:08 data: 32 05 11 01 79 00 db ff
    BmmID:32
    IC2_R: add:68 reg:40 len:02 data: 28 03
    IC2_W: add:68 reg:40 data:27
    IC2_W: add:68 reg:41 data:05
    IC2_R: add:68 reg:42 len:02 data: 28 00
    IC2_W: add:68 reg:42 data:27
    IC2_W: add:68 reg:43 data:04
    IC2_R: add:68 reg:40 len:01 data: 27
    IC2_W: add:68 reg:7e data:11
    IC2_R: add:68 reg:02 len:01 data: 80
    bmi160_set_sens_conf:0
    
    IC2_W: add:68 reg:4d data:4c
    IC2_R: add:68 reg:04 len:08 data: 06 3f 07 00 00 07 1a ff
    IC2_W: add:68 reg:4f data:06
    IC2_W: add:68 reg:4e data:4c
    IC2_W: add:68 reg:4f data:07
    IC2_W: add:68 reg:4e data:51
    IC2_W: add:68 reg:4f data:1a
    IC2_W: add:68 reg:4e data:52
    bmm150_set_presetmode:0
    
    IC2_W: add:68 reg:4d data:4c
    IC2_R: add:68 reg:04 len:08 data: 06 3f 07 00 00 07 1a ff
    IC2_W: add:68 reg:4f data:02
    IC2_W: add:68 reg:4e data:4c
    bmm150_set_op_mode:0
    
    IC2_W: add:68 reg:4d data:42
    IC2_R: add:68 reg:44 len:01 data: 0b
    IC2_W: add:68 reg:44 data:07
    IC2_R: add:68 reg:4c len:01 data: 83
    IC2_W: add:68 reg:4b data:20
    IC2_W: add:68 reg:4c data:03
    bmi160_config_aux_mode:0

     

     

    Here are the consequcitve BMM150 register reads ( followed by ACC & MAG data read)

    Read #1(Power Control Bit=1, Self Test=1, Opmode=Normal):

     

    BmmReg:
    IC2_W: add:68 reg:4d data:4a
    IC2_R: add:68 reg:04 len:08 data: 00 01 06 3f 07 00 00 07
    4a: 00
    IC2_W: add:68 reg:4d data:4b
    IC2_R: add:68 reg:04 len:08 data: 01 06 3f 07 00 00 07 1a
    4b: 01
    IC2_W: add:68 reg:4d data:4c
    IC2_R: add:68 reg:04 len:08 data: 01 06 3f 07 00 00 07 1a
    4c: 01
    IC2_W: add:68 reg:4d data:4d
    IC2_R: add:68 reg:04 len:08 data: 3f 07 00 00 07 1a ff 00
    4d: 3f
    IC2_W: add:68 reg:4d data:4e
    IC2_R: add:68 reg:04 len:08 data: 3f 07 00 00 07 1a ff 00
    4e: 3f
    IC2_W: add:68 reg:4d data:4f
    IC2_R: add:68 reg:04 len:08 data: 00 00 07 1a ff 00 1f b4
    4f: 00
    IC2_W: add:68 reg:4d data:50
    IC2_R: add:68 reg:04 len:08 data: 00 07 1a ff 00 1f b4 43
    50: 00
    IC2_W: add:68 reg:4d data:51
    IC2_R: add:68 reg:04 len:08 data: 00 07 1a ff 00 1f b4 43
    51: 00
    IC2_W: add:68 reg:4d data:52
    IC2_R: add:68 reg:04 len:08 data: 1a ff 00 1f b4 43 00 98
    52: 1a
    IC2_R: add:68 reg:12 len:06 data: 0f 1c 71 0f 00 fe
    IC2_R: add:68 reg:04 len:08 data: 1a ff 00 1f b4 43 00 98
     aX=-0.06,aY=0.48,aZ=-0.88 mX=-10.000000,mY=355.000000,mZ=2047.000000

     

     

    Read #2(Power Control Bit=0, Self Test=0, Opmode=Sleep):

     

    BmmReg:
    IC2_W: add:68 reg:4d data:4a
    IC2_R: add:68 reg:04 len:08 data: 00 01 06 3f 07 00 00 07
    4a: 00
    IC2_W: add:68 reg:4d data:4b
    IC2_R: add:68 reg:04 len:08 data: 00 01 06 3f 07 00 00 07
    4b: 00
    IC2_W: add:68 reg:4d data:4c
    IC2_R: add:68 reg:04 len:08 data: 06 3f 07 00 00 07 1a ff
    4c: 06
    IC2_W: add:68 reg:4d data:4d
    IC2_R: add:68 reg:04 len:08 data: 3f 07 00 00 07 1a ff 00
    4d: 3f
    IC2_W: add:68 reg:4d data:4e
    IC2_R: add:68 reg:04 len:08 data: 3f 07 00 00 07 1a ff 00
    4e: 3f
    IC2_W: add:68 reg:4d data:4f
    IC2_R: add:68 reg:04 len:08 data: 00 00 07 1a ff 00 1f b4
    4f: 00
    IC2_W: add:68 reg:4d data:50
    IC2_R: add:68 reg:04 len:08 data: 00 00 07 1a ff 00 1f b4
    50: 00
    IC2_W: add:68 reg:4d data:51
    IC2_R: add:68 reg:04 len:08 data: 07 1a ff 00 1f b4 43 00
    51: 07
    IC2_W: add:68 reg:4d data:52
    IC2_R: add:68 reg:04 len:08 data: 1a ff 00 1f b4 43 00 98
    52: 1a
    IC2_R: add:68 reg:12 len:06 data: 1b 1c 81 0f 03 fe
    IC2_R: add:68 reg:04 len:08 data: 1a ff 00 1f b4 43 00 98
     aX=-0.06,aY=0.48,aZ=-0.88 mX=-10.000000,mY=355.000000,mZ=2047.000000

     

     

    Read #3(Power Control Bit=0, Self Test=0, Opmode=Normal):

     

    BmmReg:
    IC2_W: add:68 reg:4d data:4a
    IC2_R: add:68 reg:04 len:08 data: 00 01 06 3f 07 00 00 07
    4a: 00
    IC2_W: add:68 reg:4d data:4b
    IC2_R: add:68 reg:04 len:08 data: 00 01 06 3f 07 00 00 07
    4b: 00
    IC2_W: add:68 reg:4d data:4c
    IC2_R: add:68 reg:04 len:08 data: 06 3f 07 00 00 07 1a ff
    4c: 06
    IC2_W: add:68 reg:4d data:4d
    IC2_R: add:68 reg:04 len:08 data: 06 3f 07 00 00 07 1a ff
    4d: 06
    IC2_W: add:68 reg:4d data:4e
    IC2_R: add:68 reg:04 len:08 data: 07 00 00 07 1a ff 00 1f
    4e: 07
    IC2_W: add:68 reg:4d data:4f
    IC2_R: add:68 reg:04 len:08 data: 00 00 07 1a ff 00 1f b4
    4f: 00
    IC2_W: add:68 reg:4d data:50
    IC2_R: add:68 reg:04 len:08 data: 00 00 07 1a ff 00 1f b4
    50: 00
    IC2_W: add:68 reg:4d data:51
    IC2_R: add:68 reg:04 len:08 data: 07 1a ff 00 1f b4 43 00
    51: 07
    IC2_W: add:68 reg:4d data:52
    IC2_R: add:68 reg:04 len:08 data: 1a ff 00 1f b4 43 00 98
    52: 1a
    IC2_R: add:68 reg:12 len:06 data: 17 1c 7d 0f 0b fe
    IC2_R: add:68 reg:04 len:08 data: 1a ff 00 1f b4 43 00 98
     aX=-0.06,aY=0.48,aZ=-0.88 mX=-10.000000,mY=355.000000,mZ=2047.000000

     

     

    I have attached a text file (BMM150_Register_Traces.h) that contains the Setup & BMM150 register traces of  multiple consecutive reads.
    Each read is done at approx. 1second intervals (no intermediate reads eventhough output rate is set to 50Hz).

    I ran the test code on 2 different PCB's to eliminate the posibility of a hardware fault.
    Both boards give the same type of result (BMM150 registers changing between reads).

    Is there a posibility of a hardware failure on both boards?

    Is there other information I can provide that will give more insight?

     

    Established Member

    Re: BMX160 Magnetometer data not changing

    Hi o_o & handytech

    I have found the final issue and MAG data is being read successfully.
    In a nutshell: Don't read the BMM150 registers unless you are setting up the BMX160 sensor

    In an attempt to find out if my compiler/project could be causing the issue, I ported the basic init & read code to a C project.
    This project worked & gave reliable ACC & MAG data.
    I think put the BMM150 register printout in the C project as well and then the MAG data being gave bogus values.

    Going back to my C++ project, I removed the BMM150 register read function & was able to read reliable MAG data.

     

    What other factors contributed to the resolution of this issue (please see earlier posts from o_o & handytech):

    • handytech's setup example (but with burst length set to 8 bytes)
    • my delay function was functioning as expected
    • my write I2C function was not incrementing the REGISTER to write to
    • bmm preset mode should be ENHANCED, for 50Hz MAG data
    • Don't read the BMM150 registers unless you are setting up the BMX160 sensor
    • I2C clk set to 100 kHz

     

    Thanks for all your help in resolving this issue.
    I really appreciate your inputs.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist