How to cancel the Interrupts Stack?
Posted: Mon Sep 03, 2018 8:29 am
Hi,
My code is similar to this:
I used the mux technique to replace the cli() and sei() of normal Arduino.
But I've found that even portENTER_CRITICAL_ISR(&mux); and portEXIT_CRITICAL_ISR(&mux); is placed in void IRAM_ATTR handleInterrupt() to stop other Interrupts. If the interrupt is triggered multiple times in a short time, there will be ONE extra interrupt behind the triggered one.
I've tested several times, there always ONE in the queue, won't get 2 or 3. I googled the situation and found this article about Switch Bounce.
https://www.allaboutcircuits.com/techni ... l-with-it/
I don't remember I've meat this situation when using AVR or ESP8266, cause normally an interrupt won't be interrupted and there seems no stack, the extra interrupt is ignored or not be detected.
Cause I'm using my code and other libraries which are written for ESP8266 and normal Arduinos.
Are there any solutions to cancel the interrupt stack of ESP32 to make it act like a normal Arduino?
And why the first line of {portENTER_CRITICAL_ISR(&mux);} won't cancel the following interrupt?
There is no other interrupt happen in the middle of handleInterrupt(), but if an interrupt is triggered when the handleInterrupt() processing, it will be stacked and wait in the queue. How to cancel this? I want interrupts to be ignored when an Interrupt() is processing.
My code is similar to this:
Code: Select all
const byte interruptPin = 25;
volatile int interruptCounter = 0;
int numberOfInterrupts = 0;
[b]portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED;[/b]
void [b]IRAM_ATTR [/b]handleInterrupt() {
[b]portENTER_CRITICAL_ISR(&mux);[/b]
interruptCounter++;
[b]portEXIT_CRITICAL_ISR(&mux);[/b]
}
void setup() {
Serial.begin(115200);
Serial.println("Monitoring interrupts: ");
pinMode(interruptPin, INPUT_PULLUP);
[b]attachInterrupt(digitalPinToInterrupt(interruptPin), handleInterrupt, FALLING);[/b]
}
void loop() {
if(interruptCounter>0){
[b]portENTER_CRITICAL(&mux);[/b]
interruptCounter--;
[b]portEXIT_CRITICAL(&mux);[/b]
numberOfInterrupts++;
Serial.print("An interrupt has occurred. Total: ");
Serial.println(numberOfInterrupts);
}
}
But I've found that even portENTER_CRITICAL_ISR(&mux); and portEXIT_CRITICAL_ISR(&mux); is placed in void IRAM_ATTR handleInterrupt() to stop other Interrupts. If the interrupt is triggered multiple times in a short time, there will be ONE extra interrupt behind the triggered one.
I've tested several times, there always ONE in the queue, won't get 2 or 3. I googled the situation and found this article about Switch Bounce.
https://www.allaboutcircuits.com/techni ... l-with-it/
I guess ESP32 stacks up ONE waiting interrupt.and some microcontrollers might stack up one waiting interrupt.
I don't remember I've meat this situation when using AVR or ESP8266, cause normally an interrupt won't be interrupted and there seems no stack, the extra interrupt is ignored or not be detected.
Cause I'm using my code and other libraries which are written for ESP8266 and normal Arduinos.
Are there any solutions to cancel the interrupt stack of ESP32 to make it act like a normal Arduino?
And why the first line of {portENTER_CRITICAL_ISR(&mux);} won't cancel the following interrupt?
There is no other interrupt happen in the middle of handleInterrupt(), but if an interrupt is triggered when the handleInterrupt() processing, it will be stacked and wait in the queue. How to cancel this? I want interrupts to be ignored when an Interrupt() is processing.