2019-11-19 10:28 AM
I'm currently trying to implement a button interrupt and need to disable the button interrupt after the initial call to the isr to avoid excessive interrupt triggering due to debounce. I'm using STM32CUBEIDE/MX currently. The button works as desired if I use
HAL_NVIC_DisableIRQ(EXTI9_5_IRQn); (in interrupt)
//do some stuff
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); (in main)
but this is non-ideal as it disables exti lines 5 through 9.
I've been trying to mask the EXTI line using EXTI_IMR. This seems to work for the first button press, but I'm never able to re-trigger the ISR
EXTI->IMR &= ~(EXTI_LINE_5);//in ISR
EXTI->IMR &= (EXTI_LINE_5);//in main
Thoughts?
Solved! Go to Solution.
2019-11-19 10:45 AM
DOH! forgot my coffee this morning, sorry this works:
EXTI->IMR &= ~(EXTI_LINE_5);//in ISR
EXTI->IMR |= (EXTI_LINE_5);//in main
2019-11-19 10:45 AM
DOH! forgot my coffee this morning, sorry this works:
EXTI->IMR &= ~(EXTI_LINE_5);//in ISR
EXTI->IMR |= (EXTI_LINE_5);//in main
2019-11-19 11:29 AM
Thanks for coming back with the solution. Can you please select our post as Best so that the thread is marked as resolved.
JW
2021-01-28 10:04 AM
Masking is needed if the interrupt is a level interrupt.
To my understanding the EXTI controller is only Edge triggered so not sure why masking is needed.
2021-01-28 01:30 PM
@deckhard
> To my understanding the EXTI controller is only Edge triggered so not sure why masking is needed.
Masking can be useful for shared EXTI interrupt vectors such as EXTI15_10, EXTI9_5.
It allows to temporary delay only one EXTI pin interrupt without affecting others on the same NVIC vector.
-- pa
2021-01-28 01:43 PM
Just adding to what Pavel told - it can be used for sections or modes of code to make the code interrupt-safe relative to a specific interrupt.
2021-01-28 02:53 PM
Careful with this, the effect of such disable may be delayed...
JW
2021-01-28 08:03 PM
Ok that makes sense
2021-01-28 08:04 PM
That is why the HAL does not natively support masking?
2021-01-28 11:13 PM
No. Cube/HAL inevitably covers only a limited subset of possible functionality, only what is authors deem "usual".
JW