Bosch Sensortec Community

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

    BMX160 magnetometer problem

    BMX160 magnetometer problem

    mnjirjak
    Established Member

    Hello,

    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 2.4.3.1.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:

     

    write_spi(0x7E, 0x19);
    delay_ms(1);
    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);
    delay_ms(1);

     

    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;

     

    Kind regards,

    Marko Njirjak

    8 REPLIES 8

    o_o
    Contributor

    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: https://github.com/BoschSensortec/BMI160_driver

    mnjirjak
    Established Member

    Hi 

    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:

    https://github.com/BoschSensortec/BMI160_driver#accessing-auxiliary-bmm150-with-bmm150-apis-via-bmi1...

    There is also a FIFO-based example here:

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

    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