I2C is one of the communication protocol which is often used for data transmission between micro controllers and peripheral devices.
This article explain how i2c works and how to use it.
Table of Contents
What is I2C?
I2C(Inter-Integrated Circuit)is a de facto standard developed by Philips Semiconductors (NXP Semiconductors).
I2C is often used in communication between micro controllers and peripheral devices (such as EEPROM).
I2C is pronounced as “I two C” or “I squared C” and sometimes written down Inter-IC.
The specification of I2C is published by NXP Semiconductors as the name of UM10204 I2C-bus specification and user manual (registration required).
I2C is de facto standard as famous as SPI that is implemented all over the world.
Overview of I2C
I2C uses two signal lines: SDA and SCL.
SDA is the abbreviation of Serial Data, which is for data exchange.
SCL is the abbreviation of Serial Clock, which is for sharing clock signal.
Each lines requires pull-up resistors.
In I2C communication, devices are divided into master and slave.
Master begins communication, generates a clock signal, and terminates communication.
Master can communicate with a slave by specifying the slave address which is unique to devices.
Example of the behavior of master and slaves
Whn master transmits data to slave:
- Master begins communication.
- Master specifies a slave address.
- Master transmits data to the slave.
- Master ends communication.
When master receives data from slave:
- Master begins communication.
- Master specifies a slave address
- She slave transmits data to the master.
- Master end communication.
How I2C works
Data transmission
SDA and SCL will work when transmitting data:
The voltage statuses of SDA when SCL=HIGH are received as data.
Thus, changing the voltage status of SDA when SCL=HIGH is prohibited.
Start and stop communication
To tell the beginning and the end of communication, master generates START Condition and STOP Condition.
When SCL=HIGH, SDA changes:
- HIGH -> LOW, START Condition
- LOW -> HIGH, STOP Condition
Communication between master and slave begin with START Condition and end at STOP Condition.
ACK and NACK
If the receiver receives data without error, it returns acknoledge (ACK) to the transmitter.
If the receiver detects errors while receiving data, it does not return ACK. This is called not acknoledge (NACK)
Byte format
I2C format is as follows.
- Master generates START Condition.
- Master broadcast slave address (7 bits).
- Master transmitts R/W bit.
- Slave specified with slave address returns ACK.
If R/W=0 (transmission from master to slave),
- Master transmits data (8 bits)
- Slave returns ACK.
- Return to 5 or master generates STOP Condition.
If R/W=1 (transmission from slave to master),
- Slave transmits data (8 bits).
- Master returns ACK.
- Return to 5 or master generates STOP Condition.
Slave address and data are both transmitted by MSB first.
How to use I2C
An example of using EEPROM by I2C is here.
Summary
This article explained how I2C works.