cancel
Showing results for 
Search instead for 
Did you mean: 

LIS2DH12 init problem for FIFO stream mode

szgabor.flowide
Associate

Hi Everybody,

I have a weird problem initializing LIS2DH12 in FIFO stream mode with the official ST driver. This is my initialization code:

bool lis2dh12wInit(lis2dh12w_cfg_t *cfg)
{
  uint8_t whoamI;
  lis2dh12_ctrl_reg3_t ctrl_reg3;
 
  /* set read and write functions for the platform-independent driver */
  dev_ctx.write_reg = platform_write;
  dev_ctx.read_reg = platform_read;
  dev_ctx.handle = NULL;   // this optional parameter is not used
 
  /* check device ID */
  lis2dh12_device_id_get(&dev_ctx, &whoamI);
  if (whoamI != LIS2DH12_ID) return false;   // not o.k.
 
  cfgSave = *cfg;
 
  /* reset register contents */
  lis2dh12_boot_set(&dev_ctx, 1);
  /* enable Block Data Update to avoid reading data values related to different samples */
  lis2dh12_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
  /* set Output Data Rate */
  lis2dh12_data_rate_set(&dev_ctx, cfg->odr);
  /* set full scale */
  lis2dh12_full_scale_set(&dev_ctx, cfg->fullScale);
  /* set device resolution (continuous mode) */
  lis2dh12_operating_mode_set(&dev_ctx, cfg->highRes ? LIS2DH12_HR_12bit : LIS2DH12_LP_8bit);
  if (cfg->fifo == 0) {   // normal mode
    /* set interrupt */
    memset(&ctrl_reg3, 0, sizeof(ctrl_reg3));   // reset all flags
    ctrl_reg3.i1_zyxda = 1;   // "data available" interrupt
    lis2dh12_pin_int1_config_set(&dev_ctx, &ctrl_reg3);
  } else {   // FIFO mode
    md_external_delay_ms(10);   // MAGIC: somewhy this is needed to make it work
    /* enable FIFO */
    lis2dh12_fifo_set(&dev_ctx, 1);
    /* set FIFO watermark level */
    lis2dh12_fifo_watermark_set(&dev_ctx, (cfg->fifo - 1) & 0x1F);
    /* set FIFO mode */
    lis2dh12_fifo_mode_set(&dev_ctx, LIS2DH12_DYNAMIC_STREAM_MODE);
    /* set interrupt */
    memset(&ctrl_reg3, 0, sizeof(ctrl_reg3));   // reset all flags
    ctrl_reg3.i1_wtm = 1;   // "FIFO watermark" interrupt
    lis2dh12_pin_int1_config_set(&dev_ctx, &ctrl_reg3);
  }
 
  return true;
} /* lis2dh12wInit */

I spent a lot of time to figure out that it is working with the magic delay inserted to line 33. Without it the sensor will also generate watermark interrupts fine, but the acceleration value is always the same (reads the same FIFO item for infinity?). With this 10 msec delay strictly before enabling FIFO it is o.k.

What may be the reason of this strange behaviour? I've found nothing in community topics and the documentation. Thank you in advance.

Gábor

1 REPLY 1
TBomb.1
Senior II

Hi Gábor, probably this is due to a combination of the debugging tool delays and internal FIFO settings.

Did you insert this value by yourself? And what if you change the device or, if possible, the debug IDE? And what if you increase this delay?

PS: note that the BOOT command of line lis2dh12_boot_set(&dev_ctx, 1) needs at least 5 milli-seconds to be effective. To check whether the issue is related to this, you can remove this command line and check if you still need the delay.

Tom