Showing results for 
Search instead for 
Did you mean: 

Read number of unread samples in FIFO - LIS2DW12

Associate III


I am working with the LIS2DW12 accelerometer and I am struggling to read from, and use the FIFO in single-conversion mode, using i2c. The chip is on a dev board which can only be used with i2c, and the INT1 or INT2 pins are not available for use.

I am configuring the chip in low-power 12-bit mode, with an ODR of 50Hz.

My configuration function:


write(CTRL2_REG, 0x0C) //block data update = 1, device-addr increment = 1

write(CTRL6_REG, 0x00) // filter = ODR/2

write(FIFO_CTRL_REG, 0x20) //fifo mode

write(CTRL1_REG, 0x48) // low-power 12-bit mode, with an ODR of 50Hz, single-conversion mode

write(CTRL7_REG, 0x20) //enable interrupts


To run the chip in single-conversion mode and read from the fifo, the function I have written is as follows:


write(CTRL3_REG, 0x02) //enable start-of-single-conversion by I2C

write(CTRL3_REG, 0x03) // start measurement


After this. I am confused, as I have posted previously

When I try to read the number of unread samples in the FIFO_Samples register, I continuously get zero. Thus, I do not have a clear indicator of when I need to read from the output registers. I can verify the read functionality as well, as I check the WhoAMI everytime the chip boots up and that checks out. I have also added a delay after the last write command to CTRL3, to ensure the FIFO can fill up according to the clock cycles required (32 cycles * 1/50 = 640ms delay). 

My attempt to read from the FIFO_Samples register, where ui8Data is zero:

	read(FIFO_Samples_reg, ui8Data);
	ui8Data &= 0x3F;

Please can I have some help on this. 



Federica Bossi
ST Employee

Hi @ZAIDS-S23 ,

After setting the accelerometer configurations, I suggest you to read samples in polling mode (without interrupt) and read the acceleration output only if new value is available (check the fifo_wtm_flag).

You can follow the steps in this PID example.

Let me know if you solve.

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Federica Bossi
ST Employee

Hi @ZAIDS-S23 ,


Has my answer helped you?

In order to give better visibility on the answered topics, please click on 'Accept as Solution' on the reply which solved your issue or answered your question.
Associate III

Hi @Federica Bossi,

Unfortunately not. I did not get the FIFO working as it should (able to actively monitor its state or count the no. of samples), using polling methods. I've found hardware that has the chip's interrupt pins routed and that worked instantly. I am able to receive interrupts on the state of the FIFO and monitor the no. of samples.

I am not sure why it doesn't work with polling techniques. All I did from the original configuration was use the interrupt pins for the FIFO_FTH flag and configure the WK_UP_THS register for a wakeup of 375mg or so, to get it working as it is now. So in terms of the FIFO, there's nothing that was changed and nothing I haven't tried, when I was attempting to poll the FTH flag.