Closed
Description
I noticed that sometimes if you reset the board during an I2C transaction the I2C bus remains stuck.
A possible solution that I found is to send a bit-banged STOP sequence before the I2C begin. Maybe it would be better to include this procedure in the Wire begin implementation or in a dedicated Wire API to improve the stability of the library.
You can find below the bit-banged STOP sequence that normally I send to unlock the I2C bus before the I2C begin:
pinMode(SCL_PIN, OUTPUT);
pinMode(SDA_PIN, OUTPUT);
for (int i = 0; i<10; i++) {
digitalWrite(SDA_PIN, LOW);
delay(3);
digitalWrite(SCL_PIN, HIGH);
delay(3);
digitalWrite(SDA_PIN, HIGH);
delay(3);
digitalWrite(SCL_PIN, LOW);
delay(3);
}
pinMode(SDA_PIN, INPUT);
pinMode(SCL_PIN, INPUT);
Best Regards,
Carlo