Hello,
I was about to try, if interrupt triggers get stored in a queue when another isr is already running, but got some confusing results.
const byte led = 8;
volatile byte leden = false;
const byte in0 = 0;
const byte in1 = 1;
const byte in2 = 2;
volatile bool ledin = false;
void setup()
{
pinMode(in0, INPUT_PULLUP);
pinMode(in1, INPUT_PULLUP);
pinMode(in2, INPUT_PULLUP);
pinMode(led, OUTPUT);
attachInterrupt(digitalPinToInterrupt(in0), isr0, FALLING);
attachInterrupt(digitalPinToInterrupt(in1), isr1, FALLING);
attachInterrupt(digitalPinToInterrupt(in2), isr2, FALLING);
}
void loop()
{
}
void isr0()
{
volatile byte count = 0;
digitalWrite(led, HIGH);
while(count < 200)
{
count++;
delayMicroseconds(16383);
}
}
void isr1()
{
ledin =!ledin;
digitalWrite(LED_BUILTIN, ledin);
}
void isr2()
{
digitalWrite(led, LOW);
}
As show in the sketch, I went in the ISRX, switched on a connected LED and waited 200*16838 µs, before ending the ISRX. In the meantime I triggered the other two interrupts.
Further i changed the ISR-Numbers to analyze the behavior.
Here the measurements with the used Pins.
LED_on LED_off LED_BUILTIN
1 0 1 2 --> LED_BI changed after 3s, the ED turned of after 7s
2 0 2 1 --> LED_BI changed after 7s, LED only turned off after 7s if interrupt was triggered >3s after LED was switched on
3 1 2 0 --> LED_BI changed after 3s, the LED only turned off, if the interrupt was triggered after LED_BI changed, otherwise never turned off
4 1 0 2 --> LED_BI changed after 3s, the LED only turned off, if the interrupt was triggered after LED_BI changed, otherwise never turned off
5 2 0 1 --> LED_BI changed and LED switched off, both after 7s
6 2 1 0 --> LED_BI changed and LED switched off, both after 7s
The Arduino Leoanardo I used, has the following Interupt-Pin configuration
Int 0 1 2 3 4
Pin 3 2 0 1 7
Why the behavior depends on the used Interrupts und therefor sometimes works and sometimes doesnt?
And why the delay is about 7s and not 200*16383s (~3s)?
Hope you can help me