cancel
Showing results for 
Search instead for 
Did you mean: 

[LSM9DS1] Can't read Magnetometer value while following the data polling example on Github.

PMach.1
Senior

Hello,

I've been trying to incorporate code from the drivers in a project while following the data polling example on Github example (https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/lsm9ds1_STdC/example/lsm9ds1_read_data_polling.c). In a first attempt, I was able to easily read data from the Accelerometer and Gyroscope and even change its' output data rate. However, the magnetometer doesn't seem to respond appropriately. The data coming from the registers indicates the magnetic field is always equal to all the axes X, Y and Z and it doesn't change between readings. The first value it reads remains the same to all axes indefinitely. The magnetometer appears to be functioning since reading the WHO_AM_I register returns the expected Byte. I've also probed the DRDY pin and there was no signal whatsoever. The value that is on its controls registers seems not much different from what is read on the IMU.

Being so, I've decided to start a new project following the instructions to integrate the example in different hardware, as is the case (I'm using a STM32H745II to control the device). Doing so, the first debug run became stuck on the following instruction:

while((__HAL_RCC_GET_FLAG(RCC_FLAG_D2CKRDY) != RESET) && (timeout-- > 0));

Thus, now the uC won't start and even loading firmware seems impossible, as the IDE keeps telling there is no device found on target. One way to get around this issue is to change the bootstrap pin, loading new code and change the boot strap back.

The said new code involves reverting some changes that the CubeMX inadvertently performed:

1) Changing the definition of USE_HAL_TIM_REGISTER_CALLBACKS from 1U to 0U;

2) Changing the configuration of the HAL_PWREx_ConfigSupply function from PWR_DIRECT_SMPS_SUPPLY to PWR_LDO_SUPPLY;

What's wrong with the magnetometer and how can I prevent the CubeMX from changing the original code?

Regards

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @Community member​ ,

regarding the first part of your question, if the issue is limited to the magnetic sensor, and you are communication via SPI using the github drivers, are you properly managing the CS_M (magnetometer chip select) pin at the application processor level, as described in the datasheet, p.34? It has to be asserted before starting the magnetic sensor data acquisition.

I add the STM32 topic for more support on the second part of your question.

-Eleon