cancel
Showing results for 
Search instead for 
Did you mean: 

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.

RKlin.1
Associate II
 
9 REPLIES 9

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

JW

RKlin.1
Associate II

The I2C peripheral?

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
Associate II

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
Guru

> "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".

> 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
Associate II

"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?

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
Associate II

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