Skip to main content
Visitor II
March 19, 2021
Solved

LIS2DE12 : How to read only one new sample ?

  • March 19, 2021
  • 1 reply
  • 2885 views

Hello,

I'm trying to understand the LIS2DE12 behaviour. First, there is no AN (Application Note), thus I used the one for LIS3DH which seems close enough.

What I want is that my accelerometer wake up my stm32. This works.

After that I just want to read 1 sample to know the current acc value. But the FIFO system seems a problem for me. In the doc, it says the sample I get is the oldest one in the FIFO and that if I don't read fast enough data will be overwrited.

I just want to read one sample for Z-Axis when I need in my code. Do you have any idea or clue?

Thanks.

Best regards, Simon

    This topic has been closed for replies.
    Best answer by SimonF

    Hi @Eleon BORLINI​,

    Now it is perfectly working as it should !

    I describe a bit my issue for people seeing this post :

    This sensor is connected on the same I2C as another sensor (TOF sensor). When I was reading value from one sensor after the other. The call for TOF sensor was breaking the I2C connection (pins not longer at High state).

    Why this behaviour ? Because I was putting CS High before sending command to the LIS2DE12 and putting CS low after it is done. The problem is that LIS2DE12 switches to SPI mode when CS is low. And this was kind of "destroying" my I2C connection !

    So, don't do that ;)

    Thank you for your time !

    Have a nice week-end.

    1 reply

    ST Employee
    March 19, 2021

    Hi Simon @SimonF​ ,

    you are right, the LIS3DH and the LIS2DE12 are similar product from the FIFO side.

    Since the buffer is a FIFO, the first sample that goes into is the first made available at the output. If you are working in pure FIFO mode, the buffer continues filling until full (32 sample sets stored), then it stops collecting data and the FIFO content remains unchanged until a different mode is selected. Only the first sample if overwritten. However, if you read fast enough form the I2C/SPI acquisition interface you will be able to manage the FIFO filling.

    I suggest you check the C example son Github for the LIS2DE12, especially the FIFO one --> lis2de12_read_fifo.c. This should help you with the device configuration.

    Please let me know if you find it useful and, if so, please click on Select as Best at the bottom of this post. This will help other users with the same issue to find the answer faster. 

    -Eleon

    SimonFAuthor
    Visitor II
    March 19, 2021

    Hello @Eleon BORLINI​ ,

    What I just want is to read current acceleration value after wake up of my device. What is the best way to achieve this ? Enable the FIFO mode, enable WTM for 1 sample, read out and go in bypass mode to disable FIFO. Then restart at enabling FIFO mode.

    Or just enable all the time Stream mode and read sometimes one value. But in this case, do I need to be sure values are correct ?

    I'm sorry, I just want to read one sample whenever I want without having to manage overflows, right sample to read and so on. What is the best solution for you ? (I'm checking also the link you gave).

    Thank you for your time !

    Simon

    ST Employee
    March 19, 2021

    Hi Simon,

    in you case you just need to power on the device, configure ODR (and the related mode) and Full Scale, enable the axis in the CTRL_REG1 (20h) register and start acquiring data. A general initial configuration procedure can be the following one:

    /* Enable Block Data Update */
     lis2de12_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
     /* Set Output Data Rate to 1Hz */
     lis2de12_data_rate_set(&dev_ctx, LIS2DE12_ODR_1Hz);
     /* Set full scale to 2g */
     lis2de12_full_scale_set(&dev_ctx, LIS2DE12_2g);

    No need to pass through the FIFO.

    The only suggestion at application level is to discard the first sample after power on to avoid any startup effects.

    -Eleon