Bosch Sensortec Community

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

    BMX160 Weird behavior while configuring MAG sensor

    BMX160 Weird behavior while configuring MAG sensor

    YahyaTawil
    Established Member

    Hi 

    I followed the process as shown in Table 16 in the BMX160 datasheet 

     

     

                _writeByte(BMX160_COMMAND_REG_ADDR, BMX160_MAG_IF_NORMAL_MODE);
                ThisThread::sleep_for(1ms);//sleep 650 uS
    
                //Enable magnetometer register access (setup mode)
                _writeByte(BMX160_MAG_IF_0_ADDR, BMX160_MAG_IF_SETUP_MANUAL_EN);
    
                //put MAG into sleep mode. 
                // write 0x01 to MAG 0x4B register 
                _writeByte(BMX160_MAG_IF_3_ADDR,0x01);
                _writeByte(BMX160_MAG_IF_2_ADDR,0x4B);
    
    
                //MAG lowpower XY preset. 
                // write 0x01 to MAG 0x51 register 
                _writeByte(BMX160_MAG_IF_3_ADDR,BMX160_MAG_XY_LP_PRESET);
                _writeByte(BMX160_MAG_IF_2_ADDR,BMX160_MAG_CONF_XY_PRESET_ADDR);
    
                //MAG regular Z preset. 
                // write 0x01 to MAG 0x51 register 
                _writeByte(BMX160_MAG_IF_3_ADDR,BMX160_MAG_Z_REGULAR_PRESET);
                _writeByte(BMX160_MAG_IF_2_ADDR,BMX160_MAG_CONF_Z_PRESET_ADDR);
    
                //set ODR to 12.5 HZ
                _writeByte(BMX160_MAG_CONF_ADDR, BMX160_MAG_ODR_12_5HZ);
    
                //put MAG_IF into lowpower mode
                _writeByte(BMX160_COMMAND_REG_ADDR, BMX160_MAG_IF_LOWPOWER_MODE);
    
                /* map data ready to INT1 */
                _writeByte(BMX160_INT_ENABLE_1_ADDR, BMX160_DATA_RDY_INT_EN );
                _writeByte(BMX160_INT_MAP_1_ADDR, BMX160_INT1_DATA_READY);
    
                // prepare MAG_IF[1-3] for mag_if data mode
                _writeByte(BMX160_MAG_IF_3_ADDR,0x02);
                _writeByte(BMX160_MAG_IF_2_ADDR,0x4C);
                _writeByte(BMX160_MAG_IF_1_ADDR,0x42);
                
    
                //Enable magnetometer data mode
                _writeByte(BMX160_MAG_IF_0_ADDR, BMX160_MAG_RD_BURST_8);

     

     

    I sniffed these commands using logic Analyzer and I can see clearly that all commands have Ack from BMX160 but after sending  0x01 to 0x4C register (to switch to MAG force mode), it gives NACK responses as shown in the figure below. 

     

    YahyaTawil_0-1623013632674.png

    Any idea what is happening ? I also mentioned that when I disable the Channel X-Y-Z from 0x4E (bmm150 datasheet), the chip doesn't goes to NACK mode and I can receive data ready interrupts, but  all MAG Data is only a small fixed number  (= 0x0001). 

    Note:The ACC and GYRO stop working  after configuring the MAG

     

    6 REPLIES 6

    BSTRobin
    Community Moderator
    Community Moderator

    Hello YahyaTawil,

    There was example code in github "How to use an auxiliary sensor or magnetometer with the BMI160.", you could refer and run it.
    https://github.com/BoschSensortec/BMI160_driver/wiki/How-to-use-an-auxiliary-sensor-or-magnetometer-....

    YahyaTawil
    Established Member

    Yes I saw it to check if I'm missing something. My question is regards the Table 16 in BMX160, I followed exactly the same steps but again once I put the MAG into force mode the chip stops acknowledging the I2C. 

    Note: I map BMX160 Data ready interrupt to INT1. Does the MAG_IF uses any INT pin internally So I should avoid using it externally ? 

    Here is the log from my Logic Analyzer: 

    Start
    h68 WR
    ACK
    h7E
    ACK
    hB6
    ACK
    Stop
    Start
    h68 WR
    ACK
    h7E
    ACK
    h19
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4C
    ACK
    h80
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4F
    ACK
    h01
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4E
    ACK
    h4B
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4F
    ACK
    h01
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4E
    ACK
    h51
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4F
    ACK
    h0E
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4E
    ACK
    h52
    ACK
    Stop
    Start
    h68 WR
    ACK
    h51
    ACK
    h10
    ACK
    Stop
    Start
    h68 WR
    ACK
    h56
    ACK
    h80
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4F
    ACK
    h02
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4E
    ACK
    h4C
    ACK
    Stop
    Start
    h68 WR
    ACK
    h4D
    NAK
    Stop
    Start
    ERROR
    Start
    ERROR
    Start
    Re-Start
    h74 RD
    ERROR
    Start
    h68 WR
    NAK
    Stop
    Start
    h68 WR
    NAK
    Stop
    Start
    h68 WR
    NAK
    Stop

    Any hints on my issue, or can I provide more details ? 

    Is there a way to debug internal registers of Mag of BMX160 ? 

    Minhwan
    Community Moderator
    Community Moderator

    Hello Yahya, 

     

    Technically, you can write read register for BMX160. That means after writing data you should read proper data from register. 

    There is information in  2.11 register map datasheet. 

    As Robin mentioned that, why don't you use our API? 

    Although you get some data using register level coding, you need to compensate our raw data. 

    Therefore, our API is much more convenient. 

    https://github.com/BoschSensortec/BMI160_driver/wiki/How-to-use-an-auxiliary-sensor-or-magnetometer-....

    Based on github API, I made example code. 

    Please let me know if you have any questions. 

    Thank you. 

     

    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