Skip to main content
Visitor II
May 24, 2021
Question

Problems reading Y and Z axes on the LSM9DS1 magnetometer.

  • May 24, 2021
  • 3 replies
  • 1506 views

Hi,

While trying to calibrate the magnetometer, upon successive failures, I noticed that the values that were read for the Y and Z axes are successively repeated until a different value is read (as can be seen below). It appears that there's some kind of great threshold for a new value to be stored in the register.

0693W00000APO4WQAX.jpg 

It's hard to debug this issue, especially since the documentation on the magnetometer of the LSM9DS1 is quite scarce (namely its functionality, as opposed to the accelerometer and gyroscope on the datasheet).

The configuration is as follows:

int32_t IMU_config(IMU_FW * imu){

/* Check device ID */

lsm9ds1_id_t whoamI;

lsm9ds1_dev_id_get(&imu->dev_ctx_mag, &imu->dev_ctx_imu, &whoamI);

if (whoamI.imu != LSM9DS1_IMU_ID || whoamI.mag != LSM9DS1_MAG_ID){

while(1){

 return 0;

}

}

/* Restore default configuration */

uint8_t rst;

lsm9ds1_dev_reset_set(&imu->dev_ctx_mag, &imu->dev_ctx_imu, PROPERTY_ENABLE);

do {

lsm9ds1_dev_reset_get(&imu->dev_ctx_mag, &imu->dev_ctx_imu, &rst);

} while (rst);

/* Little-Endian Format Selection */

lsm9ds1_dev_data_format_set(&imu->dev_ctx_mag, &imu->dev_ctx_imu, LSM9DS1_LSB_LOW_ADDRESS);

/* Enable Block Data Update */

lsm9ds1_block_data_update_set(&imu->dev_ctx_mag, &imu->dev_ctx_imu, PROPERTY_DISABLE);

/* Set INT1 as Gyroscope Data Ready */

lsm9ds1_pin_int1_route_t val;

val.int1_drdy_xl = 0;

val.int1_drdy_g = 1;

val.int1_boot = 0;

val.int1_fth = 0;

val.int1_ovr = 0;

val.int1_fss5 = 0;

val.int1_ig_xl = 0;

val.int1_ig_g = 0;

lsm9ds1_pin_int1_route_set(&imu->dev_ctx_imu, val);

/* Set full scale */

lsm9ds1_xl_full_scale_set(&imu->dev_ctx_imu, LSM9DS1_4g);

lsm9ds1_gy_full_scale_set(&imu->dev_ctx_imu, LSM9DS1_2000dps);

lsm9ds1_mag_full_scale_set(&imu->dev_ctx_mag, LSM9DS1_16Ga);

/* Configure filtering chain - See datasheet for filtering chain details */

/* Accelerometer filtering chain */

lsm9ds1_xl_filter_aalias_bandwidth_set(&imu->dev_ctx_imu, LSM9DS1_AUTO);

lsm9ds1_xl_filter_lp_bandwidth_set(&imu->dev_ctx_imu, LSM9DS1_LP_ODR_DIV_50);

lsm9ds1_xl_filter_out_path_set(&imu->dev_ctx_imu, LSM9DS1_LP_OUT);

/* Gyroscope filtering chain */

lsm9ds1_gy_filter_lp_bandwidth_set(&imu->dev_ctx_imu, LSM9DS1_LP_STRONG);

lsm9ds1_gy_filter_hp_bandwidth_set(&imu->dev_ctx_imu, LSM9DS1_HP_MEDIUM);

lsm9ds1_gy_filter_out_path_set(&imu->dev_ctx_imu, LSM9DS1_LPF1_HPF_LPF2_OUT);

/* Set Output Data Rate / Power mode */

lsm9ds1_imu_data_rate_set(&imu->dev_ctx_imu, 0xA2);

lsm9ds1_mag_data_rate_set(&imu->dev_ctx_mag, 0x27);

//IMU_setInertialRate(imu, IMU_59Hz5);

//IMU_setMagnetometerRate(imu, MAG_80Hz);

/* Set SPI as communication interface */

lsm9ds1_sim_t random;

uint32_t ret = lsm9ds1_spi_mode_set(&imu->dev_ctx_mag, &imu->dev_ctx_imu,LSM9DS1_SPI_4_WIRE);

lsm9ds1_spi_mode_get(&imu->dev_ctx_mag, &imu->dev_ctx_imu,&random);

lsm9ds1_i2c_dis_t rand;

ret = lsm9ds1_i2c_interface_set(&imu->dev_ctx_mag,&imu->dev_ctx_imu,LSM9DS1_I2C_DISABLE);

ret = lsm9ds1_i2c_interface_get(&imu->dev_ctx_mag,&imu->dev_ctx_imu,&rand);

return 1;

}

I have attached a .csv file that serves as a datalog of the several readings while rotating the LSM9DS1 with the motion described in section 2.2.5 of the UM2192.

Any idea on what might be causing this issue?

Thanks in advance.

    This topic has been closed for replies.

    3 replies

    PMach.1Author
    Visitor II
    May 24, 2021

    Ups, Gess I forgot the attatchment. Here it is:

    PMach.1Author
    Visitor II
    June 16, 2021

    Anyone?

    Visitor II
    June 9, 2023

    I'm having the same issue. My X values update normally, but Y and Z get stuck on initial values. In my case on the board I'm working with a high current inductor was placed an inch or so away along the IMU's positive Y axis. Only X works. I figured the interfering magnetic field lines were travelling along the Z and Y axes though mostly perpendicular to the X axis. My circumstances are rather specific and I doubt the odds of yours being the same. It would be helpful to know if this is actually a software issue.