From f7037c4462c0f94f5b554ae04dcbcd33787c6afa Mon Sep 17 00:00:00 2001 From: wx85105157 <19891111wangxiang@163.com> Date: Mon, 8 Jan 2024 00:17:08 +0800 Subject: [PATCH] =?UTF-8?q?SDA,SCL=E4=BB=BB=E4=B8=80=E5=BC=95=E8=84=9A?= =?UTF-8?q?=E4=BD=8E=E7=94=B5=E5=B9=B3Busy=E4=BC=9A=E7=BD=AE=E4=BD=8D?= =?UTF-8?q?=EF=BC=8C=E4=BE=8B=E7=A8=8B=E9=87=8C=E9=9D=A2=E6=80=BB=E7=BA=BF?= =?UTF-8?q?=E5=A6=82=E6=9E=9C=E4=B8=80=E7=9B=B4Busy=E5=B0=B1=E6=98=AF?= =?UTF-8?q?=E9=94=81=E6=AD=BB=EF=BC=8C=E8=B6=85=E6=97=B6100ms=E5=A4=8D?= =?UTF-8?q?=E4=BD=8DIIC=E3=80=82=20=E8=A7=A3=E5=86=B3=E5=9B=A0=E5=B9=B2?= =?UTF-8?q?=E6=89=B0=EF=BC=8C=E8=BF=9E=E7=BA=BF=E8=99=9A=E6=8E=A5=EF=BC=8C?= =?UTF-8?q?=E4=B8=A4=E8=BE=B9=E8=AE=BE=E5=A4=87=E5=A4=8D=E4=BD=8D=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E6=AD=A5=E5=AF=BC=E8=87=B4IIC=E9=80=9A=E8=AE=AF?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- libraries/Wire/examples/slave_sender/slave_sender.ino | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libraries/Wire/examples/slave_sender/slave_sender.ino b/libraries/Wire/examples/slave_sender/slave_sender.ino index d3b238a..634943b 100644 --- a/libraries/Wire/examples/slave_sender/slave_sender.ino +++ b/libraries/Wire/examples/slave_sender/slave_sender.ino @@ -11,7 +11,7 @@ #include - +unsigned long IICfreetime = 0; void setup() { Wire.begin(2); // join i2c bus with address #2 @@ -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