cancel
Showing results for 
Search instead for 
Did you mean: 

Why do I always get the same values of x, y and z for LIS2DH12 FIFO?

Allen Lin
Associate II
Posted on March 12, 2018 at 14:48

Hi,

   Thank you for reading my question.

   I always get the same values of x,y and z for using FIFO mode on LIS2DH12. The x, y and z values will change for each interrupt of WTM, but the three values are the same.

  My configurations are represent as yellow mark at following table 

0690X0000060A3xQAE.png

I'm using I2C and 

SDO is connected GND. I can get the correct WHO_AM_I value (0x33) . I also checked the registers after I set them and they are correct. I also can receive the interrupt of INT1 for reading x, y and z, but the valuesare not correct. The value of FIFO_SRC_REG is 0x00 before I read x, y and z. 

   Could you help me to check the configuration for startup and reading FIFO buffer procedure?

Best Regards,

Allen

My initialization is:

if(LIS2DH12_getRegisterValue(LIS2DH12_WHO_AM_I_ADDR) == LIS2DH12_WHO_AM_I_DEF)

{

LIS2DH12_setRegisterValue(LIS2DH12_CTRL_REG1_ADDR, LIS2DH12_ODR_SELECTION(LIS2DH12_bandWithCode) | LIS2DH12_OUT_XYZ_ALL);

LIS2DH12_setRegisterValue(LIS2DH12_CTRL_REG3_ADDR, LIS2DH12_INT1_WTM_MASK | LIS2DH12_INT1_OVERRUN_MASK); // set INT1 triger by FIFO buffer is full

LIS2DH12_setRegisterValue(LIS2DH12_CTRL_REG4_ADDR, LIS2DH12_FS_CODE(LIS2DH12_FS_2G_CODE) | LIS2DH12_HR_MASK); 

LIS2DH12_setRegisterValue(LIS2DH12_CTRL_REG5_ADDR, LIS2DH12_FIFO_EN_MASK); //Enable FIFO

LIS2DH12_setRegisterValue(LIS2DH12_FIFO_CTRL_REG_ADDR, LIS2DH12_FIFO_MODE(LIS2DH12_FIFO_FIFO) | LIS2DH12_SAMPLES(FIFOBuffSize-1)); //set FIFO mode and FIFO buffer size

}

My follow control for reading FIFO buffer:

[call My initialization function]

LIS2DH12_setRegisterValue(LIS2DH12_FIFO_CTRL_REG_ADDR, LIS2DH12_FIFO_MODE(LIS2DH12_FIFO_BYPASS) | LIS2DH12_SAMPLES(GSENSOR_CATCH_BUFF_SIZE-1));

LIS2DH12_setRegisterValue(LIS2DH12_FIFO_CTRL_REG_ADDR, LIS2DH12_FIFO_MODE(LIS2DH12_FIFO_FIFO) | LIS2DH12_SAMPLES(GSENSOR_CATCH_BUFF_SIZE-1));

for (;;)

{

Semaphore_pend(Semaphore_handle(&PedoSemaphore), BIOS_WAIT_FOREVER); //waiting the data

       regValue = LIS2DH12_getRegisterValue(LIS2DH12_FIFO_SRC_REG_ADDR); 

sensorReadReg(LIS2DH12_OUT_X_L_ADDR, readBuffer, 6);

LIS2DH12_setRegisterValue(LIS2DH12_FIFO_CTRL_REG_ADDR, LIS2DH12_FIFO_MODE(LIS2DH12_FIFO_BYPASS) | LIS2DH12_SAMPLES(GSENSOR_CATCH_BUFF_SIZE-1));

LIS2DH12_setRegisterValue(LIS2DH12_FIFO_CTRL_REG_ADDR, LIS2DH12_FIFO_MODE(LIS2DH12_FIFO_FIFO) | LIS2DH12_SAMPLES(GSENSOR_CATCH_BUFF_SIZE-1));

}0690X00000609zOQAQ.png

#fifo-buffer-interrupt #lis2dh12 #fifo
1 ACCEPTED SOLUTION

Accepted Solutions
Miroslav BATEK
ST Employee
Posted on March 12, 2018 at 15:19

I suppose the problem is in reading 6 bytes in one I2C transaction.

If you want to read multiple bytes in one transaction you have to set the MSB bit of the register address. Please check chapter 6.1.1 in the

http://www.st.com/content/ccc/resource/technical/document/datasheet/12/c0/5c/36/b9/58/46/f2/DM00091513.pdf/files/DM00091513.pdf/jcr:content/translations/en.DM00091513.pdf

.

It should be like that:

sensorReadReg(0x80 | LIS2DH12_OUT_X_L_ADDR, readBuffer, 6);

View solution in original post

2 REPLIES 2
Miroslav BATEK
ST Employee
Posted on March 12, 2018 at 15:19

I suppose the problem is in reading 6 bytes in one I2C transaction.

If you want to read multiple bytes in one transaction you have to set the MSB bit of the register address. Please check chapter 6.1.1 in the

http://www.st.com/content/ccc/resource/technical/document/datasheet/12/c0/5c/36/b9/58/46/f2/DM00091513.pdf/files/DM00091513.pdf/jcr:content/translations/en.DM00091513.pdf

.

It should be like that:

sensorReadReg(0x80 | LIS2DH12_OUT_X_L_ADDR, readBuffer, 6);

Posted on March 12, 2018 at 18:31

Hi Miroslav,

     You are right. It is workable now.

      Thank you for your helping.

Best Regards,

Allen