2022-04-27 05:53 AM
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
{
if(GPIO_Pin == LVMS_DETECT_Pin)
{
HAL_GPIO_WritePin(AMS_LED_GPIO_Port, AMS_LED_Pin, GPIO_PIN_SET);
HAL_Delay(2000);
HAL_GPIO_WritePin(AMS_LED_GPIO_Port, AMS_LED_Pin, GPIO_PIN_RESET);
}
}
When the trigger event happent to the LVMS_DETECT_Pin, the code enter into the callback and turn on the LED without turn it off after 2 seconds.
It is not the first time I noticed this behaviour, it jus execute the first line of the code.
I'm working on Nucleo F401RE.
Solved! Go to Solution.
2022-04-27 08:36 AM
2022-04-27 06:38 AM
Probably your SysTick interrupt is same/lower priority as your EXTI interrupt, so the code just stalls there during HAL_Delay.
Having a 2s blocking delay in an interrupt isn't a good practice.
In any case, debug your code. Run it, wait for the bad event to happen, hit pause, and see where the code is at.
2022-04-27 07:09 AM
2022-04-27 07:10 AM
The goal is to turn on the LED for 2 seconds.
2022-04-27 07:11 AM
Looks like exactly what I guessed, right?. Make SysTick priority higher (numerically lower) than the EXTI priority.
2022-04-27 07:37 AM
The Preemption Priority of Time Base: SysTick Timer was setted to 15 (default) meanwhile all the others to 0.
Now I set SysTick Timer Preemption Priority to 0 and the EXTI to 1.
This solved the problem but i noticed that the LED remain turned up for something more than 3 second insted of 2.
2022-04-27 07:39 AM
2022-04-27 08:22 AM
The pin is normally low (connected to GND) and internally pulled down. To generate the event I connect it to 3V3 and then again to GND.
At the end, is correct to say that the Sys Tick Timer must have always the higher priority with respect of the others interrupt?
2022-04-27 08:36 AM
2022-04-27 08:37 AM
Thank you.