How to prevent GPIO Interrupt from keep firing

mojhggn
Posts: 3
Joined: Tue Jun 23, 2015 1:32 am

How to prevent GPIO Interrupt from keep firing

Postby mojhggn » Sat Aug 15, 2015 7:22 pm

Hi everybody,

Could anyone guide me on the following issue.
I am pairing ds3231 RTC with esp-12. GPIO4 is SCL, GPIO5 is SDA. GPIO12 is setup as input to detect falling-edge with pull-up enabled.
When RTC alarm1 matches, it sends neg signal, interrupt callback fires. But it keeps firing until watchdog takes over. I can disable the interrupt and code in callback works fine. But I can not trap the second alarm interrupt as interrupt is disabled.

Thanks.

eriksl
Posts: 159
Joined: Fri May 22, 2015 6:22 pm

Re: How to prevent GPIO Interrupt from keep firing

Postby eriksl » Sat Aug 15, 2015 9:38 pm

The procedure for getting a pin change interrupt (in ATmel lingo) is a bit... peculiar. Do it exactly the way I now do it, and it works. Do it any differently and it doesn't work. The documentation about this is really... substandard.

https://github.com/eriksl/esp8266-unive ... ios.c#L209

In short: enable the interrupt "somewhere". When it fires you will get to the handler. At that point CLEAR ALL INTERRUPTS using gpio_intr_ack(pc). You cannot selectively ack one pin's interrupt and rely on the handler being called again for that interrupt. Now check the pc (mask) for all interrupts that fired set a flag for them "somewhere" and handle them later (not in the interrupt handler!). That "later" might a "posted" callback or a timer (or even better, a posted callback FROM a timer). At that point when you have actually handled the interrupt, you can enable it again, which is required. It's all one-shot, apparently.

Don't use the examples you'll find with google, they're for older SDK-versions.

Who is online

Users browsing this forum: No registered users and 28 guests