I2C
- I
nter-I
ntegrated C
ircuit is a common bus used for intra-board communication.
I2C
is a bus
, half-duplex
, synchronous
, and master/slave
.
It works only over two signal wires:
SCL
- wire with clock
SDA
- wire with data
One transfer of data works in transactions
in which messages
made of bytes
are sent over the SDA
line.
This is clocked by the SCL
line.
Each device has its address
which has to be unique on the bus
.
Each message
contains the address
of the target device.
We can have multiple masters
. (Which is rare)
I2C
supports two addressing modes - 7bit
and 10bit
.
The addresses have to be unique.
In the case of MCU
s, it is usually trivial to set up any address.
In the case of IC
s, the manufacturers tend to give a basic address and some method for changing the last few bits of the address.
For example: the first 5
bits are fixed, and the last 2
can be varied by connecting two specific pins of IC
to HIGH
or LOW
.
Let’s assume that we have only one master
.
Any communication is initiated by the master
, which sends at least one message
in the transaction
.
The first byte of the message contains the address
of the slave device and the direction
of communication (r
ead/w
rite).
Following that, based on the direction of communication:
Master
sends data over SDA
wire, which is read by the slave
that detected its address.Slave
which detected its address responds with data on the SDA
wire.Apart from the plain sending of data, bytes
are confirmed by ACK
bit from the other side of the communication.
The logical content of the message looks as follows:
What data
represents is content specific.
In the case of I2C
, the common pattern is to have an abstraction of registers
.
The slave
device has a set of registers
(usually with a size of 1 byte
and at properly defined addresses).
Any interaction with the device works in terms of:
x
bytes from a register at address addr
.x
bytes to a register at address addr
.This abstraction gives some shared form to the communication process, which translates into the following transactions:
Notice that the read
of a register is made of two messages.
There are various devices or IC
s, that use I2C
for communication.
Out of all of those, two use cases stand out as curiosity: VGA
and HDMI
.
Both interfaces use I2C
to allow control of devices over the cable or to transfer meta-information.