Hello,
I am having an issue with Wire and interrupts. When I attach an interrupt under LOW mode, and use the Wire library, the program ends up crashing when Wire tries to finish transmitting. The program itself is quite long, but I was able to create a minimal sketch that I think effectively illustrates the issue:
#include <Wire.h>
void do_nothing(){}
void setup()
{
// Comment out (will work) or Uncomment (will not work).
// Crashes under any interrupt number [0 - 7] inclusive only
// using LOW mode. Works for all other modes.
attachInterrupt(0, do_nothing, LOW);
Wire.begin(); // start I2C as master
// Send something random to some random slave
Wire.beginTransmission(0xAA);
Wire.write((byte) 0xBB);
// Program will crash or deadlock HERE
Wire.endTransmission();
// If program is *working* LED should light up
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
}
void loop(){}
Altering or removing the attachInterrupt line will let the program run to the end of setup() and turn the LED on. Otherwise, it will hang at Wire.endTransmission() and the LED will never go on (indicating failure).
Wire seems to work with the other modes, but not LOW mode. I could not see anything about this issue in
attachInterrupt(), but perhaps there is info about it somewhere else that I missed. My project is using a library that requires the use of a LOW mode interrupt, so I am unable to alter it. I am using a Seeeduino w/ ATMega1280. Any help or input would be greatly appreciated (even if just testing that it also fails for you).
Thanks.