Interruptions do not work in certain situations

Hello,
I cannot figure out why the program hangs on the interrupt service routine. I tried to create an external interrupt and all was fine, than, I tried to create another interrupt, but this time after the execution of the interrupt service routine nothing happens, as if the program counter gets stuck there. Idk why.

#define zece_secunde 6000
#define trei_secunde 3000
#define exceptie 2000
#define minut 15000

void setup() {

  pinMode(LED_BUILTIN,OUTPUT);
  digitalWrite(LED_BUILTIN,HIGH);
  //inputs:
  pinMode(A0,INPUT_PULLUP);
  pinMode(A1,INPUT_PULLUP);
  pinMode(A2,INPUT_PULLUP);
  pinMode(A3,INPUT_PULLUP);
  //outputs:
  pinMode(A4,OUTPUT);
  pinMode(A5,OUTPUT);
  pinMode(A6,OUTPUT);
  //exceptions:
  pinMode(A7,OUTPUT);
  pinMode(A8,OUTPUT);
  //interrupts:
  attachInterrupt(A2, isr2, LOW);
  //test leds:
  digitalWrite(A4,HIGH);
  digitalWrite(A5,HIGH);
  digitalWrite(A6,HIGH);
  digitalWrite(A7,HIGH);
  digitalWrite(A8,HIGH);
  delay(1000);
  digitalWrite(A4,LOW);
  digitalWrite(A5,LOW);
  digitalWrite(A6,LOW);
  digitalWrite(A7,LOW);
  digitalWrite(A8,LOW);
  //automaton:
  start:
  if(digitalRead(A0) == 0){
    if(digitalRead(A1)){
      digitalWrite(A4,HIGH);
      delay(minut);
      digitalWrite(A6,HIGH);
      digitalWrite(A5,HIGH);
      before_wait_3sec:
      delay(trei_secunde);
      if(digitalRead(A3) == 0){
        digitalWrite(A6,LOW);//stop scanteie
        if(digitalRead(A1)){
          goto before_wait_3sec;
        } else {
          digitalWrite(A5,LOW);
          digitalWrite(A4,LOW);
          goto before_wait_1min;
        }
      } else{
        //exceptie2
        digitalWrite(A4,LOW);
        digitalWrite(A5,LOW);
        digitalWrite(A6,LOW);
        digitalWrite(A8,HIGH);
        delay(exceptie);
        digitalWrite(A8,LOW);
        goto start;
      }
    } else {
      before_wait_1min:
      delay(minut);
      goto start;
    }
  } else {
    delay(zece_secunde);
    goto start;
  }
}

void loop() {

}

void isr2(){
  digitalWrite(A5,LOW);
  digitalWrite(A4,LOW);
  digitalWrite(A6,LOW);
  digitalWrite(A7,HIGH);
}

Which Arduino board are you using ?

I don't know any Arduino type that would execute that line correctly.

I see also no change to HIGH on A2, so the ISR would be called back to back,
probably single stepping the main code.

Arduino DUE

Arduino DUE does, I tried it. It does not function properly only within this excerpt of code, idk why, I suppose it may be something related to the goto label instructions.

Whether or not the gotos are causing a problem I strongly suggest that you get rid of them. They are not needed with properly structured code

You are not using attachInterrupt correctly. Check the documentation

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.