In order to use the I2C bus properly and efficiently, it is important to understand what happens in the hardware on the electric level. Protocol knowledge alone is not enough: many I2C problems – a bus that hangs, missing acknowledges, distorted signals – can only be traced back to their cause once the electrical behaviour of the lines SDA and SCL is understood. This essay explains:
- the hardware setup of an I2C bus,
- the requirements for proper operation of the I2C bus,
- how to find the cause of problems and how to solve them.
It is assumed that the reader understands the protocol basics of I2C and is thus familiar with terms like I2C master and slave, (repeated) start and stop conditions, and acknowledges. Whenever a term is used for the first time in the following chapters, it is linked to the page where it is explained in detail.
The current I2C specification has the revision 7.0 and is dated October 2021; you can find it right here: https://www.nxp.com/docs/en/user-guide/UM10204.pdf.
The pictures shown in the following sections have been made with Tracii XL 2.0, an I2C interface with analysis functions. The measurements can be reproduced with comparable equipment.
Chapters of this I2C primer
The primer consists of the following chapters. It is recommended to read them in order, since each chapter builds on the previous ones:
- I2C bus requirements – which conditions must be met for the bus to work at all.
- The typical I2C bus setup – the equivalent circuit diagram with Rp, Rs, Cp and Cc.
- How I2C hardware works – open-drain lines, pull-up and the sawtooth shape of I2C signals.
- Termination versus capacitance – how Rp and Cp limit the data rate.
- Termination versus serial resistance – how Rs shifts the low level of the signals.
- Serial resistance and debugging – recognizing who is driving the bus by looking at the low level.
- Clock generation, clock stretching and arbitration – the clock on an I2C bus and what happens when several masters want to talk.
- Crosstalk between SDA and SCL – what happens when the two lines start influencing each other.
If you are hunting a specific symptom, the sections on common problems and obscure problems are a good starting point; the chapter on a blocked bus describes one of the most frequent failure modes in practice.