Bosch Sensortec Community

    Showing results for 
    Search instead for 
    Did you mean: 

    BMX160 Magnetometer z axis outputting 2047 in upward orienation

    New Poster

    BMX160 Magnetometer z axis outputting 2047 in upward orienation


    I am using the API for bosch bmi160 and bmm 150 for the bmx160. Everything is working fine except the magnetometer for the z axis. In certain orientations (pointing up), the magnetometer reading will read 2047 and not change until it is moved out of that range. I have included the setup code that is mostly from the bmi160 github.  I have also just included a short reading I have gotten. Is this perhaps sent as an errror code. Also, I have checked and it seems like I get negative values on the magnetometer x and y readings but never the z, and the error seems to occur around the zero point. = 0;
    bmi.interface = BMI160_SPI_INTF; = spi_read_transfer;
    bmi.write = spi_write_transfer;
    bmi.delay_ms = user_delay_ms;
    rslt = BMI160_OK;
    rslt = bmi160_init(&bmi);
    /* Select the Output data rate, range of accelerometer sensor */
    bmi.accel_cfg.odr = BMI160_ACCEL_ODR_100HZ;
    bmi.accel_cfg.range = BMI160_ACCEL_RANGE_4G; = BMI160_GYRO_BW_NORMAL_MODE;

    /* Select the power mode of accelerometer sensor */
    bmi.accel_cfg.power = BMI160_ACCEL_NORMAL_MODE;

    /* Select the Output data rate, range of Gyroscope sensor */
    bmi.gyro_cfg.odr = BMI160_GYRO_ODR_100HZ;
    bmi.gyro_cfg.range = BMI160_GYRO_RANGE_1000_DPS; = BMI160_GYRO_BW_NORMAL_MODE;

    /* Select the power mode of Gyroscope sensor */
    bmi.gyro_cfg.power = BMI160_GYRO_NORMAL_MODE;
    bmm.write = user_aux_write; = user_aux_read;

    /* Set the sensor configuration */
    rslt = bmi160_set_sens_conf(&bmi);

    rslt = BMI160_OK;
    struct bmi160_sensor_data accel;
    struct bmi160_sensor_data gyro;
    /* To read both Accel and Gyro data */

    bmi.aux_cfg.aux_sensor_enable = 1; // auxiliary sensor enable
    bmi.aux_cfg.aux_i2c_addr = BMI160_AUX_BMM150_I2C_ADDR; // auxiliary sensor address
    bmi.aux_cfg.manual_enable = 1; // setup mode enable
    bmi.aux_cfg.aux_rd_burst_len = 2;// burst read of 2 byte

    /* Configure the BMM150 device structure by
    mapping user_aux_read and user_aux_write */ = user_aux_read;
    bmm.write = user_aux_write;
    bmm.dev_id = BMM150_DEFAULT_I2C_ADDRESS;
    /* Ensure that sensor.aux_cfg.aux_i2c_addr =
    for proper sensor operation */
    bmm.delay_ms = user_delay_ms;
    bmm.intf = BMM150_I2C_INTF;
    rslt = bmi160_aux_init(&bmi);
    rslt = bmm150_init(&bmm);

    bmm.settings.preset_mode = BMM150_PRESETMODE_REGULAR;

    bmm.settings.pwr_mode = BMM150_FORCED_MODE;

    uint8_t aux_addr = 0x42;

    uint8_t index;

    bmi.aux_cfg.aux_odr = 8;

    bmi160_set_aux_auto_mode(&aux_addr, &bmi);


    Read code is called by a timer

    bmi160_get_sensor_data((BMI160_ACCEL_SEL | BMI160_GYRO_SEL), &accel, &gyro, &bmi);
    bmi160_read_aux_data_auto_mode(mag_data, &bmi);
    bmm150_aux_mag_data(mag_data, &bmm);


    1 REPLY 1
    Community Moderator

    Re: BMX160 Magnetometer z axis outputting 2047 in upward orienation


    Thanks for your inquiry.

    Your code looks fine because you can get BMX160 accel, gyro and mag data changing. Only when z axis is pointing upward, the mag data outputs 2047 (not sure if the unit is LSB or uT). You may plot mag x/y/z data in the unit of uT in 3D space when you rotate your device slowly and randomly in 3D space to see how the shape looks like.

    BMM150 magnetometer is inside BMX160. It has +/-1300uT full scale range on x and y axes with 13-bit resolution. Z axis with +/-2500uT full scale range with 15-bit resolution which means that Z axis raw data should be between -16384LSB and +16383LSB. Please check if there is a strong magnetic source such as screw or a decoupling capacitor that contains Nickel material inside. This may cause mag z axis to be saturated.

    Please see the attached two documents for more information about how to convert BMM150 raw data to final uT value.