cancel
Showing results for 
Search instead for 
Did you mean: 

How to read FIFO of LIS2DW12

ZAIDS-S23
Associate III

Greetings

I am trying to read from the FIFO of the LIS2DW12. What confuses me, is that reading through the datasheet, there are only registers which indicate the number of unread samples in the FIFO (FIFO_SAMPLES (2Fh)), and a control register FIFO_CTRL (2Eh). What I am expecting, are dedicated registers from the conventional OUTPUT registers which a device like the LSM6DSOX has. 

The LIS2DW12 does not possess such registers, thus what address do I do a read from, that will be able to provide the 32 samples it is able to hold in its FIFO? Will it be the conventional OUTPUT registers?

Any help would be appreciated.

Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions
Federica Bossi
ST Employee

Hi @ZAIDS-S23 ,

Welcome to st community 🙂

You need to configure the FIFO settings using the FIFO_CTRL (2Eh) register, then use the FIFO_SAMPLES (2Fh) register to know the number of unread samples and finally perform sequential reads from the accelerometer's output registers to access FIFO data. There aren't specific registers for direct FIFO data access; you'll read data continuously from the output registers to retrieve FIFO data.

You can also have a look at our PID examples on github where you can find an example that shows how to read data from FIFO.

Hope this helps.

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.

View solution in original post

5 REPLIES 5
Federica Bossi
ST Employee

Hi @ZAIDS-S23 ,

Welcome to st community 🙂

You need to configure the FIFO settings using the FIFO_CTRL (2Eh) register, then use the FIFO_SAMPLES (2Fh) register to know the number of unread samples and finally perform sequential reads from the accelerometer's output registers to access FIFO data. There aren't specific registers for direct FIFO data access; you'll read data continuously from the output registers to retrieve FIFO data.

You can also have a look at our PID examples on github where you can find an example that shows how to read data from FIFO.

Hope this helps.

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.

Apologies for following up to this question after accepting an answer, however, I am struggling to understand the read-process of the chip. I have found an application note for the chip, that details the following process to read from the FIFO:

 

 

read_reg(0x2f, &fifo);    /* Get number of unread samples */
fifo &= 0x3f;

while (fifo != 0x00)     /* Print axes till FIFO is empty */
{
printAxes();
read_reg(0x2f, &fifo); /* Get number of unread samples */
fifo &= 0x3f;
}

 

 

While I understand what's happening, which is and correct me if I'm wrong, the value of unread samples is being read and the value of "fifo" will start at 31 (at line 2) and decrease as a read operation is performed on the output registers til it hits zero, and it will exit the while loop. Thus, I'm thinking, it's safe to place a read-operation on line 9 and then close the while-loop. However, when I do this, I obtain zeroes for all values for each data set.

 I have also tried checking for the FIFO_FTH flag, as suggested by the examples on GITHUB. This would mean, instead of the while-loop condition checking if the value of "fifo" is equal to zero, I merely remove the code from lines 1 and 2, and check if the FTH bit is set in "fifo" value. This introduces issues into my system where I cannot even read the WhoAMI value. 

Currently, I am confused on when to read from the output registers. Please may you assist.

Regards

 

Hi Federica

Any response to my most recent question below?

Regards

Federica Bossi
ST Employee

Hi @ZAIDS-S23 ,

The steps you need to do are the following:

- set BDU, FS, filters

- configure the fifo

- set the power mode and the ODR you want

- read samples in polling mode (using the fifo wtm flag)

- read the acceleration data

Hope this helps.

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.

Hi Federica 

Thank you for responding.

I am starting the sampling by setting SLP_ MODE_SEL to 1, in CTRL3.

After that, I am polling the FIFO_SAMPLES register, to check for the wtm flag, as such:

	while(!isbitSet(ui8Data,7)){
		IDS_LIS2DW12_Mem_read(_hi2c, IDS_LIS2DW12_FIFO_SAMPLES_REG, &ui8Data);
	}

Where isbitSet(), checks whether the 7th bit (FIFO_FTH) is not set and continuously polls til it does. The flag is never set in this instance, thus my code doesn't ever get to read the acceleration data.