Skip to main content
Visitor II
October 22, 2025
Solved

IIS2MDC Threshold setting and actual values ambiguity.

  • October 22, 2025
  • 1 reply
  • 214 views

Hi,

I am working on a project to read the magnetic field with the IIS2MDCTR chip. Actually, I am replacing a read switch with this accelerometer. I use the IIS2MDCSensor Arduino library. After testing with the magnet, I set the threshold to 10000. Enabled the interrupt on all axes in pulsed mode and routed it to the INT pin to get my microcontroller. (STM32U385VGT6) interrupted. When I close the magnet from the z-direction, I get the interrupt. But when I bring it closure from an angle, it does not change the pin status. I tried printing the ODR register values. I saw one, two, or three register values go beyond the 10000 threshold. But I do not get the interrupt. But when I move from the z direction, I am getting the interrupt even when only one axis exceeds the threshold. 

Can somebody explain the situation and advise me to understand this behaviour? 

    This topic has been closed for replies.
    Best answer by pLanka

    Hi, Federica

    I tested and found the issue. As I mentioned earlier, the issue was the scaling. I need to correct the threshold value with the scale before loading into the threshold registers. Now everything works fine. 

     

    Thanks

     

     

     

    1 reply

    Technical Moderator
    October 23, 2025

    Hi @pLanka ,

    Can you double-check that interrupts are enabled on all three axes in the sensor registers?

    Thanks

    pLankaAuthor
    Visitor II
    October 23, 2025

    Hi Federica,

    Thanks for your quick response. 

    Yes, I have enabled interrupts on all three axes. I think the issue is with scaling. The values read from the getAxis() function in the library scale the raw register readings and put them as int32 numbers in the given array. But I just set the threshold registers to 10000. I, too, need to scale my threshold with the same scale before loading into the register. I then should compare the printed values with the scaled threshold. I will do that test and update the blog tomorrow. 

     

     

    pLankaAuthorAnswer
    Visitor II
    October 27, 2025

    Hi, Federica

    I tested and found the issue. As I mentioned earlier, the issue was the scaling. I need to correct the threshold value with the scale before loading into the threshold registers. Now everything works fine. 

     

    Thanks