Monday, August 12, 2019

Communication Protocol for Embedded Systems - Part 1 (I2C)


Hey, Let's discuss about communication protocols commonly used in embedded field. So, Let’s begin with what communication protocol actually mean.

Communication - Imparting of information from one system to another system via a medium is termed is Communication.

Protocol - Standard set of rules which determine how data is transmitted at both ends of communication.

So, we can say that Communication Protocol is basically standard set of rules that allow two electronic devices to connect to exchange data within them.
There are two types of electronics’ communication protocol -
1. Inter System Communication Protocol
2. Intra System Communication Protocol

Inter System Communication Protocol - This protocol is used to communicate the two different devices like communication between PC and Micro-controller, PC and Development Boards. In this scenario, communication is done via inter bus system.

Inter System Communication Protocol can be divided into 3 categories -
a. USB Communication Protocol
b. UART Communication Protocol
c. USART Communication Protocol

Intra System Communication Protocol - This protocol establishes the communication between the two devices within circuit board like Micro-controller and Sensors. Advantage of Intra System Communication Protocol is secure data access.

Intra System Communication Protocol can be divided into 3 categories -
a. I2C Protocol
b. SPI Protocol
c. CAN Protocol
In this blog, we will study in detail about Intra System Communication Protocol. 
So, let’s begin with I2C Protocol.

I2C Protocol -
The name I2C is shorthand for a standard Inter-Integrated Circuit bus.
I2C protocol is intended to allow multiple "slave" digital integrated circuits ("chips") to communicate with one or more "master" chips. Like the Serial Peripheral Interface (SPI), it is only intended for short distance communications within a single device. Like Asynchronous Serial Interfaces (such as RS-232 or UARTs), it only requires two signal wires to exchange information.

I2C features -
Wires Used
2
Maximum Speed
Standard Mode - 100 kbps
Fast Mode - 400 kbps
High Speed Mode - 3.4 Mbps
Ultra Fast Mode - 5 Mbps
Synchronous or Asynchronous
Synchronous
Serial or Parallel
Serial
Max number of Masters
Unlimited
Max number of Slaves
128 for 7-bit address
1024 for 10-bit address
(Theoretically)*
 *Actually there are some reserved addresses like 0x00.
I2C necessitates two wires SDA (Serial Data Line) and SCL (Serial Clock Line) to carry information between devices. These two active wires are said to be bidirectional.

SDA - The line for the master and slave to send and receive data.
SCL (Serial Clock) – The line that carries the clock signal.
Since, I2C is a serial communication protocol, so data is transferred bit by bit along a single wire (SDA line).

Open-Drain Outputs
Having pull-up resistors is an open-drain scheme. I2C bus devices pull-down the voltage on the bus instead of using their own operating voltage. The pull-up resistor value depend on a number of factors. There are number of  formulas to calculate the correct pull-up resistor value.
If you don’t want to bother calculating the resistor value, use the typical 10  or 4.7 kΩ.

I2C Basic Commands Sequence
1. Start Bit Condition
2. Stop Bit Condition
3. Acknowledgement Condition
4. Master to slave Write operation
5. Read Operation Slave to Master

I2C Timing Diagram


Both SDA and SCL lines are high when idle. A start condition occurs when the SDA goes low before the SCL. Data is sent immediately following the start condition. The end of transmission is signaled by a stop condition. A stop condition occurs when the SDA goes high after SCL.

Start and Stop Bit Condition
When the master (micro-controller) wishes to talk to a slave device (for example ADC), it begins communication by issuing a start condition on the I2C bus, and then issues a stop condition. The I2C start and stop logic levels are shown in the figure.
The I2C start condition defines as a high to low transition of the SDA line while the SCL line is high. AN I2C stop condition occurs when the SDA line toggles from low to high while the SCL line is high.
The I2C master always generates the Start (S) and Stop (P) conditions. Once the I2C master initiates a START condition, the I2c bus is considered as being in busy state.

 

Besides this there is also a “Repeated Start” condition which allows a master to continue the current transaction without losing atomicity.
This is achieved by NOT sending a stop after the transaction but sending a Start in its place.

Acknowledgement Condition
Each byte transmitted over the I2C bus is followed by an acknowledge condition from the receiver, which means, after the master pulls SCL low to complete the transmission of 8-bit, the SDA will be pulled low by the receiver to the master.
If, after the transmission of the receiver does not pull, the SDA line LOW is considered to be a NCK condition.

 


Master to Slave Write Operation
1. Send a start sequence
2. Send the I2C address of the slave with the R/W bit low (even address)
3. Send the internal register number you want to write to
4. Send the data byte
5. [Optionally, send any further data bytes]
6. Send the stop sequence.
The bit sequence will look like this -



Read Operation Slave to Master
1. Send a start sequence
2. Send 0xC0 ( I2C address of the CMPS03 with the R/W bit low (even address)
3. Send 0x01 (Internal address of the bearing register)
4. Send a start sequence again (repeated start)
5. Send 0xC1 ( I2C address of the CMPS03 with the R/W bit high (odd address)
6. Read data byte from CMPS03
7. Send the stop sequence.
The bit sequence will look like this -


Advantages of I2C
1. Devices can work as both master and slave.
2. I2C employs better error handling functionality.
3. Addressing mechanism eases master slave communication

Disadvantages of I2C
1. The biggest disadvantage of I2C Communication Protocols is its limited speed.
2. The size of the data frame is limited to 8 bits.
3. I2C is a half-duplex protocol which adds complexity.

Applications
I2C is used where short distance communication within boards or devices are needed and when we need to connect more devices to the network. 

No comments:

Post a Comment