Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDA,SCL任一引脚低电平Busy会置位,例程里面总线如果一直Busy就是锁死,超时100ms复位IIC。 #101

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions libraries/Wire/examples/slave_sender/slave_sender.ino
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


#include <Wire.h>

unsigned long IICfreetime = 0;
void setup()
{
Wire.begin(2); // join i2c bus with address #2
Expand All @@ -20,7 +20,14 @@ void setup()

void loop()
{
delay(100);
if (__HAL_I2C_GET_FLAG(Wire.getHandle(), I2C_FLAG_BUSY) == RESET) {
IICfreetime = millis(); //总线不忙
} else if ((millis() - IICfreetime) > 100) { //总线忙超过100ms复位
Wire.end();
Wire.begin(2);
Wire.onRequest(requestEvent);
}
delay(1);
}

// function that executes whenever data is requested by master
Expand Down