2025-06-04 8:40 AM
Hello ,
I'm using an STM32U575 with an I2C connection to the AIS2DW12 accelerometer. The goal is to generate an interrupt when a free-fall event is detected. I followed the instructions provided in the datasheet (AN5326 - AIS2DW12 ultralow-power 3-axis accelerometer for automotive applications, STMicroelectronics).
I created a function to initialize the device using the specified register values, but no interrupt is detected. There are no hardware issues—when I force the INT1 pin to a high level, the MCU correctly enters the interrupt function. Later, I found a GitHub example for free-fall detection that doesn’t use interrupts. I still imported that code block into my project as an additional initialization function :
void AIS2DW12_FallDetection_Init(void) {
Ais2dw_ctx.write_reg = platform_ASW12_write;
Ais2dw_ctx.read_reg = platform_ASW12_read;
Ais2dw_ctx.mdelay = platform_ASW12_delay;
Ais2dw_ctx.handle = &hi2c3;
uint8_t whoamI, rst;
ais2dw12_reg_t int_route;
ais2dw12_device_id_get(&Ais2dw_ctx, &whoamI);
if (whoamI != AIS2DW12_ID)
while (1) {
/* manage here device not found */
}
/* Restore default configuration */
ais2dw12_reset_set(&Ais2dw_ctx, PROPERTY_ENABLE);
do {
ais2dw12_reset_get(&Ais2dw_ctx, &rst);
} while (rst);
/* Configure power mode */
ais2dw12_power_mode_set(&Ais2dw_ctx, AIS2DW12_PWR_MD_4);
/* Set Output Data Rate */
ais2dw12_data_rate_set(&Ais2dw_ctx, AIS2DW12_XL_ODR_100Hz);
/* Set full scale to 2 g */
ais2dw12_full_scale_set(&Ais2dw_ctx, AIS2DW12_2g);
/* Configure Free Fall duration and samples count */
ais2dw12_ff_dur_set(&Ais2dw_ctx, 0x06);
ais2dw12_ff_threshold_set(&Ais2dw_ctx, AIS2DW12_FF_TSH_10LSb_FS2g);
/* Enable free fall interrupt */
ais2dw12_pin_int1_route_get(&Ais2dw_ctx, &int_route.ctrl4_int1);
int_route.ctrl4_int1.int1_ff = PROPERTY_ENABLE;
ais2dw12_pin_int1_route_set(&Ais2dw_ctx, &int_route.ctrl4_int1);
/* Set latched interrupt */
ais2dw12_int_notification_set(&Ais2dw_ctx, AIS2DW12_INT_LATCHED);
}
In main function i've inserted this part:
int checkevent(void){
Ais2dw_ctx.write_reg = platform_ASW12_write;
Ais2dw_ctx.read_reg = platform_ASW12_read;
Ais2dw_ctx.mdelay = platform_ASW12_delay;
Ais2dw_ctx.handle = &hi2c3;
/* Check Free Fall events */
ais2dw12_all_sources_t src;
ais2dw12_all_sources_get(&Ais2dw_ctx, &src);
if ((src.all_int_src.ff_ia) || (src.status_dup.ff_ia) || (src.wake_up_src.ff_ia)) {
return 1;
}
return 0;
}
This code is taken from https://github.com/STMicroelectronics/STMems_Standard_C_drivers/blob/master/ais2dw12_STdC/examples/ais2dw12_free_fall.c
Even with this method, the return value never changes to 1, despite aggressively moving the device. I’m using the STEVAL-MKI206V1 evaluation board. Do you have any suggestions to resolve this?
Thanks
2025-06-06 3:04 AM
Hi @mauroalba ,
Good job in taking the code from the official drivers.
The function "checkevent" that you implement is called continuously in the while(1) similarly to the official example?
Have you verified, maybe logging the data, that with your test you manage to overcome FF threshold?
With other type of mechanism, like DATAREADY, the interrupt works?
2025-06-06 5:19 AM
Hi
Yes, checkevent() is called continuously in the main loop, and I can see the read values change when I move the device. I also used a function (taken from an example) to read values directly from the device, and these values change as expected when moving it. This confirms that the device is working and communicating properly.
I’ve tried setting very low threshold values, but the result remains the same—no interrupt is triggered. No other checks or mechanisms are being used. The threshold interrupt is exactly what I need, and it seems simple to implement, yet some hidden issue is preventing it from working.