2020-07-12 03:41 PM
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
2020-07-14 06:56 AM
Hi @Community member , but do you need to read data in synchronous way, i.e. triggering the dataout with the DRDY data-ready signal (so you can refer to this file lis2dw12_read_data_single.c), or do you need to implement the trigger with FIFO flags? Regards
2020-07-14 08:23 AM
Basically when the Fifo passes the watermark threshold I want to read its data. For that I'm using interrupt 2 connected to GPIO_PIN 3. Am I doing anything wrong?
2020-07-16 03:34 AM
Hi @Community member , it could be a problem related to a multiple access of the code to the I2C block: when the interrupt is raised, the driver functions access the I2C bus in order to read the sensor, that may interrupt the concurrent access to the bus from the main or from another interrupt. Can you please check if there are multiple accesses on that bus? Regards