Skip to main content
Associate
October 11, 2023
Solved

Reading data from lis3mdl magnetometer with NUCLEO-L412KB

I've been trying to read data from the OUT_X register of the LIS3MDL using a NUCLEO-L412KB, but I'm not getting any meaningful data output. When I move the device around, the output data doesn't change. I've connected CS to 3.3V and SDO to ground. What am I doing wrong?

 

This topic has been closed for replies.
jiangfan
jiangfanBest answer
ST Employee
October 12, 2023

OK, you confirm that I2C communication is functional.

You need to pay attention to CTRL_REG3 (22h). If I understand correctly, conversion is off by default (Power-down mode), so the value is invalid as you said.

lis3mdl_REG3.png

4 replies

jiangfan
ST Employee
October 11, 2023

My experience with such digital sensor is:

1) check and ensure communication (I2C or SPI or others) is OK, by checking WHO_AM_I or ID register. LIS3MDL WHO_AM_I register (address = 0x0F) value is 0x3D (00111101).

mvariAuthor
Associate
October 11, 2023

I can confirm that my I2C communication is functioning correctly because I successfully read the expected value from the WHO_AM_I register. However, when I attempt to read from the output registers, I encounter an issue – I do not receive any meaningful output. Strangely, the data I retrieve from these output registers remains static and unchanging until I physically unplug the device. After reconnecting and rerunning the code, the output values  change to entirely other number. I looked through the documentation and I am pretty sure there is no initialization I need todo to read the output register. Also, I am using a steval-mki137 that has a lis3mdl on it and it says it needs a 100nF capacitor. Could this be the problem? 

jiangfan
jiangfanBest answer
ST Employee
October 12, 2023

OK, you confirm that I2C communication is functional.

You need to pay attention to CTRL_REG3 (22h). If I understand correctly, conversion is off by default (Power-down mode), so the value is invalid as you said.

lis3mdl_REG3.png

Visitor II
January 17, 2024

You need to pay attention to CTRL_REG3 (22h). MD0 and MD1. For continous messurement you need "00"