cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DE12 : How to read only one new sample ?

SimonF
Senior

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

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

9 REPLIES 9
Eleon BORLINI
ST Employee

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

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

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

@Eleon BORLINI​ ,

In the datasheet, it is nowhere written that you can get data without the FIFO. It's misleading. The bypass mode is explained as "just reset the FIFO in FIFO mode". Good to know if I don't need to use it ! And thus, you can access directly to the value with "OUT_X_H" ? Because it seems to be frozen.

This is what I'm trying but if I read "OUT_X_H" for 2 bytes (to get also LSB) I get twice the same value in each byte. And this value is always the same (0x3e sometimes and sometimes 0x3d). At the same time, the status register seem to work.

Thank you !

Hi @SimonF​ ,

the "polling mode" is the default operation mode for the devices.

>> And thus, you can access directly to the value with "OUT_X_H" ? 

You can read that register (and all the other data registers) just after having enabled the ODR and the axis from the CTRL_REG1 (20h) register.

Are you working in SPI or in I2C? Your application schematic is compliant with the connections shown in the datasheet p.19?

-Eleon

Hello @Eleon BORLINI​ ,

Sorry I didn't reply sooner.

Indeed I made it works in bypass mode. I read the 3 Axis ( 8-bits values) and can convert to the right value. Interruptions are working aswell.

I'm still struggling with the sensor. Indeed, sometimes I can no longer communicate with the sensor, and there is no reset command. But it could be related to my hardware, I just don't know enough yet ^^.

I would like to add a few points about the documentation :

  • It is really unclear that you can use the device without FIFO. (it's not even possible in the Github driver file)
  • It is unclear that the values are on only 1 byte (8-bits value). Because of the name "OUT_X_H". There is "H" but no "L" for low ^^. And because of the size of 10-bits values in the FIFO.
  • There is no application note for this sensor. You should add in the datasheet a link to the LIS3DH for help !

These points are just feedback to improve the sensor documentation. You can take it into consideration or ignore it !

Anyway, thank you for the reactive support.

Simon

Hi Simon @SimonF​ ,

glad to hear that -at least partially- is working =)

If you suspect the hardware, please check that the connections of the device are the one described in the datasheet p.19, that you mounted the decoupling capacitors and that the operating Vdd and VddIO voltages are in spec.

Thank you for reporting those improvement points, I'll share them internally to our technical marketing.

-Eleon

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.

Hi Eleon,

I am having similar problems with LIS2DE12 accelerometer. I explain the details below.

  • Interface: I2C
  • FIFO: Not used, use polling mode whereby I am reading registers 0x28 through to 0x2D and ignoring the content of OUTX_L, OUT_Y_L and OUT_Z_L.
  • ODR 10 Hz
  • To start with I can read the accelerometer values fine. However, after I update the firmware followed by a software reset of the microcontroller (not Lis2de12) I notice that after reboot all the x,y,z samples from lis2de12 are the same e.g., 1, -1, 63, 1, -1, 63, 1 -1, 63... even when I am moving the device around.
  • However, when I power cycle my board the lis2de12 recovers and start sending x,y,z samples with different values.
  • Note, we are using a single voltage supply for Vdd and VddIO. Is it a must to use the two different supplies Vdd and VddIO?

I am looking forward to your reply.

Kind regards

Mohamed