Topics / Communication Protocols / Q14
What is clock stretching?
Short answer: Clock stretching is when a target device holds SCL low after the controller releases it, to tell the controller to wait until it is ready (for example while it finishes a measurement or prepares data). Because SCL is open-drain, the controller sees that SCL has not gone high and must wait before continuing. Every I2C controller must support it, but some implementations handle it badly.
When targets stretch
- After receiving a byte, while processing it (slow MCUs acting as I2C targets).
- Before sending read data that is not ready yet (some sensors during conversion, e.g. certain humidity sensors in "hold master" mode).
- On a bit level, for slow devices (rare).
Problems seen in practice
- Some controllers (notably older Raspberry Pi BCM2835 I2C hardware) do not handle stretching correctly in some phases, which corrupts transfers with stretching devices; workarounds are a software (bit-banged) I2C driver or devices configured not to stretch.
- A target that stretches forever (crashed firmware) hangs the bus; controllers should have a timeout (SMBus defines 25–35 ms) and use bus recovery.
- When designing an MCU as an I2C target, prefer hardware that stretches automatically while firmware handles each byte, but keep the stretch short.
Related: clock synchronisation between multiple controllers uses the same wired-AND property: the SCL low period is determined by the device holding it low the longest.