You are on page 1of 22

Lecture7

Serial Communication Protocols

USB CAN I2C


I2S LIN SPI
Ethernet 1-Wire UART/USART

C++ Programming: From Problem Analysis to Program Design, Fourth Edition 2


UART Protocol
Universal Asynchronous Receiver/Transmitter
There is a couple of io pins dedicated to the UART serial
communication module highlighted in the following figure.
Namely, RX (data input – receiving end) & TX (data output
– transmitting end).
UART is sold/shipped as a standalone integrated circuit
(IC) or as an internal module within microcontrollers.

There are actually two forms of UART as follows:


UART – Universal Asynchronous Receiver/Transmitter
USART – Universal Synchronous/Asynchronous
Receiver/Transmitter
3
UART vs USART
UART USART
Standalone Communication It can support multiple protocols
Protocol like LIN, RS-485, IrDA, etc
Commonly used for low-speed More suitable for high-speed
applications applications
The data rate is relatively low The data rate is much higher
The clock is generated locally and The clock signal is generated by
both devices are configured to run the transmitter and sent to the
at the same baud rate receiver during data transmission
The baud rate is useless as the
The baud rate of the receiver
receiver module will be using the
module must be known prior to
clock coming from the transmitter
any communication
device
Offer reduced low energy Operates at high energy
consumption mode
C++ Programming: From Problem Analysis to Program Design, consumption
Fourth Edition modes 4
Modes Of Operation For UART
Devices
The UART serial communication bus can only have 2
devices communicating with each other in one of the 3
modes
Simplex – One direction only, a transmitter to a receiver
Half Duplex – Devices take turns transmitting and receiving
Full Duplex – Devices can send and receive simultaneously (at the same
time)

5
UART Data Packet
The data being transmitted/received in UART serial
communication is organized into specific blocks called Packets
In the idle state, UART lines are pulled high. This allows the
receiver side to recognize that there is a transmitter device on
the other end which is connected to the serial bus.

6
UART Data Packet
• Start Bit:
- To start data transfer, the transmitting UART
pulls-down the transmission line from high to
low for one clock cycle.
- When the receiving UART module detects the
high to low voltage transition, it begins
reading the incoming bits of the entire data
frame at the same frequency of the specified
baud rate.

7
UART Data Packet
• Data Frame:
- These are the actual data bits being transmitted
from transmitter to receiver. The length of the
data frame can be anywhere between 5 and 9
(9-Bits if parity is not used and 8-Bits if parity is
used).

8
UART Data Packet
• Parity Bit:
- Parity bit allows the receiver to check the
correctness of the received data.
- Parity is a low–level error checking mechanism
and has two different options to choose from:
Even Parity and Odd Parity.
Even parity: The parity bit is a 0, the number of bits
with a value of 1 in the data frame should sum-up to
an even number.
Odd parity: The parity bit is a 1, the number of bits
with a value of 1 in the data frame should sum-up to
9
an odd number.
UART Data Packet

• Stop Bit :
- This bit is used to signal the end of the data packet
being sent.
- The sending UART drives the data transmission
line from low to high for at least two-bit durations
but most often only one bit is used.
- The data line is held high back to the idle state and
ready for any future transmission.

10
Baud Rate
• The Baud Rate specifies how fast the data is sent
over the bus and it is specified in bits-per-second
or bps.
• You can actually choose any speed for the baud
rate. However, there are some specific values that
are known to be the industry standards.
• standard baud rates include:1200, 2400, 4800,
9600,19200, 38400, 57600 and 115200.
• For a baud rate of 2400 (2400 bps) the frequency
is 2400Hz and the bit period is 1/2400 or 416.6us.
11
Baud Rate
• Baud Rate Mismatching
• The maximum allowable shift in baud rates tends
to be between (1-2%). So try to generate the exact
same baud rate at both ends to avoid mismatching
error.

12
Physical Layer Standards

• There are many different standards that


utilize the same UART protocol previously
described. Such as:
- TTL level UART
- RS-232,
- RS-422
- RS-485

13
TTL-Level UART
The majority of microcontroller chips with UART serial
communication modules do use TTL (Transistor-transistor
Logic) level UART.

Logic Level Logic-1 (High) Logic-0 (Low)


Voltage 5v 0v

14
RS-232 UART
RS-232 (Recommended Standard 232) is a standard for serial
binary data signals connecting between a Data Terminal
Equipment (DTE) and a Data Communication Equipment (DCE)
Logic Level Logic-1 (High) Logic-0 (Low)
Voltage +3 to +15v -3 to -15v

15
RS-232 UART

16
UART Bus Length VS Baud
Rate

17
PC Interfacing With Microcontroller
(PC-MCU interface)
1. TTL-UART to RS-232 Serial

2. TTL-UART to RS-232 Serial to USB

3. USB TTL Converter Module

18
Max 232 Pin Diagram and
Circuit Diagram

19
Features of Max232 IC
• Input supply voltage of 5V.
• Input voltage levels compatible with TTL
standard.
• Output voltage levels compatible with RS 232
standard.
• Low input current of 0.1microAmpere and
output current of 24mA.
• It operates in a temperature range of -40
degree Celsius to +85 degree Celsius

20
Advantages Of UART Serial
Communication
• Only two wires are required for a full-duplex data
transmission (excluding the power lines).
• The structure of the data packet can be
changed with coordination between both ends.
• No need for a serial clock signal (in asynchronous
mode).
• Parity bit provides a hardware-level error
detection.
• Well-documented and widely-used protocol.
• Relatively easy to set-up and run.
21
Disadvantages Of UART Serial
Communication
• Speed for data transfer is less compared to
parallel communication or even USARTs.
• The baud rates of each UART must be the
same in both sides.
• The size of the data frame is limited to a
maximum value of 9-Bits.
• Doesn’t support multiple slaves or multiple
masters capability.

C++ Programming: From Problem Analysis to Program Design, Fourth Edition 22

You might also like