I'm attempting to use the GPIO interrupts to detect the rising and falling edges on some switches, but I'm having trouble with some interrupts firing as soon as I enable them using GPIO_EnableIRQ.
For example, I've got a rising-edge interrupt on a pin which is initially low. There's also a falling-edge interrupt on the same pin which does not immediately fire.
Similarly the falling-edge interrupt fires on a pin which is initially high.
Is there any way to suppress this immediate interrupt so that my edge-triggered interrupts only fire on edges?
Device:
Hi Eric,
I am not sure i understand the question, i dont see any firing up of the interrupts as soon as i invoke the GPIO_EnableIRQ() unless the pin is at the state that fires the interrupt (if you set the interrupt to be triggered at the opposite state that triggers at your current setup, the interrupt will still be triggered ?), you can try to manually reset the interrupt (GPIO_ResetIRQ() before enabling the corresponding interrupt) and check if that solves what you are experiencing. Regarding the Edge interrupts, in the 580 the GPIO interrupts are level triggered and not edge triggered, but you will be able to detect the transition from high to low or the opposite by changing the polarity of the interrupt as soon as it triggers, something like the below snippet:
void irq0_interrupt_cb(void)
{
if (GPIO_GetIRQInputLevel(GPIO0_IRQn)==GPIO_IRQ_INPUT_LEVEL_LOW)
{
GPIO_SetActive(LED_PORT, LED_PIN);
GPIO_SetIRQInputLevel(GPIO0_IRQn,GPIO_IRQ_INPUT_LEVEL_HIGH);
}
else
{
GPIO_SetInactive(LED_PORT, LED_PIN);
GPIO_SetIRQInputLevel(GPIO0_IRQn,GPIO_IRQ_INPUT_LEVEL_LOW);
}
}
也有关you are facing please have a look at the additional parameters that the GPIO_EnableIRQ, the debounce for example or the release_wait, perhaps there the line that drives the interrupt has spikes that trigger the interrupt.
Thanks MT_dialog
Thank you, I seem to have misunderstood the API. I had the impression that the interrupts could be configured for edge detection, if that's not the case then the errors I was experiencing make sense.