I'm using a 6DOF IMU: https://www.sparkfun.com/products/10121 and the FreeIMU implementation for this IMU (code at http://www.varesano.net/projects/hardware/FreeIMU).
In order to get raw data from the Gyroscope (ITG3200), the following sequence of calls are made:
void ITG3200::readmem(uint8_t _addr, uint8_t _nbytes, uint8_t __buff[]) {
Wire.beginTransmission(_dev_address); // start transmission to device
Wire.write(_addr); // sends register address to read from
Wire.endTransmission(); // end transmission
Wire.beginTransmission(_dev_address); // start transmission to device
//crashes on next line
Wire.requestFrom(_dev_address, _nbytes);// send data n-bytes read
uint8_t i = 0;
while (Wire.available()) {
__buff[i] = Wire.read(); // receive DATA
i++;
}
Wire.endTransmission(); // end transmission
}
It will run for a while (I'm calling this code in a loop every 100ms), but then it will freeze up on the call to requestFrom after a while and not return. I've tracked the problem down to inside the following function: uint8_t twi_readFrom(uint8_t address, uint8_t* data, uint8_t length, uint8_t sendStop) (which is in the twi.c file in /libraries/Wire/utility/twi.c).
Has anyone had this problem before with the ITG3200? I suspect I have a timing problem (not calling this code fast enough or too fast), but have not been able to fix it. Why does this just seem to hang sometimes? Any help is appreciated.
I have read before that beginTransmission does not need to be called before requestFrom, and I have tried running this code with the beginTransmission removed, but I have the same problem.
I can provide more details if necessary. Thanks.