What is I2C? How does it work? // Technology

I2C protocol

The I2C protocol uses a fairly simple put/get model, transferring data one byte at a time with the master always setting the clock rate. So, there’s a fair amount of protocol overhead.

Write operation

A typical 7 bit address write interaction will be:

The master pulling SDA low to indicate the start sequence.

Followed by an address frame, with the first 7 bits being the address.

and then a low on the 8th bit indicating a write.

The slave should then respond with an ACK by pulling the SDA line low on the next clock.

Then the master will send an 8 bit I2C register number,

with the slave responding with an ACK.

Followed by the data payload,

and a slave ACK.

Once complete the master will indicate a stop condition, where SDA is pulled low and then high just after a low to high transition of SCL. SCL and SDA are then kept high to free the bus.

Read operation

When reading from a slave the sequence initially starts out the same as a write:

The master pulling SDA low to indicate the start sequence.

Followed by an address frame, with the first 7 bits being the address.

and then a low on the 8th bit indicating a write.

The slave should then respond with an ACK by pulling the SDA line low on the next clock.

Then the master will send an 8 bit I2C register number,

with the slave responding with an ACK.

But this is where it deviates.

At this point the master will send another start sequence,
followed by an address frame, with the first 7 bits being the address

but the 8th bit high indicating a write.
Another slave ACK,
followed by the slave sending 8 bits of data back to the master.
With the master sending an ACK back to the slave on the next clock.
Once complete the master will indicate another stop condition freeing the bus.