Skip to content

How to avoid I2C bus stuck after a board reset #1661

Closed
@cparata

Description

@cparata

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

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions