cancel
Showing results for 
Search instead for 
Did you mean: 

Reading data from lis3mdl magnetometer with NUCLEO-L412KB

mvari
Associate II

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?

 

1 ACCEPTED SOLUTION

Accepted Solutions

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

View solution in original post

4 REPLIES 4
jiangfan
ST Employee

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).

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? 

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

AngelML
Associate

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