Communication Protocols
I2C, SPI, UART, and similar protocols are communication protocols used to enable data transfer
between microcontrollers, sensors, displays, and other peripheral devices. These areserial
communication protocols, meaning data is sent onebit at a time over a single wire or channel,
as opposed to parallel communication where multiple bits are sent simultaneously.
1. I2C (Inter integrated circuit bus protocol):
● sed forserialcommunication
U
● With just2 lineswe can interface128 devices (2^7)
● Used in general for low BW communication
● 2 lines:
○ SCL: serial clock line, provided forsynchronouscommunication
○ SDA: serial data line
● SupportsMulti master Multi slaveconfiguration
Both SCL and SDA should behold up, like we can place5V connection through register
●
● Not necessary as many masters have internal pull up
T
● ype:Synchronous,multi-master, multi-slave.
● Number of Wires:2 (SDA for data, SCL for clock).
● Addressing:Each device on the bus has a unique address,7 bit addressingto comm
with 128 devices obv
●
●
Majority times, data from master is sent to slave
Clock stretching
lock stretchingwhenmaster is transferring datato slaveand if there is some imp task
C
that slave needs to do, thenslave will doclock stretching
lock stretching is a mechanism used in theI²C (Inter-IntegratedCircuit) protocolthat
C
allows aslave deviceto hold the clock line (SCL)lowto slow down communication
when it needs more time to process data.
o,Slave makesthis clock signal SCLlowtill itis ready to continue
S
Once slave releases low signal, then master is allowed to send data to slave
I2C supports multi master multi slave config, but Mostly we do single master multiple
slave
Data Transmission in I2C Protocol
How It Works:
O
● ne device acts as amaster and controls the clock(SCL).
● Multiple devices (masters/slaves) can share the same bus.
● Communication starts when themaster sends a startcondition followed by the address
of the target device.
● Data is sent/received in8-bit frames,followed byan ACK/NACK from the receiver.
When master wants to initiated Data write or read:
. M
1 aster first sends thestart bit
2. Now master should haveunique address of the slavefrom which it wants to
read/write
Somasterwill have to send thisaddress on SDA line
3. After thismaster will tell whether it wants to reador write data,
Forwrite:0, read:1
4. After this, Slave willacknowledgement:
a. 0 if slave is ready
b. 1 if not ready
5. In case of
a. Writing: Master willsend datato slave : say 01101100,8 bit
b. Reading: Slave will send data to master: say 01101100 ,8 bit
6. After receiving data
a. Writing: Slavesends acknowledgementto master :ACK=0
b. Reading: Master sends acknowledgement to slave:ACK=1
7. At the end, Master sendsstop bit
2.SPI Protocol:
● erialperipheral interfacebus
S
● Used for serial communication
● Needs4 wires
● Synchronous comm(as we provide clock along with data)
● Supportshalf and full duplexcommunication
U
● sed for on board short range comm only (like interfacing a microcontroller with display)
● Maxspeedis 10Mbps, farbetter than I2C, so betterbandwidth
● Master provides cock for synchronous.
Key Features:
T
● ype:Synchronous,master-slave.
● Only Single master, Multi slave allowed
● Number of Wires:4 (SCLK, MOSI, MISO, and SS).
○ SCLK:Clock signal.
○ MOSI:Master Out Slave In (data from master to slave).
○ MISO:Master In Slave Out (data from slave to master).
○ SS:Slave Select (used to enable/disable a specificslave device).
● Data Rate:Typically faster than I2C (up to tens ofMbps).
How to configure 2 devices having spi protocol?
● S/CS : We have slave select/ chip select line to select slave
S
● SCLK : Master will provide serial clock to slave
● MOSI : Master sends data to slave
● MISO : Master will read data from slave
How protocol is providing Half duplex comm?
alf duplex : one direction comm possible, so when master reads , it cannot write and
H
vice versa
So when master has finished sending data MOSI, only then slave can send data MISO
Protocol also supports Full duplex, how?
aster and slave can send data at the same time simultaneously
M
Inside Master and slave there will beshift registers
oth shift reg connected with clock generator
B
Clock provided by master
sing them, we can swap data from master to slave
U
Say i have
40H and 60H
Then after 8 clock cycles, we get
60H and 40H
How It Works:
● ne device is themaster, and the others are slaves.
O
● Master generates the clock signal (SCLK).
● Data is exchanged simultaneously in both directions (full-duplex) via MOSI and MISO.
● Each slave device has its ownSlave Select (SS)pin,which the master uses to enable
or disable communication with a specific device.
Communication happens wrt 4 different modes:
POL =0, CPHA(clock phase)=0 → data read happening at rising edge
C
CPOL =1,CPHA(clock phase)=0→ data read happening at falling edge
POL =0,CPHA(clock phase)=1→ data read happening after 180 phase of clock
C
CPOL =1,CPHA(clock phase)=1→ data read happening after 180 phase of clock
ne of disadvantage is that it requires 4 wires for 2 device communication, so if we
O
increase no. of slaves, more no. of wires required for slave select, remaining 3 lines
common for other slaves
Advantages:
H
● igh-speed communication.
● Full-duplex transmission.
● No need for addressing.
Disadvantages:
M
● ore wires compared to I2C.
● Limited scalability (each slave needs a separate SS line).
Applications:
● High-speed data transfer for sensors, SD cards, flash memory, and display modules.
Q) Multi-Master & Multi-Slave Configurations in I²C and SPI
othI²C (Inter-Integrated Circuit)andSPI (SerialPeripheral Interface)support multiple
B
devices, but their handling ofmulti-masterandmulti-slaveconfigurations differs.
I²C: Supports Multi-Master & Multi-Slave ✅
1. Multi-Slave I²C
I²C is designed for multi-slave communication. Each slave has aunique 7-bit or 10-bit
address, and the master selects which slave to communicatewith.
W
● iring:All devices share two lines (SDA - Data, SCL- Clock).
● Communication:Master sends theaddress, and onlythe matching slave responds.
● Example:A microcontroller communicating with multiplesensors like temperature and
pressure sensors.
2. Multi-Master I²C
I²C allows multiple masters, butonly one can controlthe bus at a time.
● A rbitration:If two masters try to communicate simultaneously,arbitration (bitwise
comparison) determines which one continues.
● Clock Synchronization:If two masters provide differentSCL speeds, the bus slows
down to the lowest speed.
● Example:Multiple microcontrollers managing the sameperipheral devices.
SPI: Multi-Slave Supported, Multi-Master is Complex 🚫
1. Multi-Slave SPI ✅
SPI naturally supports multiple slaves usingchip select (CS/SS) lines.
E
● ach slave needs a separate SS (Slave Select) linecontrolled by the master.
● Wiring:
○ MOSI (Master Out Slave In)
○ MISO (Master In Slave Out)
○ SCK (Serial Clock)
○ SS (Slave Select) – One per slave
● Example:A microcontroller communicating with an SDcard and a display.
2. Multi-Master SPI 🚫 (Difficult to Implement)
SPI doesnot natively supportmultiple masters because:
T
● here isno built-inarbitrationlike in I²C.
● Masters could drive theclock (SCK) and chip select(SS) linesat the same time,
causing conflicts.
● Workarounds exist usingexternal arbitrationcircuitsorbus contention handling, but
they are complex.
Comparison Table
Conclusion
I²C is better for multi-master systemsbecause ofbuilt-in arbitration.
●
● SPI is better for speedbut needs extra lines foreach slave and does not support
multiple masters easily.
3.I2C V/S SPI Protocol:
PI is faster
S
No need of acknowledgement in SPI as dedicated lines are provided
I2C has redundancy in bits→ start, Stop, Acknowledgement, address
I2C is slower
For high BW, Full duplex → SPI
Multiple masters devices → I2C better
4.UART Protocol:
● erialprotocol
S
● U : universal, means we can apply this protocol to any transmitter and receiver
● A :Asynchronous, wedon't use clock signal for commof data
● 2 wireCommunication
● Tx and Rx
● Baud Rate should be same
●
Comparison of UART and Parallel Comm
In terms of bus complexity, UART is better, but in terms of speed, Parallel is better
UART Configuration
aud rate should be samefor device 1 and 2, otherwisethey cant understand at what speed the
B
data is coming, normally baud rate is 9600 for UART
Also data length should have fixed data length
What is UART?
ART (Universal Asynchronous Receiver Transmitter) is a hardware communication protocol
U
used for serial communication between two devices. It is widely used in embedded systems,
microcontrollers, and computers to send and receive data over a simple two-wire interface.
How Does UART Work?
ART transmits and receives dataasynchronously, meaningit does not require a clock signal.
U
Instead, it relies onpre-agreed settings betweenthe sender and receiver, such asbaud rate,
start/stop bits, and parity bits.
Basic UART Communication Steps:
1. D ata Preparation:The transmitter takes parallel data(e.g., an 8-bit byte) and converts it
into a serial stream of bits.
2. Data Transmission:The transmitter sends data frame-by-frame,starting with astart
bit, followed by data bits, an optionalparity bit,and astop bit.
3. Data Reception:The receiver detects the start bitand reads the incoming bits based on
the agreed baud rate.
4. Data Reconstruction:The receiver converts the serialdata back into parallel form.
UART Frame Structure
Each data packet in UART follows a specific format:
| Start Bit | Data Bits (5-9) | Parity Bit (Optional) | Stop Bit (1 or
2) |
.
1 tart Bit (1 bit)→ Always LOW (0) to indicate thebeginning of a new data frame.
S
2. Data Bits (5-9 bits)→ The actual data being transmitted(typically 8 bits).
3. Parity Bit (Optional, 1 bit)→ Used for error checking(Even or Odd parity).
4. Stop Bit (1-2 bits)→ Always HIGH (1) to indicatethe end of the data frame.
Key Features of UART
● ull-duplex Communication:Can send and receive datasimultaneously.
F
● Asynchronous:No need for a clock signal.
● Simple Wiring:Requires onlytwo wires(TX for transmission,RX for reception).
● Baud Rate:Determines the speed of data transfer (e.g.,9600, 115200 bps).
● Error Detection:Uses parity bits and stop bits todetect errors.
Advantages of UART
✅
Simple and low-cost
✅
Reliable for short distances
✅
No need for a separate clock signal
✅
Supports full-duplex communication
Disadvantages of UART
❌
Limited speed(Compared to SPI/I2C)
❌
Only supports point-to-point communication(No multipledevice support)
❌
Data frame overhead(Start, stop, and parity bitsadd extra bits)
Comparison with Other Communication Protocols
singparity bitwe can identify whether we have receiveddata correctly or not, i.e.error
U
correction
Even parity:0
Key Features:
● Type:Asynchronous, point-to-point communication.
● N umber of Wires:2 (TX for transmit, RX for receive). Often uses GND for a common
reference.
● Data Rate:Configurable using baud rates (common values:9600, 115200, etc.).
● Data Frame:Start bit, data bits (5–9), optional paritybit, stop bit(s).
How It Works:
U
● nlike I2C and SPI, UART does not use a clock line.
● Devices must agree on the samebaud rate(speed ofcommunication).
● Data is transmitted asynchronously in chunks (frames), with each frame having:
○ Astart bit(indicates the start of data).
○ Data bits(the actual information).
○ Optionalparity bitfor error checking.
○ Stop bit(s)to indicate the end of the frame.
Advantages:
S
● imple, requires only two lines.
● Widely supported by most microcontrollers.
Disadvantages:
L
● imited to two devices (point-to-point).
● Slower compared to I2C and SPI.
● Requires both devices to use the same baud rate.
Applications:
● D
ebugging (serial communication with PCs), GPS modules, Bluetooth modules, and
GSM modules.
5.USB:
ajority in all computers, we have usb 2.0 as this much data rate is sufficient
M
It has black strip
We have different type of usb for different application
ajority we can see have 4 busses
M
2 busses : D+ and D-, carry the same info but are mirror images
And, at the receiver, there will be a differential amplifier, i.e. we amplify the difference of both the
signals
We will have better SNR (higher)
2.5 - (-2.5) = 5V, so increase SNR
ighSignal-to-Noise Ratio (SNR)is desirable in manyapplications because it indicates that
H
the signal (desired information) is much stronger than the noise (unwanted interference).
6. RS-232:
RS-232: The Standard for Serial Communication
S-232 (Recommended Standard 232) is aserial communicationstandardused for
R
transmitting data between computers and peripheral devices. It defineselectrical, signal
timing, and physicalcharacteristics for communication.
Key Features of RS-232
● synchronous communication(no clock signal required).
A
● Point-to-point connection(only two devices can communicateat a time).
● Voltage levels:Useshigh voltagefor data representation.
● Supports full-duplex(simultaneous send/receive).
● Slow speedcompared to modern serial interfaces.
How RS-232 Works?
RS-232 transmitsbinary data(0s and 1s) asvoltagelevels:
Logic Level Voltage
1 (Mark/Idle) -3V to -15V
0 +3V to +15V
(Space/Active)
his isinverted compared to TTL logic(0V for LOW,5V for HIGH). That's whylevel
T
converters(like MAX232) are needed to connect RS-232to microcontrollers.
RS-232 Pin Configuration
TheDB-9 (9-pin) connectoris the most commonly usedRS-232 connector.
Pin Name Function
1 DCD Data Carrier Detect
2 RXD Receive Data
3 TXD Transmit Data
4 DTR Data Terminal Ready
5 GND Ground
6 DSR Data Set Ready
7 RTS Request to Send
8 CTS Clear to Send
9 RI Ring Indicator
● XD (Transmit Data):Sends data from the device.
T
● RXD (Receive Data):Receives data from the other device.
● GND (Ground):Common ground for both devices.
● RTS/CTS & DTR/DSR:Flow control signals.
Some applications only needTXD, RXD, and GNDforbasic data transmission.
RS-232 Communication Process
.
1 tart Bit: Indicates the beginning of data transmission.
S
2. Data Bits (5-8 bits): Actual data being sent.
3. Parity Bit (Optional): Used for error checking.
4. Stop Bit (1 or 2 bits): Marks the end of data transmission.
Thebaud rate(e.g.,9600 bps) must be the same onboth devices.
Advantages of RS-232
✅
Simple and widely used
✅
Works over long distances (up to 15m)
✅
Supports full-duplex communication
Disadvantages of RS-232
❌
Slow data rates(up to 115.2 kbps)
❌
High voltage levels (requires level converters)
❌
Limited to point-to-point communication
RS-232 vs. UART
Feature RS-232 UART
Type Communication Standard Communication Protocol
oltage
V ±3V to ±15V 0V to 5V (TTL)
Levels
Wiring 3-9 wires 2 wires (TX, RX)
Speed Slow (~115 kbps) Faster (Up to Mbps)
Usage Long-distance communication Embedded systems
R
● S-232 is a standard, whileUART is a protocolusedin microcontrollers.
● To interface a UART-based microcontroller with RS-232, aMAX232 converter ICis
required.
Where is RS-232 Used?
● Industrial automation(PLC communication)
● Legacy computer peripherals(serial mouse, modems)
● Microcontroller debugging
● Point-of-sale (POS) systems
● Medical devices
Example: RS-232 Communication with Arduino
To connect anArduino (UART, 5V logic)to anRS-232device, use aMAX232level shifter:
pp
c
CopyEdit
void setup() {
Serial.begin(9600); // Initialize UART (RS-232 communication)
}
void loop() {
Serial.println("Hello, RS-232!");
delay(1000);
}
This will send "Hello, RS-232!" every second over the serial port.
Conclusion
S-232 is a classic serial communication standard that has been widely used in industrial and
R
embedded systems. Though slower and gradually being replaced by USB and other protocols, it
remains useful for legacy systems and debugging purposes.
7. Parallel Communication
arallel communication is a method of transferring data where multiple bits are transmitted
P
simultaneously over multiple channels or wires. Each bit has its own dedicated wire, and all bits
are sent at the same time. This contrasts with serial communication, where bits are sent one
after the other over a single channel.
Key Features of Parallel Communication
1. Multiple Wires or Channels:
○ Each bit of data uses a separate wire.
○ For example, an 8-bit data word requires 8 separate wires for the data.
2. High Speed:
○ Since multiple bits are sent simultaneously, the data transfer rate is higher than
serial communication for short distances.
3. Synchronization:
○ A clock signal is usually required to synchronize the sending and receiving ends.
This ensures all bits are interpreted correctly at the receiver.
4. Short Distance:
○ Parallel communication is typically used for short distances due to problems like
signal interference and crosstalk between wires over long distances.
How It Works
1010
Imagine you have a4-bit data word, like . Inparallel communication:
● Bit 1 (
1)is sent over Wire 1.
● Bit 2 (
0)is sent over Wire 2.
● Bit 3 (
1)is sent over Wire 3.
● Bit 4 (
0)is sent over Wire 4.
All four wires transmit their respective bitsat the same time.
Example in Real Life
1. Computer Buses:
○ Inside a computer, data moves between the CPU, memory, and peripherals using
parallel communication buses like the data bus.
2. Printers:
○ Older printers used parallel ports (e.g., the Centronics port) to receive data from
computers.
Advantages
1. Faster Data Transfer:
○ Multiple bits are transmitted simultaneously, making it faster for large volumes of
data.
2. Simplicity in Timing:
○ Easier to achieve synchronous communication since all bits arrive together.
Disadvantages
1. Wiring Complexity:
○ Requires more wires, making the design bulky and expensive.
2. Signal Degradation:
○ Over long distances, parallel communication suffers from issues like crosstalk
and skew (timing mismatches between wires).
3. Distance Limitation:
○ Best suited for short-range communication, usually within a device or a small
setup.