Using interrupt as trigger to read LISD2W12's FIFO
Hi,
I started working with LIS2DW12 trying to acquire simple data in pooling mode. I've done this wihtout any troubles using STM's mems drivers.
Now, I'm trying to take this to a next level and I'm trying to work with LISDW12 FIFO's in interrupting mode.
So I'm using a GPIO in EXT mode with the following configuration:
Furthermore, the interrupts has a priority of 0.
And I'm setting up the Accelerometer as following:
lis2dw12_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
is2dw12_full_scale_set(&dev_ctx, lis2dw12.scale);
lis2dw12_power_mode_set(&dev_ctx, lis2dw12.power_mode);
lis2dw12_data_rate_set(&dev_ctx, lis2dw12.data_rate);
lis2dw12_fifo_watermark_set(&dev_ctx, 6*31);
lis2dw12_fifo_mode_set(&dev_ctx, LIS2DW12_STREAM_MODE);
// Enable interrupt to FIFO TH
lis2dw12_pin_int2_route_get(&dev_ctx, &int_route.ctrl5_int2_pad_ctrl);
int_route.ctrl5_int2_pad_ctrl.int2_fth = PROPERTY_ENABLE;
lis2dw12_pin_int2_route_set(&dev_ctx, &int_route.ctrl5_int2_pad_ctrl);
lis2dw12_int_notification_set(&dev_ctx, LIS2DW12_INT_LATCHED);And of course I override GPIO's callback in this manner:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin){
if ( GPIO_Pin == GPIO_PIN_3)
{
uint8_t num_pattern;
uint8_t flags;
uint16_t num = 0;
// Check if FIFO level over threshold
lis2dw12_fifo_wtm_flag_get(&dev_ctx, &flags);
if (flags)
{
/* Read number of sample in FIFO */
lis2dw12_fifo_data_level_get(&dev_ctx, &num);
num_pattern = num / OUT_XYZ_SIZE;
while (num_pattern-- > 0)
{
/* Read XL samples */
lis2dw12_acceleration_raw_get(&dev_ctx, data_raw_acceleration.u8bit);
acceleration_mg[0] = lis2dw12_from_fs2_to_mg(data_raw_acceleration.i16bit[0]);
acceleration_mg[1] = lis2dw12_from_fs2_to_mg(data_raw_acceleration.i16bit[1]);
acceleration_mg[2] = lis2dw12_from_fs2_to_mg(data_raw_acceleration.i16bit[2]);
}
}
}
}The problem is that inside the callback I cant call any HAL methods. After I digging in the code I've check that it falls in the following line:
if (I2C_RequestMemoryRead(hi2c, DevAddress, MemAddress, MemAddSize, Timeout, tickstart) != HAL_OK)Throwing an exception.
Any help would be appreciated.
Best regards
