cancel
Showing results for 
Search instead for 
Did you mean: 

LIS3DH: FIFO only retrieved once

dumdum
Associate

Hello,

actually I am want to read data from fifo of the lis3dh sensor. I follow the datasheet and application note:

write 00000000 in TEMP_CRG_REG

write 00100111 in CTRL_REG1

write 10001000 in CTRL_REG4

write 01011110 in FIFO_CTRL_REG

write 10000000 in CTRL_REG5

clear fifo in while loop until FIFO_SRC_REG&0x20 == 0 (check for empty flag)

write 01011110 in FIFO_CTRL_REG

wait until watermark flag is activated (i.e. FIFO_SCR_REG&0x80==0)

read values since empty flag stays 0 (i.e. FIFO_SRC_REG&0x20==0)

Unfortunately it works exactly once. Than the watermark will never be reached again (I was waiting appr. 1h). Also there seems to be no change at the FSS bits of the FIFO_SCR_REG. Has anybody a hint for me what can be the root cause and how to overcome that issue? Thanks a lot.

Kind regards,

Philipp

1 REPLY 1
Eleon BORLINI
ST Employee

Hi @dumdum​ , I suggest you to check the online-available C examples on Github for the LIS3DH device, in particular the multi_read_fifo.c file.

The configuration section is the following one:

/* Enable Block Data Update*/
  lis3dh_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
 
  /* Set Output Data Rate to 25 hz  */
  lis3dh_data_rate_set(&dev_ctx, LIS3DH_ODR_25Hz);
 
  /* Set full scale to 2 g*/
  lis3dh_full_scale_set(&dev_ctx, LIS3DH_2g);
 
  /* Set operating mode to high resolution */
  lis3dh_operating_mode_set(&dev_ctx, LIS3DH_HR_12bit);
  
  /* Set FIFO watermark to 25 samples*/
  lis3dh_fifo_watermark_set(&dev_ctx, 25);
 
  /* Set FIFO mode to Stream mode: Accumulate samples and override old data*/
  lis3dh_fifo_mode_set(&dev_ctx, LIS3DH_DYNAMIC_STREAM_MODE);
 
  /* Enable FIFO*/
  lis3dh_fifo_set(&dev_ctx, PROPERTY_ENABLE);

The loop section is the following one:

while(1)
  {
    uint8_t flags;
    uint8_t num = 0;
 
    /* Check if FIFO level over threshold*/
    lis3dh_fifo_fth_flag_get(&dev_ctx, &flags);
    if (flags)
    {
      /* Read number of sample in FIFO*/
      lis3dh_fifo_data_level_get(&dev_ctx, &num);
      while (num-- > 0)
      {
        /* Read XL samples*/
        lis3dh_acceleration_raw_get(&dev_ctx, data_raw_acceleration.u8bit);
        acceleration_mg[0] = lis3dh_from_fs2_hr_to_mg(data_raw_acceleration.i16bit[0]);
        acceleration_mg[1] = lis3dh_from_fs2_hr_to_mg(data_raw_acceleration.i16bit[1]);
        acceleration_mg[2] = lis3dh_from_fs2_hr_to_mg(data_raw_acceleration.i16bit[2]);
 
        sprintf((char*)tx_buffer, "Acceleration [mg]:%4.2f\t%4.2f\t%4.2f\r\n",
                acceleration_mg[0], acceleration_mg[1], acceleration_mg[2]);
                tx_com(tx_buffer, strlen((char const*)tx_buffer));
      }
    }
  }

Regards