Introduction To I2C Protocol:
The I2C Protocol, pronounced as I-squared-C, is a multi-master, multi-slave, packet-switched single-ended, serial-based synchronous type computer bus protocol invented in 1982 by Philips Semiconductor (Now it is NXP).
The I2C is a serial protocol for a two-wire interface to connect low-speed devices like microcontrollers, EEPROMs, A/D and D/A converters, Automotive vehicle sensors, I/O interfaces and other similar peripherals in embedded systems. Each I2C slave device needs an address which must still be obtained from the NXP.
The I2C bus is very popular because it is very simple to use, there can be more than one master, only upper bus speed is defined and only two wires with pull-up resistors are needed to connect the number of devices. Mostly the maximum number of Slaves can be connected to the BUS depends on the slave address. If the slave address is 7-bit, then the number of slaves that can be connected to the I2C BUS is 2^7 = 128. The I2C can use even slower microcontrollers with general-purpose I/O pins since they only need to generate correct Start and Stop conditions in addition to functions for reading and writing a byte.
Each slave device has a unique address. Transfer from and to the master device is serial and it is split into 8-bit packets. All these simple requirements make it very simple to the implement I2C interface of the even with cheap microcontrollers that have no I2C hardware controller. You only need 2 free I/O pins and few simple i2C routines to send and receive the commands.
The initial I2C specifications of the defined maximum clock frequency of 100 kHz. This was later increased to the 400 kHz as
I2C Commands (simplified for communication:
- Device Address + write bit “To Write” = 0xC0
- Device Address + read bit “To Read” = 0xC1
- Command to Write “Convert Pressure and Temperature” = 0x12
- Command to Read “Pressure ADC High byte” = 0x00
- Command to Read “Pressure ADC Low byte” = 0x01
- Command to Read “Temperature ADC High byte” = 0x02
- Command to Read “Temperature ADC Low byte” = 0x03
- Command to Read “Coefficient data byte 1 High byte” = 0x04
I2C Protocol Terminologies:
- Transmitter: The device that transmits data to the bus.
- Receiver: The device that receives data to the bus.
- Master: The device that generates a clock, starts communication, sends I2C commands, and stops communication.
- Slave: The device that listens to the bus and is addressed by the master.
- Multi-master: More than one master can attempt to control the bus at the same time without corrupting the message is called a Multimaster.
- Arbitration: A procedure to ensure that, if more than one master simultaneously tries to control the bus – only one is allowed to do so; the winning message is not corrupted.
- Synchronization: Procedure to synchronize the clock singles of two or more devices is called synchronization.
I2C BUS Architecture
The I2C is a serial bus protocol consisting of two signal lines such as SCL and SDL lines which are used to communicate with the devices. The SCL stands for a ‘serial clock line’ and this signal is always driven by the ‘master device’. The SDL stands for the ‘serial data line’, and this signal is driven by either to the master or the I2C peripherals. Both these SCL and SDL lines are in an open-drain state when there is no transfer between I2C peripherals.
What is Open-Drain Outputs?
The open-drain is the concept for FET transistor wherein the drain terminal of the transistor is the open state. The SDL and SCL pins of the master device are designed with the transistors in the open state, so data transfer is possible only when these transistors are conducted. Hence, these lines or drain terminals are connected through pull-up resistors to VCC for conduction mode.
Both signals (SCL and SDA) are bidirectional. They are connected via resistors to the positive power supply voltage. This means that when the bus is free, both lines are of the high. All the devices on the bus must have open-collector or open-drain pins. Activating of the line means pulling it down (Wired AND). The number of devices on a single bus is almost unlimited – the only requirement is that the bus capacitance does not exceed 400 pF. Because the logical 1 level depends on the supply voltage, there is no standard of the bus voltage.
I2C Protocol BUS Interface:
There are many slave devices are interfaced with the microcontroller with the help of the I2C bus through I2C level shifter IC for transferring the information between them. The I2C protocol used to connect a maximum of 128 (7-bit Slave address) devices that are all connected to communicate with the SCL and SDL lines of the master unit as well as the slave devices. It supports the Multi-master of the communication, which means two masters are used to communicate the external devices.
How Communication occurs in I2C BUS?
The I2C bus protocol is the most commonly used in master and slave communication wherein the master is called “microcontroller”, and the slave is the called other devices such as ADC, EEPROM, DAC and similar of the devices in the embedded system. The number of slave devices is connected to the master device with the help of the I2C bus, wherein each slave consists of the unique address to communicate it. The following steps are used to communicate the master of the device to the slave:
- First, the master device issues a start condition to inform all the slave devices so that they listen to the serial data line.
- The master of the device sends the address of the target slave device which is compared with all the slave devices’ addresses as connected to the SCL and SDL lines. If anyone addresses the matches, that device is selected, and the remaining all of the devices are disconnected from the SCL and SDL lines.
- The slave device with a matched address received from the master, responds with an acknowledgment to the master thereafter communication is established between both the master and slave devices on the data bus.
- Both the master and slave receive and transmit the data of depending on whether the communication is read or write.
- Then, the master can transmit 8-bit of data to the receiver which replies with a 1-bit acknowledgment.
Arbitration in I2C Protocol
For normal data of the transfer on the I2C bus, only one master can be active. If for some reason of the two masters initiate the I2C command at the same time, the arbitration procedure determines which of the master wins and can continue with the command. Arbitration is performed of the SDA signal while the SCL signal is high. Each master of the checks if the SDA signal on the bus corresponds to the generated SDA signal. If the SDA signal on the bus is low but it should be high, then this master has lost the arbitration. Master I2C device that has lost arbitration can generate SCL pulses until the byte ends and must then release the bus and go into slave mode. The arbitration of the procedure can continue until all the data is transferred. This means that in the multi-master system each I2C master of the must monitor the I2C bus for collisions and act accordingly.
I2C Bus Clock Synchronization and Handshaking:
The Slave devices that need some time to process received byte or are not ready yet to send the next byte, can pull off the clock low to signal to the master that it should wait. Once the clock is released the master can proceed with the next byte.
7-bit I2C Addressing:
A slave address may contain a fixed of the programmable part. Some slave of the devices has few bits of the I2C address dependent on the level of address pins. This way it is possible to have on the same I2C bus more than one I2C device with the same fixed part of the I2C address.
The allocation of I2C addresses is administered by the I2C bus committee which takes care of the allocations. Two groups of 8 I2C addresses are reserved for future uses and one address is used for 10-bit I2C addressing.
|Slave Address||R/W Bit||Description|
|0000000||0||General Call Address|
|0000010||X||Reserved for different BUS Format|
|0000011||X||Reserved for future purpose|
|00001XX||X||HS-Mode & Master mode|
|11111XX||X||Reserved for Future Purpose|
|11110XX||X||10-bit Slave Addressing|
Applications of I2C Protocol
The I2C (Inter-Integrated Circuit) protocol is a serial communication protocol that allows multiple devices to communicate with each other using a common bus. Here are some common applications of the I2C protocol:
- Sensors and modules: Many sensors and modules such as temperature sensors, accelerometers, and gyroscopes use I2C communication to send and receive data to and from a microcontroller.
- LCD displays: I2C is commonly used to connect LCD displays to a microcontroller, allowing the display to show text or graphics.
- EEPROMs and other memory devices: I2C is used to interface with EEPROMs (electrically erasable programmable read-only memory) and other memory devices such as FRAM (ferroelectric random access memory).
- Real-time clocks (RTC): RTC modules are often used to keep track of time in microcontroller projects. I2C is a common communication protocol used to communicate with these modules.
- Audio codecs: I2C is used to control audio codecs, which are used to convert analog audio signals to digital signals and vice versa.
- Power management ICs: I2C is used to communicate with power management ICs (integrated circuits), which are used to control the power supply to various components of a system.
- Motor controllers: I2C can be used to communicate with motor controllers to control the speed and direction of motors.
- LED drivers: I2C is used to control LED drivers, which are used to control the brightness and color of LEDs.
Advantages of I2C Protocol
The I2C (Inter-Integrated Circuit) protocol is a popular serial communication protocol that is used in a wide range of applications. Here are some of the advantages of using I2C:
- Simple Hardware Requirements: I2C requires only two wires for communication, making it a simple and cost-effective option for connecting multiple devices.
- Multi-Master Capability: I2C supports multi-master communication, allowing multiple devices to share the same bus and communicate with each other without conflicts.
- Addressing: I2C uses addressing to identify specific devices on the bus, which makes it easy to add or remove devices from the system.
- Low Power Consumption: I2C operates at low speeds and uses low power, making it an ideal choice for battery-powered devices.
- Support for Different Data Rates: I2C supports different data rates, allowing devices to communicate at speeds that are suitable for their specific needs.
- Compatibility with a Wide Range of Devices: I2C is compatible with a wide range of devices, including sensors, memory, displays, and other peripherals.
- Robust Error Detection: I2C has robust error detection capabilities, which allows devices to detect and recover from transmission errors, ensuring reliable communication.
Disadvantages of I2C Protocol
While the I2C (Inter-Integrated Circuit) protocol offers many advantages, there are also some disadvantages that should be considered when choosing a communication protocol for a particular application. Here are some of the disadvantages of using I2C:
- Limited Range: I2C is designed for communication over short distances, typically a few meters or less. For longer distances, other communication protocols may be more suitable.
- Limited Bandwidth: I2C operates at lower speeds compared to other protocols like SPI, which can limit the amount of data that can be transferred.
- Shared Bus: I2C uses a shared bus, which means that multiple devices are competing for access to the same bus. This can lead to collisions and delays if multiple devices try to communicate simultaneously.
- Clock Synchronization: I2C uses a clock signal to synchronize communication between devices. If the clock signal is not synchronized properly, data transfer can be disrupted, leading to errors and lost data.
- Pull-up Resistors Required: I2C requires pull-up resistors on the communication lines to ensure proper voltage levels. This can add additional hardware components and increase cost.
- Interrupt-Driven: I2C is interrupt-driven, which means that the receiving device must interrupt the sending device to acknowledge that data has been received. This can add additional complexity to the system design.
- Not Suitable for High-Speed Communication: I2C is not suitable for high-speed communication applications, such as video or audio data transmission, where higher bandwidth and faster data transfer rates are required.