I2C stands for Inter Integrated Circuit. It is one of the most widely used communication protocols used in embedded systems. I2C is most commonly used in a circuit itself hence named inter integrated circuit.
What is I2C
It was invented by philips.It is a two line synchronous communication protocol. Transmitter and receiver sharing a common clock is known as synchronous. In I2C only two lines are used to interface the transmitter and receiver. The two lines are SDA , SCL . The device which gives the clock is known as master , and the other device is known as slave. In short Master is the device that has control over other devices.
SCL – Serial Clock : This is the clock line given to slave/s from master.
SDA – Serial Data : This is a bidirectional bus where data transmission occurs.
I2C is useful when there are multiple devices on a chip. In I2C interface multiple slaves and multiple masters can be interfaced using only 2 lines.
Types of Interfaces:
- Master Slave Interface
- Single Master , Many Slaves
- Many Masters, Many Slaves.
Hardware implementation :
Data Transmission :
Data transfer in i2c protocol follow certain procedure
2. Device Address
3. Control Signal ( Read/Write )
5. Data Transmission
Before data is transmitted, both the lines SDA and SCL are high. As the data should be transmitted SDA line goes zero, following it SCL lines goes zero. This indication states that it is the start bit.
Address ( target device ) :
Master should select the device to which data should be sent or received. In total 128 slaves can be interfaced with a single master. Only 2 lines are required to communicate with all these slaves. So a 7 bit address is given on the SDA line to select the slave.
In the previous part already 7 bits in a byte were utilized to select address, this last bit is used to select, whether the master wants to read the data or write the data. If R/W = 1, then it wants to read the data , if R/W = 0, then it wants to write the data.
If the Master wants to write the data, then till now R/W = 0. Then the slave will acknowledge the master , whether it is ready to receive the data or not.
After the data transmission, the master acknowledges that the data is transmitted.
Once the total data is transmitted, both SCL and SDA will go high.
Advantages of I2C :
- It uses only 2 pins for communication.
- It can communicate with upto 128 devices.
- Addressing mode is inbuilt.
- It is ubiquitous.
- It is half duplex. As it has only one data line, either it can receive or transmit data at a time.
- Careful consideration of hardware due to pull up resistors.
- It is more complicated than SPI and UART.