cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable/MASK an exti line ON THE FLY

Craig1
Associate

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?

1 ACCEPTED SOLUTION

Accepted Solutions
Craig1
Associate

DOH! forgot my coffee this morning, sorry this works:

EXTI->IMR &= ~(EXTI_LINE_5);//in ISR

EXTI->IMR |= (EXTI_LINE_5);//in main

View solution in original post

19 REPLIES 19
Craig1
Associate

DOH! forgot my coffee this morning, sorry this works:

EXTI->IMR &= ~(EXTI_LINE_5);//in ISR

EXTI->IMR |= (EXTI_LINE_5);//in main

Thanks for coming back with the solution. Can you please select our post as Best so that the thread is marked as resolved.

JW

deckhard
Associate III

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.

@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

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.

Careful with this, the effect of such disable may be delayed...

JW

Ok that makes sense

That is why the HAL does not natively support masking?

No. Cube/HAL inevitably covers only a limited subset of possible functionality, only what is authors deem "usual".

JW