1. I am new to ESP32S Platform and trying to understand its interrupt structure by writing/experimenting UNO-styled interrupt sketches.
2. In the following ESP32S Interrupt Experiment, the MCU does not respond to external interrupt when the sketch contains an infinite local loop in the loop() function. Would appreciate if someone guides to the appropriate path. Hardware Setup:
#define IRQ18 18
volatile bool flag = false;
void IRAM_ATTR ISR18()
{
flag = true;
}
void setup()
{
Serial.begin(115200);
pinMode(IRQ18, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(IRQ18), ISR18, FALLING);
}
void loop()
{
if (flag == true)
{
Serial.println("Interrupt has occurred.");
flag = false;
noInterrupts(); //to prevent recurrent interrupt
}
if (digitalRead(4) == LOW)
{
Serial.println("Closed key detected.");
while (true) //local infinite loop
{
;
}
}
}
3. In my hardware setup (Fig-1), there is Btn-1 connected with DPin-4 with internal pull-up resistor to feed a status to the MCU. Also, there is Btn-2 connected at DPin-18 to inject interrupt signal to the MCU.
4. Sketch Behavior (1) I press Btn-1, the MCU detects it and then locked into an empty infinite local loop.
while(true)
{
;
}
OUTPUT:
Closed key detected.
2. I press Btn-2 to inject interrupt signal, the MCU is not interrupted as this message: "Interrupt has occurred." does not appear on Serial Monitor.
3. I re-run the sketch by pressing pressing the EN-button of the ESP32S Kit. Open the Serial Monitor. Press Btn-2 to inject interrupt signal, The MCU is interrupted due to IRQ signal at DPin-18, and the MCU is also interrupted by WDT. OUTPUT:
Interrupt has occured.
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
This is just for test purpose as Btn-2 (the interrupting device) bounces and the MCU is interrupted for each bounce. Thinking to install external hardware based (using 74LS123 one-shot) debounce circuit.
I have not yet known how to disable only one local interrupt (the IRQ18) leaving the Global Interrupt Enable Bit active.
But for test purposes in the demonstration Lab, I use a jumper wire to inject an interrupt request signal and then disable the interrupt logic globally in the sketch to stop recurrent interrupt triggering. Is it ok?
sort of a dilemma, trying to demonstrate code using an interrupt that requires additional code because of the source (button switch) being used.
i can understand why you want to disable the interrupt. could try detaching the interrupt, but code wouldn't typically do this. adding code to ignore a 2nd interrupt within some time of a first might be more reasonable
have you consider using a photo transistor. it won't bounce. perhaps a pair < 1inch apart and 2 interrupts measuring the speed of an object passing across them
Congratulation! You have detected the flaw of my program/sketch. Once the isr() function is done, the control goes back to the local loop; as a result, my print() command at the beginning of loop() function is not encountered at all. How could be that I overlooked such an obvious reasoning?
For test purposes, I can print the debug message (Interrupt has occurred) in the isr() function.
In the following ESP32S Interrupt Experiment, the MCU does not respond to external interrupt when the sketch contains an infinite local loop in the loop() function. What could be the reason? There are issues with WDT which may appear in later posts.