cancel
Showing results for 
Search instead for 
Did you mean: 

I have a problem with the interrupt callback. The interrupt event is correctly detected but when the code enter into the callback function it excecute just the first line of the code wrot between the curly brackets.

GMart.7
Associate II

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Only if you need the functionality of systick in those interrupts, which is typically poor practice, but can work.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

10 REPLIES 10
TDK
Guru

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.

If you feel a post has answered your question, please click "Accept as Solution".
GMart.7
Associate II

0693W00000LzDg1QAF.png

The goal is to turn on the LED for 2 seconds.

Looks like exactly what I guessed, right?. Make SysTick priority higher (numerically lower) than the EXTI priority.

If you feel a post has answered your question, please click "Accept as Solution".
GMart.7
Associate II

0693W00000LzDsvQAF.pngThe 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.

Probably for 4 seconds if the pin isn’t debounced.
If you feel a post has answered your question, please click "Accept as Solution".
GMart.7
Associate II

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?

Only if you need the functionality of systick in those interrupts, which is typically poor practice, but can work.
If you feel a post has answered your question, please click "Accept as Solution".
GMart.7
Associate II

Thank you.