Basics of The I2C Communication Protocol
Basics of The I2C Communication Protocol
SEARCH …
PROTOCOL
Get new tutorials sent
Posted by Scott Campbell | DIY Electronics | 57
to your inbox!
EMAIL ADDRESS
SUBSCRIBE
So far, we’ve talked about the basics of SPI communication and UART
communication, so now let’s go into the final protocol of this series, the Inter-
Integrated Circuit, or I2C.
You’ll probably find yourself using I2C if you ever build projects that use OLED
displays, barometric pressure sensors, or gyroscope/accelerometer modules.
Like UART communication, I2C only uses two wires to transmit data between
devices:
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 1/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
Ads by
SYNC3000 Data Concentrator
Stop seeing this ad -
Why this ad?
IEC 61850, IEC 60870-5-104/101/103, DNP3, ICCP, Modbus, C37.118 PDC kalkitech.com
SDA (Serial Data) – The line for the master and slave to send and receive data.
SCL (Serial Clock) – The line that carries the clock signal.
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 2/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
Start Condition: The SDA line switches from a high voltage level to a low
voltage level before the SCL line switches from high to low.
Stop Condition: The SDA line switches from a low voltage level to a high
voltage level after the SCL line switches from low to high.
Address Frame: A 7 or 10 bit sequence unique to each slave that identifies the
slave when the master wants to talk to it.
Read/Write Bit: A single bit specifying whether the master is sending data to
the slave (low voltage level) or requesting data from it (high voltage level).
ADDRESSING
I2C doesn’t have slave select lines like SPI, so it needs another way to let the
slave know that data is being sent to it, and not another slave. It does this
by addressing. The address frame is always the first frame after the start bit in a
new message.
The master sends the address of the slave it wants to communicate with to
every slave connected to it. Each slave then compares the address sent from
the master to its own address. If the address matches, it sends a low voltage
ACK bit back to the master. If the address doesn’t match, the slave does
nothing and the SDA line remains high.
READ/WRITE BIT
The address frame includes a single bit at the end that informs the slave
whether the master wants to write data to it or receive data from it. If the
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 3/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
master wants to send data to the slave, the read/write bit is a low voltage level.
If the master is requesting data from the slave, the bit is a high voltage level.
The data frame is always 8 bits long, and sent with the most significant bit first.
Each data frame is immediately followed by an ACK/NACK bit to verify that the
frame has been received successfully. The ACK bit must be received by either
the master or the slave (depending on who is sending the data) before the
next data frame can be sent.
After all of the data frames have been sent, the master can send a stop
condition to the slave to halt the transmission. The stop condition is a voltage
transition from low to high on the SDA line after a low to high transition on the
SCL line, with the SCL line remaining high.
2. The master sends each slave the 7 or 10 bit address of the slave it wants to
communicate with, along with the read/write bit:
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 4/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
3. Each slave compares the address sent from the master to its own address. If
the address matches, the slave returns an ACK bit by pulling the SDA line low
for one bit. If the address from the master does not match the slave’s own
address, the slave leaves the SDA line high.
5. After each data frame has been transferred, the receiving device returns
another ACK bit to the sender to acknowledge successful receipt of the frame:
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 5/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
6. To stop the data transmission, the master sends a stop condition to the slave
by switching SCL high before switching SDA high:
master. With a 7 bit address, 128 (27) unique address are available. Using 10 bit
addresses is uncommon, but provides 1,024 (210) unique addresses. To connect
multiple slaves to a single master, wire them like this, with 4.7K Ohm pull-up
resistors connecting the SDA and SCL lines to Vcc:
MULTIPLE MASTERS WITH MULTIPLE SLAVES
Multiple masters can be connected to a single slave or multiple slaves. The
problem with multiple masters in the same system comes when two masters
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 6/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
try to send or receive data at the same time over the SDA line. To solve this
problem, each master needs to detect if the SDA line is low or high before
transmitting a message. If the SDA line is low, this means that another master
has control of the bus, and the master should wait to send the message. If the
SDA line is high, then it’s safe to transmit the message. To connect multiple
masters to multiple slaves, use the following diagram, with 4.7K Ohm pull-up
resistors connecting the SDA and SCL lines to Vcc:
ADVANTAGES
DISADVANTAGES
Thanks for reading! Hope you learned something from this series of articles on
electronic communication protocols. In case you haven’t read them already,
part one covers the SPI communication protocol, and part two covers UART
driven communication.
If you have any questions or have anything to add, feel free to leave a comment
below. And be sure to subscribe to get more articles like this in your inbox!
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 7/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
SHARE:
RELATED POSTS
57 COMMENTS
REPLY
REPLY
REPLY
REPLY
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 8/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
REPLY
GOOD JOB!
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
ArchonOSX on December 18, 2016 at 2:45 pm
Step 6 is similarly confusing as you say “6. To stop the data
transmission, the master sends a stop condition to the slave
by switching SCL high before switching SDA high:” The
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 9/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
diagram shows both lines high already with SDA going low
before SCL. I follow your written explanation but I don’t
think your diagrams do.
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 10/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
REPLY
REPLY
REPLY
REPLY
REPLY
You could add a chapter about I2C multiplexing and how to handle
it for example with a TCA9548A .
REPLY
REPLY
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 11/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
REPLY
REPLY
Since polarity and phase cannot be set as with SPI, would this not
be a disadvantage? Are these parameters sometimes adjusted for
better communication, and thus SPI might be a better choice over
I2C ?
REPLY
REPLY
REPLY
REPLY
REPLY
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 12/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 13/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
In the Start & STOP cases, the SDA line is represented wrongly
Start: SDA goes high to low (In the diagram, it is low to high)
Stop: SDA goes from low to high(In the diagram, it is high to low)
REPLY
REPLY
Thanks
Aakash patel
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
REPLY
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 14/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
The content was concise and I could grasp it in one reading, also
the diagrams were of great help. Much appreciated.
REPLY
LEAVE A REPLY
Your email address will not be published. Required fields are marked *
COMMENT
Save my name, email, and website in this browser for the next time I comment.
For security, use of Google's reCAPTCHA service is required which is subject to the Google
Privacy Policy and Terms of Use.
POST COMMENT
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 15/16
10/9/23, 12:45 PM Basics of the I2C Communication Protocol
https://www.circuitbasics.com/basics-of-the-i2c-communication-protocol/ 16/16