cancel
Showing results for 
Search instead for 
Did you mean: 

Hi, I'm trying to use the accelerometer sensor LIS2DH12, and having some issues reading data from it. Sometimes it works fine, but when re-flashing the device it doesn't work. I try to power-cycle but still issue with it. The values are all '0'

BPapp.2
Associate II
 
1 ACCEPTED SOLUTION

Accepted Solutions
BPapp.2
Associate II

Got it to work now!

Think it might have been the magnetometer (LIS2MDL) connected to the same SPI-bus that was sending out some garbage. Saw that when CS is high the sensors are configured for I2C.

When I configured the magnetometer sensor in my device tree and enabled the LIS2MDL driver in Zephyr OS it is working fine.

But I have another question regarding the accelerometer LIS2DH12.

I'm trying to configure the interrupt, to trigger when e.g. the x-axis goes above a threshold value. Not sure what to put in the INT1_THS register?

and, in the output registers (OUT_X_L and OUT_X_H) what's the value/unit? is it in g, mg or m/s2?

Looked in the datasheet and looks like when the sensor is configured in Normal Mode with +-2g sensitivity, each digit is equal to 4mg?

 So if I read out for example the raw value '2000' from x-axis, this should be:

2000x4 = 8000mg = 8g?

How can it be 8g when the measurement range is +-2g?

The reason I'm asking is because I'm trying to get the interrupt to work. It is working but not as expected. Either the interrupt never triggers, or it triggers priodically, even when the device is not moving.

View solution in original post

4 REPLIES 4
BPapp.2
Associate II

sometimes the raw values are '255'.

My setup is Zephyr RTOS with an nrf5340 MCU interfacing the LIS2DH12 with SPI.

When I have this issue and reading the CTRL_REG1 and CTRL_REG4 the values are corrupted. CTRL_REG1 = 0x00 and CTRL_REG4 = 0xFF

But when it works those registers are correct configured. Don't know why those registers change, but probably the issue why the accelerometer values are incorrect.

Eleon BORLINI
ST Employee

Hi @BPapp.2​ ,

Are your SPI or I2C lines, and Vdd and VddIO always stable during communication?

-Eleon

BPapp.2
Associate II

Got it to work now!

Think it might have been the magnetometer (LIS2MDL) connected to the same SPI-bus that was sending out some garbage. Saw that when CS is high the sensors are configured for I2C.

When I configured the magnetometer sensor in my device tree and enabled the LIS2MDL driver in Zephyr OS it is working fine.

But I have another question regarding the accelerometer LIS2DH12.

I'm trying to configure the interrupt, to trigger when e.g. the x-axis goes above a threshold value. Not sure what to put in the INT1_THS register?

and, in the output registers (OUT_X_L and OUT_X_H) what's the value/unit? is it in g, mg or m/s2?

Looked in the datasheet and looks like when the sensor is configured in Normal Mode with +-2g sensitivity, each digit is equal to 4mg?

 So if I read out for example the raw value '2000' from x-axis, this should be:

2000x4 = 8000mg = 8g?

How can it be 8g when the measurement range is +-2g?

The reason I'm asking is because I'm trying to get the interrupt to work. It is working but not as expected. Either the interrupt never triggers, or it triggers priodically, even when the device is not moving.

Eleon BORLINI
ST Employee

Hi @BPapp.2​ ,

thank you for having reported your solution!

I see you started another thread, I'll deal directly with that.

-Eleon