cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2MDL does not work in single-shot mode with offset cancellation

JanRusnak
Associate

Hello,

I am testing the LIS2MDL magnetometer in single-shot mode with offset cancellation enabled, according to the datasheet (DS12144 - Rev 6, page 22). The documentation states that in single-shot mode both bits OFF_CANC and OFF_CANC_ONE_SHOT in register CFG_REG_B must be set to 1.

However, when these bits are both set (CFG_REG_B) and a single measurement is triggered by writing md = 01b in CFG_REG_A the measurement never completes — the ZYXDA flag in STATUS_REG remains 0 permanently.

If only OFF_CANC_ONE_SHOT=1 is set, the measurement finishes normally and ZYXDA is asserted, but the output values look identical to normal single-shot measurements (no visible offset compensation effect).

Test conditions:

  • 4WSPI
  • BDU=1

  • verified data readout sequence (reading all 6 output bytes resets ZYXDA properly)

  • communication via SPI verified by WHO_AM_I = 0x40

It appears that combining OFF_CANC=1 and OFF_CANC_ONE_SHOT=1 prevents the internal FSM from completing a single measurement.

Questions:

  1. Is this a known limitation or silicon bug of the LIS2MDL?

  2. Is there any confirmed working configuration for single-shot with offset cancellation?

  3. Should the offset cancellation be used only in continuous mode?

2 REPLIES 2
Federica Bossi
ST Employee

Hi @JanRusnak ,

You can use the offset cancellation both in single and continuous mode.

Have you already tried to use our official examples on Github? Let me know if implementing this code it works so that we can exclude sensor related problem.

Thanks

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.

Hello,

I have checked the official LIS2MDL sources on GitHub. They only contain low-level driver functions for register access, but no actual application example that performs full magnetic data readout with manual offset cancellation.
I also could not find any public example demonstrating data acquisition triggered by a single-shot measurement with manual offset cancellation, as in my configuration where the LIS2MDL is connected via 4-wire SPI.

I am attaching the source I am testing. The code reads data correctly in single-shot mode over 4-wire SPI.  ZYXDA toggles and clears after reading 6 bytes, so the basic flow is fine.

The issue appears only when I enable offset cancellation as per DS12144 Rev 6 p.22.

Repro:

  1. Idle config: BDU=1, MD=00b in CFG_REG_A.

  2. Enable offset cancel in CFG_REG_B:

    • OFF_CANC_ONE_SHOT | OFF_CANC (bits 4 and 1 set)
      In my code this is the change at lis2mdl_stm_regs.c:122:
      // working:
      r = 0;
      // working:
      r = LIS2MDL_CFG_B_OFF_CANC_ONE_SHOT;
      // failing:
      r = LIS2MDL_CFG_B_OFF_CANC_ONE_SHOT | LIS2MDL_CFG_B_OFF_CANC;

  3. Trigger single-shot: MD=01b in CFG_REG_A.

    Observed result: the conversion never completes. STATUS_REG remains 0x00, ZYXDA never asserts.

    Control cases:

    • With only OFF_CANC_ONE_SHOT=1 (OFF_CANC=0), single-shot completes and ZYXDA asserts, but the data looks the same as normal single-shot, with no visible offset-cancel effect.

    Questions:

    1. Can you confirm that OFF_CANC=1 together with OFF_CANC_ONE_SHOT=1 is supported in single-shot mode?

    2. If yes, please provide a working register sequence (timing) or a pointer to an example that demonstrates single-shot with offset cancellation over SPI.

    3. If not, is there an erratum or recommended workaround?