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.

asked Sep 16, 2016 at 13:51
9
  • Just a thought, check arduino.stackexchange.com/questions/23006/… Commented Sep 16, 2016 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? Commented Sep 16, 2016 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. Commented Sep 16, 2016 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 Commented Sep 19, 2016 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. Commented Sep 19, 2016 at 10:38

1 Answer 1

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)

answered Sep 22, 2016 at 10:06

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.