The initial release for V1.9 had an I2C bug that caused board lockups on some installations. There were several reports of "dead" boards and I was affected too. Although the latest V1.9 releases have fixed the lockup issue, it turns out that the bug helped identify an I2C performance problem on my model that I did not know I had. Furthermore, it is very likely that any board that experienced the lockup issue on the early V1.9 code has an I2C problem. In other words, the lockup would never have occurred if the I2C transmissions were working perfectly.
While debugging the lockup problem I wrote some test code to see what was going on. The test code chirps the buzzer whenever a basic I2C transmission is not successful. I've since added an error counter to it so that the GUI's debug window can show the number of bad I2C hits.
To demonstrate how the test code helped me: After applying the latest V1.9 code fix my model was working fine (and no hints of any I2C issues!). But after applying the test code the buzzer was very noisy (a lot of beeping) which showed there were I2C problems. Temporarily reducing the I2C clock to 100KHz did not help at this point. My o-scope found an inadequate I2C clock signal (SCL); It had poor rise-time and low amplitude. I reduced the SCL pullup resistor value and then ran the test again. The buzzer chirp test was now very quiet, so I thought all the problems were solved. But I allowed the test to run for more than an hour. Every few minutes I would hear a single short chirp. At the end of the hour long test the GUI debug window showed a half-dozen error hits. Reducing the I2C speed to 100KHz eliminated the final remaining sporadic errors and all I2C issues were solved.
To use the debug code all you have to do is edit the sensors.pde file. This code should work in version 1.8 and higher. So open sensors.pde and completely comment out the waitTransmissionI2C() function. Replace it with this:
- Code: Select all
// START OF RC-CAM DEBUG CODE.
// I2C Test Code: Used to help identify I2C xfr problems.
// If TWINT flag is not detected the buzzer will chirp and the
// global error counter will increment (max 1000 hits).
// Hint: The GUI's debug window can be used to show the error count.
#define I2C_WAIT_TIME 2000 // Timeout count is long enough to hear the buzzer chirp.
static int16_t i2c_wait_error = -1; // I2C error counter. Init to -1 for GUI confirmation.
void waitTransmissionI2C() {
uint16_t count = I2C_WAIT_TIME;
while (!(TWCR & (1<<TWINT))) {
count--;
if (count==(I2C_WAIT_TIME-200)){ // TWINT flag not detected, I2C problem!
BUZZERPIN_ON; // Chirp the user.
if(i2c_wait_error == -1) {
i2c_wait_error = 1;
}
else {
if(i2c_wait_error<1000) i2c_wait_error++; // Limit error count to 1000 max.
}
}
else if (count==0) { // We are in a blocking state => we don't insist
TWCR = 0; // Force a reset on TWINT register
neutralizeTime = micros(); // We take a timestamp here to neutralize the value during a short delay after the hard reset
BUZZERPIN_OFF; // Chirp is done.
break; // Abort, this xfr is bad and needs to be killed.
}
}
}
// END OF DEBUG CODE
Then open the serial.pde and find this code sequence (may be different if you have edited this file before):
- Code: Select all
serialize16(BaroAlt/10); // 4 variables are here for general monitoring purpose
serialize16(0); // debug2
Replace it with:
- Code: Select all
serialize16(BaroAlt/10); // 4 variables are here for general monitoring purpose
serialize16(i2c_wait_error); // debug2
Now upload the edits to your wiiCopter and verify that the GUI's debug2 window shows -1. If it shows 0 then your serial.pde edits are wrong. If greater than 0 then you have I2C problems. Pressing the Arduino reset button will clear the count back to -1 if you want to start the test again.
Allow the model to run for an hour. Motors off is best, so you can hear the buzzer (but try it with motors on too to test for intermittent solder connection problems). Basically, if you hear any chirps or beeps then you've got problems. As an alternative, the GUI's debug2 window will show the running error count (max 1000 errors will be counted).
- Thomas