Question
LIS2MDL Offset Cancellation Issues
I'm having trouble getting a heading from the LIS2MDL on our custom PCB. A summary of the issue:
- If in the presence of a strong magnetic field (ie. magnet), the LIS is able to report the field as expected and I can see headings calculated in the [-180,180] range.
- If the magnet is removed and we attempt to measure just the earth's magnetic field it seems there is enough offset (even with offset cancellation enabled) to skew the results.
- After experimentally measuring the remaining offset, I am able to compensate by that vector and then we are able to measure heading correctly. However, this same compensation does not work on other copies of the same board.
My Questions:
- Am I configuring the device and offset cancellation correctly?
- Is there anything else I can do to correct this reading without manually calibrating each device?
- What might the source of this issue be, and what further steps can I take to debug it?
Initialization Procedure:
/* LIS2MDL Initialization: Offset Cancellation Disabled */
mag_reset(); // Reset device, set SPI mode, read WHOAMI
lis2mdl_block_data_update_set(&mag_ctx, PROPERTY_ENABLE);
lis2mdl_power_mode_set(&mag_ctx, LIS2MDL_LOW_POWER);
lis2mdl_offset_temp_comp_set(&mag_ctx, PROPERTY_ENABLE);
lis2mdl_operating_mode_set(&mag_ctx, LIS2MDL_SINGLE_TRIGGER);
/* LIS2MDL Initialization: Offset Cancellation Enabled */
mag_reset(); // Reset device, set SPI mode, read WHOAMI
lis2mdl_block_data_update_set(&mag_ctx, PROPERTY_ENABLE);
lis2mdl_data_rate_set(&mag_ctx, LIS2MDL_ODR_100Hz);
lis2mdl_set_rst_mode_set(&mag_ctx, LIS2MDL_SENS_OFF_CANC_EVERY_ODR);
lis2mdl_offset_temp_comp_set(&mag_ctx, PROPERTY_ENABLE);
lis2mdl_operating_mode_set(&mag_ctx, LIS2MDL_CONTINUOUS_MODE);Logs:
Data dump for both enabled and disabled offset cancellation are attached
Plots:


