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;