Interrupt hanging Arduino

Need some help. Trying to run this code (Arduino 0015, Duemillanove with 168)

Whenever I generate the interrupt (using a rotary encoder), the Arduino stops (the code inside the loop stops). Can’t figure out why.

Update: if I use serial.print, the interrupt routine works, but wire protocols (to an LCD) hangs the Arduino

#include <Wire.h>

void setup()
{
Wire.begin(); // Joining the I2C bus as master
pinMode(2, INPUT); //interrupt 0, pin 2
digitalWrite(2, HIGH);
attachInterrupt(0, Decoder, CHANGE); //encoder trips interrupt on change at pin 2

}

void loop()
{
Wire.beginTransmission(0x4C);
Wire.send(0x08);
Wire.endTransmission();
delay(1000);
}

void Decoder()
{
Wire.beginTransmission(0x4C);
Wire.send(0x05);
Wire.endTransmission();
}

You can't use the I2C routines inside an interrupt service routine(ISR). This is because they use a timer that requires the interrupts to be running and inside an ISR interrupts are disabled.

Bummer. That's a pretty big drawback for my application. Is this a limitation of the Atmel chips or software libraries? Any hope for this to be fixed?.... Thanks

You shouldn't be doing heavy lifting inside an ISR anyway.

Use the ISR to set a flag, watch the flag in your main program (i.e. loop()) and act when it changes.

instead of

myISR()
{
  do_some_serious_work();
}

do this

byte get_to_work = 0;

myISR()
{
  get_to_work = 1;
}

loop()
{
  if (get_to_work)
  {
    get_to_work = 0;
    do_some_serious_work();
  }
}

-j

kg4wsv,

Yeah, that makes a lot of sense. Thanks!.