Skip to main content
Visitor II
November 30, 2020
Question

Gets the same value every time after enabling FIFO and setting FIFO mode(LIS2DH12)

  • November 30, 2020
  • 1 reply
  • 811 views

I am using the LIS2DH12 accelerometer in our product. I am trying to use FIFO.

I have set watermark level to 10 and use fifo buffer in fifo mode.

Every 1 sec I have read data from output register but every time I got same value irrespective of accelerometer is in stable or moving position.

The Configuration settings used as follows

static uint8_t x_buf [10]={0};

static uint8_t y_buf [10]={0};

static uint8_t z_buf [10]={0};

spi_write_reg(LIS2DH_CTRL_REG1, 0X2F); // ODR 10HZ AND LOW POWER MODE ENABLE

spi_write_reg(LIS2DH_CTRL_REG2, 0X00); // HIGH PASS FILTER DISABLED

spi_write_reg(LIS2DH_CTRL_REG4, 0X80); // BLOCK DATA UPDATE AND FS = ±2 g  

spi_write_reg(LIS2DH_CTRL_REG5, 0x48); // FIFO ENABLE & LATCH ENABLE ON INT1

spi_write_reg(LIS2DH_FIFO_CTRL_REG, 0x4A); // FIFO MODE SELECTED AND NO OF SAMPLE - 10

spi_write_reg(LIS2DH_CTRL_REG3, 0x04);   // FIFO WATERMARK INTERRUPT ENABLE 0N INT1

After 1 Sec

void fifo_read()

{

uint8_t watermark_val;

watermark_val = spi_read_reg(LIS2DH_FIFO_SRC_REG);

if( watermark_val == 0x8B)

{

for( uint8_t i = 0; i< 10; i++)

{

x_buf[i] = spi_read_reg(LIS2DH_OUT_X_H);

y_buf[i] = spi_read_reg(LIS2DH_OUT_Y_H);

z_buf[i] = spi_read_reg(LIS2DH_OUT_Z_H);

}

spi_write_reg(LIS2DH_FIFO_CTRL_REG, 0x00); // RESET FIFO

spi_write_reg(LIS2DH_FIFO_CTRL_REG, 0x4A); // FIFO MODE SELECTED AND NO OF SAMPLE - 10

}

}

Can you tell me whether the above is correct? My requirement is to store 10 samples in FIFO and read them every 1s for further processing.

    This topic has been closed for replies.

    1 reply

    ST Employee
    December 2, 2020

    Hi @PD_learner​ ,

    I'm wondering whether you might never enter in the condition:

    if( watermark_val == 0x8B)

    The meaning of that register is the following one:

    0693W000006ENABQA4.pngYou may limit the condition of the loop to the first bit value of the above register.

    You can in any case take inspiration from this code on Github designed for a product similar to the LIS2DH12 (with the "12" in the end, right?), in its register map --> lis3dh_multi_read_fifo.c

    -Eleon