I was happily writing an interrupt service routine to service an NXP UART that is communicated with via I2C and of course it didn't work. Here is why:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1251326763
Since I2C uses interrupts you can't use it in an ISR because interrupts are down. So I set a flag in the ISR and poll the flag in my main application, and service the UART when the flag is set. Code below.
My question is, what's the point of the ISR? If I have to set a flag and poll it, why not just poll the device directly?
Is there a better way? Maybe put interrupts back up in the ISR but declare it atomic?
Thanks...
#include <Wire.h>
#include <MultiSerial.h>
#define DATA_LED 20
// Create a MultiSerial instance to communicate with port 0 on shield 0x4D
MultiSerial msInstance = MultiSerial(0x4D, 1);
volatile bool isrTriggered = false;
// The ISR in all its glory
ISR(PCINT1_vect)
{
isrTriggered = true;
}
void setup()
{
// establish interrupt processing / ISR
PCICR |= (1<<PCIE1);
PCMSK1 |= (1<<PCINT10);
MCUCR = (1<<ISC10);
pinMode(2, INPUT);
Serial.begin(9600);
msInstance.begin(4800);
// Turn on the shield's receive interrupt
msInstance.enableInterrupt(INT_RX);
// Read some registers to confirm a few things
unsigned char tmp = msInstance.msReadRegister(IER);
Serial.print("IER: ");
Serial.println(tmp, HEX);
tmp = msInstance.msReadRegister(FCR);
Serial.print("FCR: ");
Serial.println(tmp, HEX);
tmp = msInstance.msReadRegister(IIR);
Serial.print("IIR: ");
Serial.println(tmp, HEX);
}
void loop()
{
if(isrTriggered)
{
isrTriggered = false;
Serial.print((char)msInstance.read());
}
}
