Serial Communication Protocol
Serial Communication Protocol
a
Only Two lines are required for the communication
d
using I2C protocol.
n
Here main advantage of I2C protocol is interfacing
u
simplicity and with the use of Two lines we can
interface 128 devices.
It is simple, low bandwidth protocol used for short
g F
𝑰𝑰𝟐𝟐 𝑪𝑪
SDA
i n
range communication. SCL
Most I2C devices operates up to speed of 400Kbps.
er
e
I2C lines
in
1. Serial Data SDA
g
2. Serial Clock SCL
n
Both of this lines are pulled up at 5V, explains that no
E
communication is happening. Master Slave
Addressing is done by 7bits to communicates with 128 Clock Stretching in I2C protocol
devices at max.
An I2C Slave can hold of the master in the middle of
Here number of devices is also limited by the total
transaction using clock stretching.
allowed bus capacitance of 400pF.
Slave pull clock low until it’s ready to continue.
Master is initiating data transfer and controls the clock
I2C support multiple master as well but most system are
normally and the device being addressed is slave.
designed with one master and rest slaves.
Data Transmission in I2C Protocol
Slave Master Data from master Slave Master
= 01101100
5V 5V
OLED Address
Data from Slave=
a
HEX = 6CH
01101000
d
Binary = 1101100
u n
F
SDA SDA
𝟐𝟐
𝑰𝑰 𝑪𝑪
g
𝑰𝑰𝟐𝟐 𝑪𝑪
n
SCL
i
SCL Master to slave data write. Master to Slave data read.
r
Stop Bit = 0
e
D6 D5 D4 D3 D2 D1 D0 D7 D6 D5 D4 D3 D2 D1 D0
Master to
Slave data
SDA 0 1 1 0
in
1
e 1 0 0 0 0 0 1 1 0 1 1 0 0 0 0
write SCL
n g
Normally High
Master to SDA 0
E
Start Bit = 0 7 bits Slave Address Write bit = 0 ACK bit = 0 8 bits Data from master ACK bit = 0
D6 D5 D4 D3 D2 D1 D0
1 1 0 1 1 0 0
D7 D6 D5 D4 D3 D2 D1 D0
0 0 1 1 0 1 0 0 0
Stop Bit = 0
1 0
1
Slave data
Read SCL
Normally High Start Bit = 0 7 bits Slave Address Read bit = 1 ACK bit = 0 8 bits Data from Slave ACK bit = 1
SPI Protocol
Basics of SPI – Serial Peripheral Interface Bus Modes of SPI Protocol
SPI supports Half / Full Duplex serial communication. Based on Clock Polarity CPOL and Clock Phase CPHA, there are
It is synchronous communication protocol. {As we provide four operating modes.
a
clock along with data.}
d
SS Slave Select Enabled by making it 0
n
It is four wire communication protocol.
u
In most cases one master multiple slave protocol, but it also Mode 0
SCLK (CPOL = 0, CPHA = 0)
F
supports multiple master configuration.
It is on board short range communication protocol for SCLK (CPOL = 0, CPHA = 1) Mode 1
g
embedded system.
i n
It supports maximum speed up to 10Mbps. Mode 2
r
SCLK (CPOL = 1, CPHA = 0)
e
Master provides clock for synchronization.
SCLK (CPOL = 1, CPHA = 1) Mode 3
e
SPI supports 8 & 16 bits data frame format.
in
MISO IO Data On MISO/MOSI
MOSI
n g D7 D6 D5 D4 D3 D2 D1 D0
E
SCLK Advantages of SPI Protocol Disadvantages of SPI Protocol
SS/CS No start & Stop bits required. Four wires required.
Master Slave SIP is full Duplex protocol. Only One Master.
SS/CS {Slave Select / Chip Select} – Master selects the slave. Signals are unidirectional Multiple SS required for multiple
SCLK {Serial Clock} – Line to send clock signal. allowing easy isolation. slave.
MOSI {Master Out Slave In} – Line to send data from Master. No protocol for error detection.
No acknowledgment for
MISO {Master In Slave Out} – Line to receive data from Slave.
confirmation.
I2C Vs SPI
Parameters I2C – Inter Integrated Circuit Bus {Philips-1982} SPI – Serial Peripheral Interface Bus {Motorola-1979}
Numbers of Wires Only Two wires: Four Wire:
a
1. SDA – Serial Data 1. MOSI – Master Out Slave In
d
2. SCL – Serial Clock 2. MISO – Master In Slave Out
n
3. SCLK – Serial Clock
u
4. SS – Slave Select
F
Communication Half Duplex Half Duplex / Full Duplex
g
Configuration Suitable for Multiple Master Multiple Slave Suitable for Single Master Multiple Slave
Speed Slower {400Kbps Majority}
e
Start & Stop bits Required Not required
Acknowledgment after
data transfer
Required
in e Not required
Redundant data
n g
Required {Start + Stop + Address} Not required
E
Cost Low cost {Only two wire configuration} Costly {Minimum Four wire configuration}
IO Constraint Pull Resistor Not required
Addressing 7 bits addressing Chip Select
Power consumption Bit high {Pull Up resistor} Low
Plug & Play Yes No
Distance On board {Short} On board {Short}
Engineering Funda App ARM7 YT Playlist
UART
Basics of UART – Universal Asynchronous Configuration of UART before transmission
Receiver/Transmitter Both devices should be configured with same transmission speed. {Baud rate}
UART is used for serial communication. Fix the Data length. {5 to 9 bits}
a
It requires start bit {1 bit} and stop bit {1 or 2 bits}.
d
It is two wire communication protocol:
NRZ encoding is used for data communication.
n
One wire is for transmission
u
Second wire is for reception Data Format of UART
F
Data Format & Transmission speeds are configurable.
Here, clock is not given for synchronisation. Ideal
g
1 1 1 0 0 0 1 0 Ideal
i n
Start
r
UART 8 bits data Parity bit Stop
e
Tx Rx Bit = 0
Device 1 Device 2 {Optional} Bit = 1
e
Rx Tx
in
Start Data {5 to 9 bits} Parity Stop
g
bit = 0 Bit Bit
n
Parallel
Advantages of UART Protocol Disadvantages of UART Protocol
E
Less physical interfacing. Low speed communication.
Device 1 Device 2 Simple configuration. Start & Stop bit required.
Data size is configurable. Asynchronous communication.
Speed is configurable. Redundant bits are present. {Start
Full Duplex mode can be configure bit + Stop bits + parity bit}
UART transmission speed is slower compared to by two wire.
parallel communication but it needs less bus Error identification mechanism
interface for communication. {One bit error can be identified}
USB – Universal Serial Bus
Basics of USB – Universal Serial Bus
Design of USB protocol was developed by Compaq, DEC, IBM,
Intel, Microsoft, NEC & Nortel.
a
The main ideal behind USB is to make simple plug and play
serial communication.
n d
u
Versions of USB Protocol
g F
r i n
e
USB 1.0 Jan. 1996 Full speed 1.5 Mbps
Type A Type B USB 3.0 USB USB Type C Micro B
e
Mini Micro
in
USB 1.1 Aug. 1998 Full speed 12 Mbps
g
(White) USB 1.x
n
USB 2.0 Apr. 2000 High Speed 480 Mbps
E
USB 3.0 Nov. 2008 SuperSpeed 5 Gbps
(Black) USB 2.0
USB 3.1 July 2013 SuperSpeed+ 10 Gbps (Blue) USB 3.0 (Red, Orange
& Yellow) it
USB 3.2 Sep. 2017 SuperSpeed+ 20 Gbps (Teal) USB 3.1
provides
charging in
(Red) USB 3.2
sleep mode.
USB – Universal Serial Bus
Working of USB – Universal Serial Bus Objectives of USB – Universal Serial Bus
Main computer is Host. USB Interface is self Configuring.
It has Tree Topology, in which one Host and Multiple slaves can USB ports are backward Compactible.
a
be there. Host provides power processing. {small devices can mange
d
It has 7bits of addressing so we can interface 127 devices. power from host}
n
Host can only initiate data transfer in USB protocol. USB interface is Hot swappable. {use without reboot host}
u
It is Asynchronous protocol in which we don’t use clock signal. Powered Charging. {for charging small devices}
F
Plug & Play.
g
USB eliminates requirements for new peripherals.
i n
Wide range of Transfer speed.
r
USB provides best available Latency to current transfer. So,
e
that main program will have minimum effect.
e
No need of any other control signals. {Dedicated functioning of
in
data transfer that only decided by host.}
E
USB cable will have limited length. {However, USB port can be
connected to gateway for long distance transfer.}
Slower then Ethernet. {100 Gbps Ethernet}
USB is simple Master/Slaves Tree topology. {Other then host
can not initiate transfer}
D+ and D- signals carries data of same information with mirror Host can not broadcast data to all the slaves.
image. Multiple Host not possible.
At receiver side we have deferential amplifier which gives If USB slave is virus prone then it may be dangerous to host.
difference of D+ & D-. That difference will be our data.
RS 232 Protocol
Basics of RS 232 Protocol Pin Details of DB9 and DB25 connector
RS 232 protocol is used for serial communication.
RS 232 protocol provides Asynchronous full duplex
a
communication. {Without Clock}
d
RS 232 protocol can handle serial communication with the
n
distance of 50ft, depending on cable type and bit rate.
u
RS 232 protocol can handle maximum data rate of 1Mbps.
F
As we increase the length of cable, capacitance will also increase Pin-D9 Pin-D25 Signal Source Type Description
g
which will limits the data rate.
in
Some special cables are also available, by which we can have 1 8 CD DCE Control Carrier Detect
r
communication up to 130fts. 2 3 RX DCE Data Receive Data
e
RS 232 protocol uses DB9 or DB25 connector for serial
e
communication. 3 2 TX DTE Data Transmit Data
DB9.
g i n
In DB25 connector, only Nine lines are used as it is there with 4 20 DTR DTE Control Data Terminal
Ready
n
Connectors of RS 232 Protocol 5 7 SG - - Signal Ground
E 6
7
6
4
DSR
RTS
DCE
DTE
Control
Control
Data Set Ready
Request to Send
- Rest None - - -
RS 232 Protocol
DTE and DCE of RS 232 Protocol Voltages of RS 232 Protocol
DTE – Data Terminal Equipment. {Computer}
DCE – Data Communication Equipment. {Modem} 15V Logic 0 15V
a
Communication happens between DTE and DCE, we can not have
d
communication between two DTE or two DCE. 5V
n
For two DTE communication, we use Null modem in between 3V
Tx Side
u 0 Voltage Rx Side
two DTE for communication.
F
In Null Modem, we just need to configure Rx, Tx and SG lines of
g
DB9 or DB25 connector. -3V
-5V
RS232
g
RTS of DTE is connected with CTS of DCE and visa versa.
n
DSR of DTE is connected with DTR of DCE and visa versa.
DCE
E
DTE Tx of DTE is connected with Rx of DCE and visa versa.
SG of DTE and DCE is commonly connected.
1st DTE is giving RTS {Request to Send} Signal to DCE.
If DCE is not busy then only DCE sends respond on DTR {Data
RS232 Null RS232 Transmit Ready}
Modem Then DTE can send data to DCE.
Similarly DCE can also initiate data transmission.
DTE DTE
RS 232 Protocol
Data Frame Format of RS 232 Protocol RS 232 Protocol in Embedded System
Data Frame Format of RS 232 Protocol is similar to UART. Majority of embedded system work with voltage range of 0 to 5V
and RS 232 works with ±15V.
a
Start Data {8 bits} Parity Stop To make data transfer compactible, we need to use MAX 232 IC
d
bit = 0 Bit Bit = 1 with embedded system to enable RS 232 Protocol.
n
MAX 232 converts voltage range of (0-5V) into ±25V and visa
u
In one frame of RS 232 Protocol, along with 8 bits of data, start
versa.
F
bit, stop bit and parity redundancy is also added.
Parity bit is optional but it can be used to identify the error in NOTE: MAX 232 will also limit the data transfer speed of RS 232
g
data reception. Protocol.
r i n
e e
g in
E n 0 to 5 Voltage ±30 Voltage