Serial1.begin(9600) kills INT0 processing (FioV3 / Leonardo)

The code adds the following interrupt handler to INT0 using
attachInterrupt(0, irTempInterrupt, FALLING);

volatile static byte irTempData[pfodIRTemp::IRTEMP_DATA_SIZE];
volatile static byte irTempDataBit;
volatile static byte irTempDataIndex;
volatile static bool irTempSensorEnabled;

static void irTempInterrupt(void) {
if (irTempSensorEnabled) {
if (irTempDataIndex < pfodIRTemp::IRTEMP_DATA_SIZE) {
irTempDataBit --;
irTempData[irTempDataIndex] |= digitalRead(pfodIRTemp::PIN_DATA) << irTempDataBit;
if (irTempDataBit == 0) {
irTempDataBit = 8;
irTempDataIndex ++;
}
}
}
}

Everything works fine until I add the following line in setup()
Serial1.begin(9600);

Serial1 is not used or accessed after this, but now the interrupt routine either does not get IRTEMP_DATA_SIZE values or gets corrupt values. I am sending the values received to Serial (USB/SerialMontor). Nothing else changes in the codes apart from the Serial1.begin(9600) line. After adding that line the values become garbage.

Any ideas. This code is actually running on a FioV3 but that uses the same chip/pin outs as the Leonardo

Variables shared between an ISR and the main code should be declared volatile.

http://gammon.com.au/interrupts

Oops, I see you did that. :)

Try removing "static" from the declarations.

but now the interrupt routine either does not get IRTEMP_DATA_SIZE values or gets corrupt values

Post the whole thing please, I can't see where IRTEMP_DATA_SIZE is declared.

How to use this forum

thank for the quick response,

const byte pfodIRTemp::IRTEMP_DATA_SIZE = 10;

tried removing the statics, same result. Everything works until I add the line in setup();
Serial1.begin(9600); //this line kills it

comment out that one line and re-compile/reload and everything runs as it should

here is the basic sketch. (corrected, compiling version posted in a later post)

Doesn’t compile:

   void setup() {
     initIRTemp(
     Serial.begin(9600);
     //Serial1.begin(9600); //this line kills it
     for (int i=5; i>0; i--) { // wait a little while on startup, makes re-programming more reliable on FioV3
       delay(1000); 
       Serial.print(i);
       Serial.print(F(" "));
     }
     Serial.println();  
   }
FioV3BasicProblem.ino: In function 'void setup()':
FioV3BasicProblem:47: error: expected `)' before ';' token
FioV3BasicProblem.ino: In function 'void initIRTemp(byte, byte, byte, byte)':
FioV3BasicProblem:76: error: assignment of read-only variable 'PIN_DATA'
FioV3BasicProblem:77: error: assignment of read-only variable 'PIN_ACQUIRE'
FioV3BasicProblem:88: error: 'dataType' was not declared in this scope
FioV3BasicProblem:88: error: 'IRTEMP_DATA_IR' was not declared in this scope

my apologies, I missed saving the final edit
here is the compiling sketch. Bare in mind that the sketch expects a IR temp sensor connected to the board to produce the values.

FioV3BasicProblem.ino (5.05 KB)

I can't see anything obvious, but I don't use the Leonardo as much as the Uno. It might be a subtle hardware thing.