cancel
Showing results for 
Search instead for 
Did you mean: 

I2C Timeout

Pje
Associate II

Hi All,

I am new to programming in general and I want to ask what is the best practices to timeout on I2C bus communication  Appreciate any ideas and methods ,As I am starting a project with I2C communication for a production device and need to ensure that the communication is stable and not getting blocked by any means.

 

Regards 

1 ACCEPTED SOLUTION

Accepted Solutions
Danish1
Lead II

The first question is whether your stm32 will be the only master in your system. I2C is capable of being used in “multi-master“ systems although it is rare, and places extra responsibility on all masters including the stm32.

The most common “lockup” I experience with I2C is when I reset the stm32, either during debugging or due to a crash in my code. If that happens part-way through a byte then a peripheral might still want to send the remainder of the byte and so drive SDA low. The easiest way to fix this is, before using I2C for the first time coming out of reset, to “clock out” the byte by manually bit-banging 9 low pulses on SCL before issuing a “Stop Condition”. This will cleanly tell all peripherals to stop ongoing communication and be ready.

Of course you mustn’t do that if a different master is using the I2C bus.

Sadly this “clocking out” has to be done manually before enabling the I2C peripheral with HAL or your own code

View solution in original post

2 REPLIES 2
Danish1
Lead II

The first question is whether your stm32 will be the only master in your system. I2C is capable of being used in “multi-master“ systems although it is rare, and places extra responsibility on all masters including the stm32.

The most common “lockup” I experience with I2C is when I reset the stm32, either during debugging or due to a crash in my code. If that happens part-way through a byte then a peripheral might still want to send the remainder of the byte and so drive SDA low. The easiest way to fix this is, before using I2C for the first time coming out of reset, to “clock out” the byte by manually bit-banging 9 low pulses on SCL before issuing a “Stop Condition”. This will cleanly tell all peripherals to stop ongoing communication and be ready.

Of course you mustn’t do that if a different master is using the I2C bus.

Sadly this “clocking out” has to be done manually before enabling the I2C peripheral with HAL or your own code

Pje
Associate II

Thank you for your reply the STM32 is the only master on the Bus,

I will get going with it and I am sure I will be back to ask some more questions

 

Regards