I am trying to read data from a Wire (connected to a gyroscope) from inside a function called from an interrupt service routine. I am using the FlexiTimer2 library from
http://playground.arduino.cc/Main/FlexiTimer2.
The problem I am having is that whenever this function (my function I'm attaching to the interrupt) is called, the code locks up. I beleive this is due to my Wire.something() function calls, since removing them and just using some Serial.print()s allows it to work properly.
My code:
void timerTask() {
Serial.print("Gyro X: ");
int buff[10];
Wire.beginTransmission(ADDRESS_GYRO); //start transmission to ACC
Wire.write(0x1B); //sends address to read from
Wire.endTransmission(); //end transmission
Wire.beginTransmission(ADDRESS_GYRO); //start transmission to ACC
Wire.requestFrom(ADDRESS_GYRO, G_TO_READ); // request 6 bytes from ACC
int i = 0;
while(Wire.available()) //ACC may send less than requested (abnormal)
{
buff[i] = Wire.read(); // receive a byte
i++;
}
Wire.endTransmission(); //end transmission
Serial.print(buff[0]);
Serial.print("\r\n");
}
And I assign my fuction to the interrupt handler here:
FlexiTimer2::set(500, timerTask);
FlexiTimer2::start();
Is there a way for me to use Wire functions from within an interrupt, or is this not possible?
My ultimate goal is to query the gyro every so many milliseconds to get an accurate picture of how far I've rotated since I started.
Thanks for taking the time to read this...