0

I am using the following simple code to test the interrupt functionality of due:

void aMillion(){
    for(int i = 0; i < 1000000; i++){
        if(i % 1000 == 0){
            Serial.print("m");
        }
    }
}

void setup(){
  Serial.begin(9600); 
  pinMode(2, INPUT);
  attachInterrupt(digitalPinToInterrupt(2), aMillion, CHANGE);
}
void loop()
{
}

obviously what we expect to see is a thousand "m" characters after each interrupt event. On Arduino Mega, this worked fine. But I have tested it on multiple Due boards.

Very odd news is that on the reset event of due, I do get a single "m" character printed.

  • Just a thought, check arduino.stackexchange.com/questions/23006/… – Jesse Sep 16 '16 at 15:34
  • 1
    Doing a lot of stuff inside the ISR isn't advised. Especially if you are doing serial communication. What happens if you do just a single serial.print? – Gerben Sep 16 '16 at 15:52
  • 2
    I am surprised this could ever work on the Mega. The test i < 1000000 is always true due to the limited range of int type. And you get undefined behavior when i overflows. – Edgar Bonet Sep 16 '16 at 15:55
  • @EdgarBonet haha yea, but an automatic cast during the comparison would make the loop run forever. wouldn't it? That's what I saw with MEGA – Makan Tayebi Sep 19 '16 at 9:46
  • I don't understand your comment. Could you be more explicit? I just compiled aMillion() for AVR and got “warning: comparison is always true due to limited range of data type”. And gcc optimized out the test i < 1000000. The generated assembly is just an infinite loop. – Edgar Bonet Sep 19 '16 at 10:38
0

An attempt to run long loops in the ISR for the DUE fails. This is the result of some sort of a run time monitoring system. An infinite loop like this one here, or even a loop with a thousand repetitions of a Serial Print will result in an early halt of ISR on the DUE.

On the MEGA however, This is not the case. ISRs can run much longer. (At least ten minutes as I tried)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.