2022-08-31 02:19 PM
Hello,
i tried to implement a I2C slave device on a STM32L486.
It is working, but sometimes (after a few seconds, minutes or even hours) it freezes/blocks the SCL line. So the master device (also a STM32) generates a error.
I have no glue what happens here. We tried to send stop condictions by the master, toggle scl and sda line, but nothing helped. after a rest of the Slave device everything works fine again.
I followed an cubemx example. My source code is attached.
Any idea how to solve this?
thank you so much
Max
2022-08-31 03:01 PM
Assume you'll need to debug the slave in this situation, and perhaps instrument to understand the interactions.
The Slave shouldn't have cause to drive SCL, is it trying to clock stretch? Why?
The Master should get to set and control the pacing.
Not got some latch-up, or grounding issues?
Separate boards? DuPont connectors?
Use something like wire-wrap, with a solid metal-to-metal bond.
Bond the Grounds
2022-09-01 01:05 AM
Hi,
i think the slave does some clock stretching. This could cause some influence on the SCL line.
if it is a wiring issue why is it working for hours without touching it and then it hangs up.
I tried also wire-wrap (15cm) but still the same issue.
2022-09-04 12:52 AM
i had similar problems (other cpu etc.) by stray cap. /spike on the I2C line ;
so try
2022-09-04 08:52 AM
The HAL is a broken bloatware full of race conditions and other bugs. In addition the I2C peripheral also has a significant number of flaws documented in errata. To get a reliable software, read the reference manual, implement your own code and keep an eye on errata.
2022-09-04 10:05 AM
Not saying it is or isn't, just not in much of a position to judge from here.
Guess at some level you'll need to disconnect the SCL and determine who's driving it low.
2022-09-04 06:24 PM
Slave mcu embedded function means max sw latency should be known and compared with the worst case occurring in the user code. If the master support clock stretch fully, what timeout? If not, there are some. The overrun interrupts occur when hang by other interrupt processing, it shows like non repetitive, hard to duplicate, random malfunction. In case of I2C, master should check SDA and SCL are both high before initiating a Start bit. If not, breakpoint and debug. One error recovery is to manually gpio bit bang 18 stop bits. With an MCU as slave, it might not be enough. If you increase the bus speed. The problem occurs more frequently, slowing down the bit rate may reach a non glitch level.
2022-09-05 12:26 AM
It is sometimes the master and sometimes the slave itselv. After a reset of the "damaged" device the i2c works again for a certain time
2022-09-05 12:27 AM
Thank you for your answer. I will try the 100pF.
I think the GND connection is good.
Do i need to enable the filtering on the slave or master? or both?
The same for the port speed.