-->
Page 1 of 11

How to clear pending interrupt

PostPosted: Wed Jan 04, 2017 8:16 pm
by dfrap
The Arduino code does not clear pending interrupts on attachInterrupt Even though most consider this a bug, they have decided not to change the way it works. https://github.com/arduino/Arduino/issues/510

So before I attach interrupts, I clear pending interrupts by clearing the EIFR which is an Atmel specific flag that is available to Arduino programs running on traditional Arduino hardware.

Section 2.2.4 of the ESP8266 Technical Reference describes:
Interrupt clearing register GPIO_STATUS_W1TC
Bit[15:0] (readable and writable):
Write 1 into the related bit, the related GPIO interrupt status will be cleared.

But I can't find anything like GPIO_STATUS_W1TC in any of the header files. How do I access this register from my Arduino sketch? Am I missing another way to clear pending interrupts on the ESP8266?

Re: How to clear pending interrupt

PostPosted: Thu Jan 05, 2017 9:30 pm
by dfrap
I found that the Interrupt clearing register GPIO_STATUS_W1TC is part of the SDK. To use those API functions, external C headers must be included.

// Include API-Headers
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "cont.h"
}
unsigned long gpio_status;

//Clear GPIO Interrupt Status
gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
attachInterrupt(digitalPinToInterrupt(PIN), keypress, FALLING);

Re: How to clear pending interrupt

PostPosted: Tue Jan 08, 2019 6:26 pm
by lucasromeiro
dfrap wrote:I found that the Interrupt clearing register GPIO_STATUS_W1TC is part of the SDK. To use those API functions, external C headers must be included.

// Include API-Headers
extern "C" {
#include "ets_sys.h"
#include "os_type.h"
#include "osapi.h"
#include "mem.h"
#include "user_interface.h"
#include "cont.h"
}
unsigned long gpio_status;

//Clear GPIO Interrupt Status
gpio_status = GPIO_REG_READ(GPIO_STATUS_ADDRESS);
GPIO_REG_WRITE(GPIO_STATUS_W1TC_ADDRESS, gpio_status);
attachInterrupt(digitalPinToInterrupt(PIN), keypress, FALLING);


Hello, this problem continues?

I'm having problems with the external interruption!
It causes bug in my code and I do not know why!
I use it to read pulses with a frequency of max 50hz
but with much less than that, the esp locks and resets!
I still have not figured out the reason, but I suspect the interrupt is changing the value of the variable at the same time of some operation with it! it ends up crashing.
So I plan to enable an external interrupt without an ISR. (function that will be called when the interruption occurs)
Then I read the flag recorder to see if there was or not the interrupt and clean this recorder! I do not know if it is resolved or if it is possible.
But I would use this knowledge you posted here.
Can you give me advice?
Thank you!

Re: How to clear pending interrupt

PostPosted: Tue Jan 08, 2019 7:07 pm
by McChubby007
I very much doubt that that is your problem.

Can you zip and attach your code and I will look at it. If nothing else I will give it a once over with my critical eye.

Briefly, can you describe what and how you are doing things? Are you using an interrupt routine (ISR) at the moment, and if not how are you timing each operation? In any case, post the code and I'm sure I will work it out.