cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_GPIO_EXTI_Callback, falling and rising

Posted on February 09, 2017 at 14:23

Hi. I'm using the HAL_GPIO_EXTI_Callback function to have an event when a pin is falling or is rising.

To know if a pin is low or high I use this function

if (__HAL_GPIO_EXTI_GET_IT(GPIO_Pin)== GPIO_PIN_RESET) {

} else {

}

but the functions seems to not work prerfectly. Sometimes the function returns a wrong value.

Is there another way to do that?

Many thanks.

1 REPLY 1
S.Ma
Principal
Posted on February 18, 2017 at 18:27

The simplest way is to setup EXTI as triggering an interrupt on both edges.

In the interrupt, read the pin level to know if it was a rise or falling edge.

Memorize this bit in a global variable. This way you can check it has toggled between 2 interrupt.

If not, you detected the edge to edge time duration is too fast for the interrupt to work.

If this happens, you'll have to giveup on EXTI and use TIMER Channel input captures for this job (with edge prescaler, or DMA rolling buffer on captures, or use 2 channels one for rising, 1 for falling with DMAs)