2018-08-20 01:48 AM
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:
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.
I have spent a lot of time with this issue and would greatly appreciate any help I could get.
Best regards
Nils
2018-08-22 02:52 AM
BTW, with SPL I meant the Standard Peripheral Library, a more robust but now abandoned predecessor of Cube.
It's still availabe for the early F4xx variants, and comes with plenty of examples - and driver code for the peripherals.
In this "Worst Forum Ever", it is really hard to keep track of threads one got involved.
2019-05-03 07:12 AM
I have recently had the same issue, and I thought it would be worth noting what I found, in case someone else is struggling with this.
The solution given by Nils B -
> So, in all, what I did was set the software reset bit (CR1.SWRST) and then call the init function once more, thus resetting the peripheral to the same state it is after startup.
I found that the Deinit function must be run after the SWRST. Without it, CR2 was never set, and thus the clk never generated, tieing SCL low constantly. I have no idea why this is, as it passes the Init function without error.
2019-05-03 10:34 AM
Reference Manual, SYSCFG has reset bit for each peripheral. Set and clear the bit for the chosen I2C.
2019-07-28 01:10 AM
Hello all,
I have also same problem with I2C.
I use STM32F439BGT6.
After the I2C was stuck, I set the software reset bit (CR1.SWRST) but this bit remained 1.
The init function (HAL_I2C_Init) didn't clear this bit and the I2C didn't work at all.
I cleared the software reset bit (CR1.SWRST) via debugger and after it the device started to work.
A few questions:
1) Is the software reset bit (CR1.SWRST) cleared automatically or should I clear by software?
2) If I should clear by software, how long time should I wait between setting and clearing (microseconds or milliseconds)?
3) Should I reset and clear of the software reset bit (CR1.SWRST) in disable interrupts state?
Thanks.
Yacob Hassidim.
2019-07-28 10:09 AM
Hi Yacob,
I believe some of the I2C drivers will clear it automatically but you may have to do it yourself depending on your version. You can step through the driver to find out, but there's no harm in doing it yourself aswell.
I am not sure about the timing, but most drivers I've looked at don't seem to give any delay so probably don't need to worry about it, but this information should be given in your device's datasheet.
Hope this helps.
Damien
2019-07-28 10:49 AM
External I2C peripherals can also get into odd states. Worst case clock them out driving pins as GPIO
2019-07-31 11:03 PM
Hello Damien,
Thanks for your response.
Yacob Hassidim.
2019-07-31 11:04 PM
Hello Clive,
Thanks for your response.
Yacob Hassidim.
2020-06-14 09:21 PM
Thanks Nils B,
I had the same problem with Stm8.
I have solved this problem in your way.
I'm really thankful to you