How to reset I2C on STM32F4407 without resetting the MCU
Hello
I have trouble with handling an I2C error on my STM32F407. My I2C bus usually works fine but it sometimes hangs, with both clock and data lines are high, but the I2C communication does not start. The SR2.BUSY bit remains high and sometimes when this bit is indeed low, the SR1.SB bit remains low after the code sets the CR1.START to initiate a transfer.
I've noticed that resetting the entire MCU fixes the problem, I2C communication restarts and everything is fine.
However, resetting the entire MCU is not an option. Instead I'd rather like to reset just the I2C peripheral.
I've tried doing this in a number of ways:
- By setting and clearing APB1RSTR.I2C2RST
- By setting CR1.STOP to generate a stop in the communication
- By setting CR1.SWRST to generate a software reset of the I2C peripheral
- By clearing CR1.PE
The above is followed by calling the same setup routines as used initially to set up I2C communication.
Once the error happens, none of this seems to fix the error.
- What other ways are there to reset the I2C peripheral?
- What could cause the SR2.BUSY bit to remain high?
- What could cause the SR1.SB bit to remain low after setting the CR1.START bit?
I have spent a lot of time with this issue and would greatly appreciate any help I could get.
Best regards
Nils