Skip to main content
RKlin.1
Associate
Jan 11, 2022 4:22 PM UTC
Question

Is there a way to get the F4 I2C peripheral to toggle the SCL line while it is in the busy state i.e SDA is externally held low by a slave device.

..

This topic has been closed for replies.

9 replies

waclawek.jan
Super User
Jan 11, 2022 4:25 PM UTC

Switch given pin to Output in GPIO_MODER, and toggle as usually using GPIO_BSRR.

JW

RKlin.1
RKlin.1Author
Associate
Jan 11, 2022 4:31 PM UTC

The I2C peripheral?

waclawek.jan
Super User
Jan 11, 2022 4:46 PM UTC

The I2C peripheral is at that point presumably in some invalid state, so you can reset it (using its respective RCC_APBxRSTR bit).

JW

RKlin.1
RKlin.1Author
Associate
Jan 11, 2022 4:53 PM UTC

The I2C peripheral is not in an invalid state, "Is there a way to get the F4 I2C peripheral to toggle the SCL" was the question.

TDK
Jan 11, 2022 4:59 PM UTC

> "Is there a way to get the F4 I2C peripheral to toggle the SCL" was the question.

The answer is no.

Since SCL is driven in OD mode, if it's being held low externally, of course the I2C peripheral cannot override it.

Driving it high as JW suggests will lead to the MCU and the slave I2C device fighting over the same line. At best, undefined behavior.

Edit: I misread the question as the slave holding SCL low (clock stretching), not SDA.

"If you feel a post has answered your question, please click ""Accept as Solution""."
waclawek.jan
Super User
Jan 11, 2022 5:11 PM UTC

> Since SCL is driven in OD mode, if it's being held low externally, of course the I2C peripheral cannot override it.

That would be unresolvable in any other way than removing power or otherwise explicitly resetting the slave. The original question said, "SDA is externally held low by a slave device". The SCL toggling to resolve this problem is part of the I2C standard, btw.

Well maybe I2C peripheral is *not* in unknown state at that point, but the attached device is, and the pulsing brings it to idle. At that point, the I2C peripheral (master) is in the same position as after reset - it has to start the transaction on the bus - so resetting it explicitly won't make any harm. But you don't need to reset it if you know what state is it in.

The problem with the I2C module in 'F4 is, however, that due to noise on the bus it sometimes *does* fall into (undocumented) states which are not indicated to the user. SDA being held low by a slave may be result of the I2C module falling into such state, that's why I routinely reset it.

JW

RKlin.1
RKlin.1Author
Associate
Jan 11, 2022 5:17 PM UTC

"Is there a way to get the F4 I2C peripheral to toggle the SCL line", and "SDA is externally held low by a slave device" - SCL is not held low obviously. I could try a different language?

waclawek.jan
Super User
Jan 11, 2022 5:23 PM UTC

The culprit is here slave being out of sync for whatever reason.

What's the difference between "peripheral toggling SCL line" and "switching pin to GPIO and toggling it manually" from the point of view of the slave?

JW

RKlin.1
RKlin.1Author
Associate
Jan 11, 2022 5:48 PM UTC

Nothing, I just don't want to reconfigure my GPIOs and was wandering if it is possible to get the I2C peripheral to generate clocks - it looks like this is not possible like I suspected. Thanks