I2C
N.B As of 2021, master/slave architecture has been refactored to controller/peripheral or similar.
Introduction
I2C (Sometimes I2C, pronounced either “Eye-Two-See” or “Eye-Squared-See”) is a synchronous digital communication protocol designed for short distance communication between embedded devices. The name encapsulates its primary use – ‘Inter-Intergrated (I2) Circuit (C)’. I2C was initally designed by Phillips Semiconductor (now NXP) in 1982, and has sence undergone approximately 7 revisions. The most
I2C in Relation to Other Protocols
While often multiple communication protocols are satisfactory for an application, it is important to understand the benefits and drawbacks of I2C when compared to other communication systems.
Drawbacks of UART / Serial While the most ‘simple’ of communication protocls, UART has the majority of drawbacks. It is effectively single controller / single target, there is extensive harware overhead, and both nodes must be in agreement on procotol details such as partiy bit and stop bit. Additionally, the max baud rate commonly supported is 230400 bits / sec
, or approximately 230 kbit / sec
. This speed is cut into as well due to the excess framing bits required (stop, start, and partiy).
Drawbacks of SPI Not as bad as UART, SPI still has drawbacks that would cause an engineer to shy away. Like UART, it also has some hardware limitations – Any additional device will require an additional CS
pin, and even just communicating between two devices will requrie 4 pins. However, SPI does support the largest data transmit rate, at 10Mhz = 10 megabits / sec
.
I2C Communication at a High Level
There are two wires in I2C: SDA
and SCL
, corresponding to ‘serial data’ and ‘serial clock’ respectively. All devices on the bus simply share these two pins to communicate on the bus. Every device on the I2C bus is either a controller (or client) or a target / peripheral. The controller is the only device which can initate a conversation, but both controllers and peripherals can particiapte.
Communication in I2C is done in a series of communication frames. The I2C standard defines two types of frames:
Address frames, specifing which device is being communicated to. For each conversation there is only one address frame sent by the controller.
Data frames, unsurprisingly, communicate data. There can be any number of data frames in a conversation.
Note: In isolation, it is impossible to tell who the data is for, or who is sending the data. Data frames must be analyzised in the context of a full I2C conversation.
I2C Communication at a Low Level
Electrically
The I2C bus is by default held high, with pull-up resistors on SCL
and SDA
. All devices on the bus are open drain, meaning they can only pull the line to 0V
, but CANNOT drive it high. These two principles are the foundation for all communication ideosyncracies in I2C – Without them the protocol breaks down.
Signal
How does it work? Explain its operation.
What is the pin type/config of I2C? Because of this? What do I2C signals require?
What is bus capacitance? How does that affect design considerations with I2C? (considerations should be PCB design specific)
What happens when the resistances of I2C pullup resistors are increased or decreased? What are the two conflicting tradeoffs?
How can leakage current impact I2C signals?
How are slaves interfaced?
How many slaves can there be? Why?
When would you need more masters?
Explain address/data frames.
How can you change a slave's address?
Explain NACK/ACK.
Explain clock stretching