cancel
Showing results for 
Search instead for 
Did you mean: 

Problems in reading FIFO for LIS2DE12

Kinjal Prajapati
Associate II
Posted on June 09, 2017 at 08:18

Hello all,

I am configuring LIS2DE12 accelerometer with JN5169 module using I2C. I read the AN3308 application note of LIS3DH and implemented the code accordingly but I am facing the problems in the configurations.

I have done following steps:

1) Writing 0x7F in the CTRL1 Register

2) Writing 0x00 in the CTRL2 Register

3) Writing 0x40 in CTRL5 Register    //made FIFO enable

4) Writing 0x40 in FIFO_CTRL Register   //made FIFO mode enable

5) Then, I am waiting for a while 

6) Reading X, Y and Z axis.

7) Enabling bypass mode, writing 0x00 to CTRL5\

Now, the problem is that the axis are showing the data till 11 sample numbers correctly. Even, it is changing according to the directions, but then, on the 12th sample, the axis are constantly giving me 0x33 till the 32 sample number. Then, it is giving as 0xff and then, the buffer again starts giving correct data till 11th sample.

When I read the status register, it is giving me always 0x00 , and the FIFO_SRC register as 0x20 upto 11th sample, & then, it also comes as 0x33.

I don't understand its behavior.

Did I configured anything wrong? 

Please help me out with this !

I will be greatly thankful !!!

#accelerometer
10 REPLIES 10
Miroslav BATEK
ST Employee
Posted on June 12, 2017 at 14:21

I think the problem will be in the reading procedure.

You can read the data from FIFO only when FIFO mode is enabled. If you enable FIFO bypass mode (step 7) then you will read only latest data in output register not FIFO.

When you read FIFO you should read 6 bytes from 0x28 to 0x2D and then start again from 0x28. You can use multi-read procedure or read the registers one by one.

It seems to me that your reading procedure is not correct, because 0x33 is value of WHO_AM_I register so you are reading probably this register.
Posted on June 12, 2017 at 15:05

Thanks for the Reply!

I enable the bypass mode only after reading the output registers. This is also mentioned in the application note that the bypass mode should be enabled at the exit to reset the FIFO.

Though, I checked the registers commenting 7th step, but the issue continued...

Kinjal Prajapati
Associate II
Posted on June 13, 2017 at 10:22

Batek.Miroslav

‌ Please find the configurations in the following function:

I2C bus is running on 100 kHz and I am calling this function periodically at 1 second.

void LIS2DE12_get_acceleration()

{

uint8_t buff[6] = {0}, out_xyz_axis[6] = {0}, FIFO_SRC[2] = {0}, FIFO_SRC_buf[2] = {0};

writeToAcc(LIS2DE12_CTRL_REG0, 0x10);

/*10Hz, enable axis*/

writeToAcc(LIS2DE12_CTRL_REG1, 0x2F);

/*disable filters*/

writeToAcc(LIS2DE12_CTRL_REG2, 0);

/*enable overrun flag*/

//writeToAcc(LIS2DE12_CTRL_REG3, 2);

/*enable FIFO*/

writeToAcc(LIS2DE12_CTRL_REG5, 0x40);

/*enable FIFO mode*/

writeToAcc(LIS2DE12_FIFO_CTRL_REG, 0x40);

Delay(15000);

readFromAcc(LIS2DE12_FIFO_SRC_REG, 1, FIFO_SRC_buf);

printf('FIFO SRC buf = %x \n\r',FIFO_SRC_buf[0]);

/*read axis*/

readFromAcc(LIS2DE12_OUT_X_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

out_xyz_axis[0] = buff[0];

readFromAcc(LIS2DE12_OUT_Y_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

out_xyz_axis[1] = buff[1];

readFromAcc(LIS2DE12_OUT_Z_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

out_xyz_axis[2] = buff[2];

readFromAcc(LIS2DE12_FIFO_SRC_REG, 1, FIFO_SRC);

printf('FIFO SRC = %x \n\r',FIFO_SRC[0]);

printf('---------------------------------------------\n\r');

printf('buf[0]= %x :: buf[1]= %x :: buf[2]= %x \n\r',out_xyz_axis[0],out_xyz_axis[1],out_xyz_axis[2]);

printf('----------------------------------------------\n\r');

/*enable bypass mode*/

//writeToAcc(LIS2DE12_FIFO_CTRL_REG, 0);

}

The macro

LIS21D_READ has the value of 6 .

Posted on June 13, 2017 at 09:05

Can you share the reading procedure?

Posted on June 13, 2017 at 13:51

I think the reading part is not correct.

When you read the FIFO_SRC_REG by readFromAcc(LIS2DE12_FIFO_SRC_REG, 1, FIFO_SRC_buf); you should evaluate number of samples in the FIFO and then make appropriate number of readings to retrieve the data from FIFO.

If your I2C reading function support reading of multiple bytes you can use the command  readFromAcc(LIS2DE12_OUT_X_H, LIS21D_READ, buff); with 

LIS21D_READ = 6; it will read one record from FIFO (X = buff[0], Y = buff [2], Z = buff [4]). This reading can be repeated until the FIFO is empty.

Following comands are not correct in your program because you are staring from 

OUT_Y_H or OUT_Y_Z register and read 6 bytes which leads to reading different registers, not the output ones.

readFromAcc(LIS2DE12_OUT_Y_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

out_xyz_axis[1] = buff[1];

readFromAcc(LIS2DE12_OUT_Z_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

out_xyz_axis[2] = buff[2];
Posted on July 26, 2017 at 22:09

Hello Miroslav,

I am attempting to use the FIFO STREAM, but reading 6-bytes from the FIFO_READ_START (0x28h) continually returns 0's. I check the FIFO_SRC_REG and see that it has 0x1F bytes filled with and overrun and watermark flag set.

Is there a particular read sequence or will clocking the additional bytes within the same addressed read get the remaining data?

I am using the 8-bit LIS2DE12 sensor. I confirmed the register readback and even start with the BOOT value set within the CTRL_REG5 and have FIFO_EN set in CTRL_REG5 and the FIFO_CTRL_REG set correctly for FIFO Stream.

Is it necessary to read OUT_X, Y, Z individually? Or is there something I am missing to kick off the reads form 0x28h?

Thanks,

--Rob

Babip Bipbop
Associate II
Posted on July 27, 2017 at 12:07

Hi Robert,

just my 2 cents [probably not useful, but just to be sure]

readFromAcc(LIS2DE12_OUT_X_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

         out_xyz_axis[0] = buff[0];

         readFromAcc(LIS2DE12_OUT_Y_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

         out_xyz_axis[1] = buff[1];

         readFromAcc(LIS2DE12_OUT_Z_H, LIS21D_READ, buff); //read the acceleration data from the LIS21D

         out_xyz_axis[2] = buff[2];

does your readFromAcc function has the capability to ``understand'' that it shall place data read from the accelerometer in buff[0] at first call, buff[1] at second call and buff[2] at third call ?

Could you post your readFromAcc function code ?

Isn't the bug related to C-coding instead ?

Sorry if this remark is non relevant!

cheers

Posted on July 27, 2017 at 15:24

Hellp Babip,

I perform a multi-byte read (6-bytes) to the FIFO_READ_START (28h) address and it returns just 0's.

I did change to reading from the X, Y, Z axis and stuffing it into a local buffer in the way you showed. However, reading the datasheet and some of the drivers out there it appears it should work using the FIFO_READ_START address. It is just unclear if I am to keep reading FIFO_READ_START (28h) or to increment through.

Also, as you likely know, the LIS2DE12 is an 8-bit version, however the addressing is the same as the higher-bit versions.

Posted on July 27, 2017 at 22:15

Figured it out. I saw it after reading the details on auto-increment.

Setting the read to use (0x80 | [

FIFO_READ_START] 0x28) appears to work when reading the 6 bytes.