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.
i < 1000000is always true due to the limited range ofinttype. And you get undefined behavior whenioverflows. – Edgar Bonet Sep 16 '16 at 15:55aMillion()for AVR and got “warning: comparison is always true due to limited range of data type”. And gcc optimized out the testi < 1000000. The generated assembly is just an infinite loop. – Edgar Bonet Sep 19 '16 at 10:38