Skip to main content
BPapp.2
Associate II
September 30, 2022
Solved

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'

  • September 30, 2022
  • 4 replies
  • 2154 views

..

    This topic has been closed for replies.
    Best answer by BPapp.2

    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.

    4 replies

    BPapp.2
    BPapp.2Author
    Associate II
    September 30, 2022

    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
    October 6, 2022

    Hi @BPapp.2​ ,

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

    -Eleon

    BPapp.2
    BPapp.2AuthorBest answer
    Associate II
    October 7, 2022

    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
    October 10, 2022

    Hi @BPapp.2​ ,

    thank you for having reported your solution!

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

    -Eleon