I am having weird problems with external interrupts. It all works great with 5 of them, but when I add 6th, core crashes (red blinking status LED). All pins are used to handle buttons without any debouncing (done in software for now). Code is quite complex already (a large library plus client code I am developing), but what works:
Interrupts are attached to pins D2, D3, D4, A0, A1, relevant, incomplete code:
int gaugeA = D2;
int gaugeB = D3;
// several more pins defined...
volatile int8_t gaugeChange;
void setup() {
pinMode(gaugeB, INPUT_PULLUP);
pinMode(gaugeA, INPUT_PULLUP);
// ...
attachInterrupt(gaugeA, isr_gaugeMinus, RISING);
attachInterrupt(gaugeB, isr_gaugePlus, RISING);
// ...
}
void isr_gaugeMinus() {
gaugeChange = -1;
}
void isr_gaugePlus() {
gaugeChange = 1;
}
All ISRs look about the same as in example, main code just checks variables controlled by ISR and acts on them (and resets them to neutral value). And crash I am seeing seems not related to any my interrupts.
Core also communicares using UDP and dumps debug informations on Serial console. At the start, it waits for communication on Serial console, calling while(!Serial.available()) Spark.process();
in setup()
. All works great, until I add 6th interrupt. Several variants of strange behaviour happen:
-
Button on A6 - code crashes after a second or so after communication starts, without touching any buttons (no interrupts). Some UDP (send and receive 2-3 packets) and Serial communication happens, core locks up in same moment in the middle of receiving text over serial. Code processes UDP packets as they arrive, so it is hard to tell when exactly it crashes. Commenting out
attachInterrupt()
(keeping pin setup) makes code run as befrore. -
Button on A7 - no crashes, except interrupt is not working.
-
Commented out other interrupt, button on A6 or A7 - no crashes, no interrupt
-
Button on A7, polling it in addition to interrupt - no interrupt, but
digitalRead()
catches the value
Is there any limit on external interrupts? Datasheet says 16 interrupt vectors. I expect some interrupts are used for Spark itself (WiFi, buttons), but is should leave at least 6 interrupts free (although I would like to have 7 at least). Or any other ideas?