From 87fda7e878cd948bb21905afa1fce9296cb4b912 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 5 Aug 2022 15:15:59 +0200 Subject: [PATCH] =?UTF-8?q?implement=20I=C2=B2C=20bus=20clear?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/main.c b/main.c index 2d36126..a6e6eca 100644 --- a/main.c +++ b/main.c @@ -336,6 +336,16 @@ we will only be able to provide 1 extension block since we can only respond to o SCL_SNK_PU_PORT->ODR.reg |= SCL_SNK_PU_PIN; // pull up SCL line SCL_SNK_PU_PORT->CR1.reg |= SCL_SNK_PU_PIN; // switch pin to push pull SCL_SNK_PU_PORT->DDR.reg |= SCL_SNK_PU_PIN; // switch pin to output + if (0 == (SDA_SNK_PORT->IDR.reg & SDA_SNK_PIN)) { // SDA line is stuck + puts ("bus clear "); + // perform bus clear + for (uint8_t i = 0; i < 9; i++) { + SCL_SNK_PORT->ODR.reg &= ~SCL_SNK_PIN; + wait_10us(1); + SCL_SNK_PORT->ODR.reg |= SCL_SNK_PIN; + wait_10us(1); + } + } uint8_t i2c_rc = 1; // if the complete read succeeded if (!softi2c_master_setup(400)) { // start the I²C master to talk to sink i2c_rc = 2;