cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Slave freezes SCL line

Maximilian Pohl
Associate II

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

8 REPLIES 8

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

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Maximilian Pohl
Associate II

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.

AScha.3
Chief III

i had similar problems (other cpu etc.) by stray cap. /spike on the I2C line ;

so try

  • good GND connection ( as Tesla. already said)
  • lower pullup resistors
  • add 100pF on I2C lines to GND
  • set I2C filtering (if chip has options for this)
  • set port speed to low (if chip has options for this)

If you feel a post has answered your question, please click "Accept as Solution".
Piranha
Chief II

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.

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.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
S.Ma
Principal

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.

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

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.