This simple program doesn't work if the speed of the serial for debugging is lower than 115200. The card seems to hang, even the few works "doLI" are not written in the console.
I use a Seedunio Mega:
const byte LIpinI = 2;
pinMode (LIpinI, INPUT);
attachInterrupt(0, doLI, RISING);
Serial2.println("------------ START LI ------------");
Serial2.println("doLI"); // this line is nerver seen
Serial2.println(pulseIn(LIpinI, HIGH)); // it works very slowly !
I saw this remark which seems to explain the reason.http://forums.adafruit.com/viewtopic.php?f=25&t=32234
Under Arduino, yes, Serial inside an interrupt runs into problems on Arduino 1.0+. Due to the circular buffer used to implement the Serial streams, the method used to write to it, and the relative interrupt priorities, a serial write to a full buffer will wait until the buffer has space before releasing. Unfortunately, since the Serial interrupts take lower priority than the user pin interrupts, the buffer is never emptied, so the Serial write method hangs indefinitely. It's a really annoying problem, and one newly introduced in 1.0 (They made the choice to make not losing data a higher priority.)
Is there a way to avoid this behaviour?
I can't debug code, because it's hanging very quickly, even with few debugging information sent in the Serial2.