Serial
Communication
Mohamad Abd Elhay

Copyright © 2012 Embedded Systems
Committee
Serial Communication:
is the process of sending data one bit at a time,
sequentially, over a communication channel or
computer bus.

Parallel Communication:
where several bits are sent as a whole, on a link with
several parallel channels.
Copyright © 2012 Embedded Systems
Committee
serial connection requires fewer interconnecting
cables and hence occupies less space.
 the cost of cable and synchronization difficulties
make parallel communication impractical.

Copyright © 2012 Embedded Systems
Committee
• For serial communications to be accomplished
there must be a transmitter (TX), and a
receiver (RX).
• The TX is responsible for taking a byte (or
several bits of data) in parallel, and convert
them to a series of successive bits.
• The RX on the other side, collects the
successive bits to reform the data once again.

Copyright © 2012 Embedded Systems
Committee
A Serial Line.(HIGH=RED & LOW=WHITE)

Copyright © 2012 Embedded Systems
Committee
1-Simplex:
one way communication where all signals can flow in only
one direction.
Example Radio & TX.

2- half-duplex system
It provides for communication in both directions, but only one
direction at a time (not simultaneously).
Example walkie-talkie.

3-Full-duplex
allows communication in both directions.
Example Telephone.
Copyright © 2012 Embedded Systems
Committee
synchronous communication
Is transmission of data with the use of an external
clock signal.

Example:
Serial Peripheral Interface (SPI).

Inter-Integrated Circuit (I2C).
Copyright © 2012 Embedded Systems
Committee
Asynchronous communication
Is transmission of data without the use of an external
clock signal.

Example:
Universal asynchronous receiver/transmitter (UART).

Copyright © 2012 Embedded Systems
Committee
Serial Communication In Embedded Systems:
We use serial communication (UART-SPI-I2C) to interface
microcontroller with different devices such as :
1-Computer.
2-LCD.
3-EEROM.
4-Ultrasonic.
Also, serial communication used in embedded systems
networks such as:
1- Controller Area Networks (CAN)
2- Local Interconnect Networks (LIN)
Copyright © 2012 Embedded Systems
Committee
• Bit time:
– The time taken to transmit a bit/sec.
• Bit rate:
– The number of bits transmitted per second.
– Bit rate = 1 / Bit time.
• Baud Rate:
– The number of symbols signaled in a second.
– Baud rate = 1 symbol / sec.
• Symbol = bit or byte or number of bits or
bytes
Copyright © 2012 Embedded Systems
Committee
• When using a device has a set of 8 different
symbols.
• Each symbol represents 3 bits of useful data.
• If it transmits 300 bits per second, it gathers
each 3 bits in 1 symbol.
• So it transmits 100 symbol per second
– 300 bit per second (bit rate)
– 100 baud (baud rate)
Copyright © 2012 Embedded Systems
Committee
Copyright © 2012 Embedded Systems
Committee
 It also called Serial Communication Interface(SCI)
 full-duplex communication.
 Asynchronous communication.
 Compatible with PC .

 The Standard bit rates are:
100, 200, 300, 1200, 2400, 4800, 9600, 19200,

38400, 57600, 115200 bps.
Copyright © 2012 Embedded Systems
Committee
Copyright © 2012 Embedded Systems
Committee
• Frame : A frame is the unit of transmission in serial
communications.
• A frame contains:
– Start bit: To declare the start of transmission.
– Data bits: 4,5,6,7, or 8 bits of useful data bits.
– Parity bit : To check for transmission errors.
– Stop bit: To declare end of frame.

• Parity bit is used to check the integrity of a frame
and signal if an error occurred during
transmission.
Copyright © 2012 Embedded Systems
Committee
• Parity :
– Parity bit is an extra bit added to the end of a
frame.

• Even parity :
– The number of ‘1’ symbols inside a frame must
always be even.

• Odd parity :
– The number of ‘1’ symbols inside a frame must
always be odd.

Copyright © 2012 Embedded Systems
Committee
Frame structure:

Copyright © 2012 Embedded Systems
Committee
RS232 Data Interface
 PC serial interface.
 SPACE (0) will be between +3 to +15 volts.

 MARK (1) will be between -3 and -15 volts.

Copyright © 2012 Embedded Systems
Committee
Microcontroller O/P voltages:
o0 v for logic 0.
o5v for logic 1.
MAX232
Is an IC that converts signals
from an RS-232 serial port to
signals suitable for use in TTL
compatible digital logic circuits
Copyright © 2012 Embedded Systems
Committee
Copyright © 2012 Embedded Systems
Committee
Hyper Terminal from Start > Programs > Accessories >
Communications

Copyright © 2012 Embedded Systems
Committee
UCSRA: USART Control and Status Register A
Bit No
7
Name RXC

6
5
TXC UDRE

4
FE

3
DOR

2
PE

1
0
U2X MPCM

RXC this bit is set when the USART has completed receiving a byte
from the host
UDRE this bit set when UDR emty.
UCSRB: USART Control and Status Register B
Bit No
7
6
5
4
3
2
1
0
Name RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8

RXCIE: Receive Complete Interrupt Enable
TXCIE: Transmit Complete Interrupt Enable
RXEN: Receiver Enable
TXEN: Transmitter Enable
UCSZ2: USART Character Copyright © 2012 Embedded Systems
Size
Committee
UCSRC: USART Control And Status Register C
Bit No
7
6
5
Name URSEL UMSEL UPM1

4
UPM0

3
2
1
USBS UCSZ1 UCSZ0

0

URSEL: USART register select.
The UCSRC and the UBRRH register shares same address so to determine which register user
want to write is decided with the 7th(last) bit of data if its 1 then the data is written to UCSRC
else it goes to UBRRH.

USART Mode Select
USBS
0
1

Stop Bit(s)
1 BIT
2 BIT

USBS: USART Stop Bit Select
UMSEL
0
1

Mode
Asynchronous
Synchronous

UCSZ2
0
0
0

UCSZ1
0
0
1

UCSZ0
0
1
0

Character Size
5Bit
6Bit
7Bit

0

1

1

8Bit

1
1
1
1

0
0
1
1

0
1
0
1

Reserved
Reserved
Reserved
9Bit

Copyright © 2012 Embedded Systems
Committee
UDR: Data Register
UBRR: USART Baud Rate Register:

Copyright © 2012 Embedded Systems
Committee
void MCL_UART_Init(void)
void MCL_UART_SendByte(unsigned char byte)
void MCL_UART_StartSendArray(unsigned char length, unsigned char * array)
void MCL_UART_StartReceving(void)
void MCL_UART_GetReceivedData(unsigned char length, unsigned char * arr_rx)
int Compare (unsigned char * arr_rx,unsigned char length)
//equal=1 //not equal=0

Copyright © 2012 Embedded Systems
Committee
References

• ESC Training Team

Copyright © 2012 Embedded Systems
Committee
info@escommittee.net

Copyright © 2012 Embedded Systems
Committee

Uart

  • 1.
    Serial Communication Mohamad Abd Elhay Copyright© 2012 Embedded Systems Committee
  • 2.
    Serial Communication: is theprocess of sending data one bit at a time, sequentially, over a communication channel or computer bus. Parallel Communication: where several bits are sent as a whole, on a link with several parallel channels. Copyright © 2012 Embedded Systems Committee
  • 3.
    serial connection requiresfewer interconnecting cables and hence occupies less space.  the cost of cable and synchronization difficulties make parallel communication impractical. Copyright © 2012 Embedded Systems Committee
  • 4.
    • For serialcommunications to be accomplished there must be a transmitter (TX), and a receiver (RX). • The TX is responsible for taking a byte (or several bits of data) in parallel, and convert them to a series of successive bits. • The RX on the other side, collects the successive bits to reform the data once again. Copyright © 2012 Embedded Systems Committee
  • 5.
    A Serial Line.(HIGH=RED& LOW=WHITE) Copyright © 2012 Embedded Systems Committee
  • 6.
    1-Simplex: one way communicationwhere all signals can flow in only one direction. Example Radio & TX. 2- half-duplex system It provides for communication in both directions, but only one direction at a time (not simultaneously). Example walkie-talkie. 3-Full-duplex allows communication in both directions. Example Telephone. Copyright © 2012 Embedded Systems Committee
  • 7.
    synchronous communication Is transmissionof data with the use of an external clock signal. Example: Serial Peripheral Interface (SPI).  Inter-Integrated Circuit (I2C). Copyright © 2012 Embedded Systems Committee
  • 8.
    Asynchronous communication Is transmissionof data without the use of an external clock signal. Example: Universal asynchronous receiver/transmitter (UART). Copyright © 2012 Embedded Systems Committee
  • 9.
    Serial Communication InEmbedded Systems: We use serial communication (UART-SPI-I2C) to interface microcontroller with different devices such as : 1-Computer. 2-LCD. 3-EEROM. 4-Ultrasonic. Also, serial communication used in embedded systems networks such as: 1- Controller Area Networks (CAN) 2- Local Interconnect Networks (LIN) Copyright © 2012 Embedded Systems Committee
  • 10.
    • Bit time: –The time taken to transmit a bit/sec. • Bit rate: – The number of bits transmitted per second. – Bit rate = 1 / Bit time. • Baud Rate: – The number of symbols signaled in a second. – Baud rate = 1 symbol / sec. • Symbol = bit or byte or number of bits or bytes Copyright © 2012 Embedded Systems Committee
  • 11.
    • When usinga device has a set of 8 different symbols. • Each symbol represents 3 bits of useful data. • If it transmits 300 bits per second, it gathers each 3 bits in 1 symbol. • So it transmits 100 symbol per second – 300 bit per second (bit rate) – 100 baud (baud rate) Copyright © 2012 Embedded Systems Committee
  • 12.
    Copyright © 2012Embedded Systems Committee
  • 13.
     It alsocalled Serial Communication Interface(SCI)  full-duplex communication.  Asynchronous communication.  Compatible with PC .  The Standard bit rates are: 100, 200, 300, 1200, 2400, 4800, 9600, 19200, 38400, 57600, 115200 bps. Copyright © 2012 Embedded Systems Committee
  • 14.
    Copyright © 2012Embedded Systems Committee
  • 15.
    • Frame :A frame is the unit of transmission in serial communications. • A frame contains: – Start bit: To declare the start of transmission. – Data bits: 4,5,6,7, or 8 bits of useful data bits. – Parity bit : To check for transmission errors. – Stop bit: To declare end of frame. • Parity bit is used to check the integrity of a frame and signal if an error occurred during transmission. Copyright © 2012 Embedded Systems Committee
  • 16.
    • Parity : –Parity bit is an extra bit added to the end of a frame. • Even parity : – The number of ‘1’ symbols inside a frame must always be even. • Odd parity : – The number of ‘1’ symbols inside a frame must always be odd. Copyright © 2012 Embedded Systems Committee
  • 17.
    Frame structure: Copyright ©2012 Embedded Systems Committee
  • 18.
    RS232 Data Interface PC serial interface.  SPACE (0) will be between +3 to +15 volts.  MARK (1) will be between -3 and -15 volts. Copyright © 2012 Embedded Systems Committee
  • 19.
    Microcontroller O/P voltages: o0v for logic 0. o5v for logic 1. MAX232 Is an IC that converts signals from an RS-232 serial port to signals suitable for use in TTL compatible digital logic circuits Copyright © 2012 Embedded Systems Committee
  • 20.
    Copyright © 2012Embedded Systems Committee
  • 21.
    Hyper Terminal fromStart > Programs > Accessories > Communications Copyright © 2012 Embedded Systems Committee
  • 22.
    UCSRA: USART Controland Status Register A Bit No 7 Name RXC 6 5 TXC UDRE 4 FE 3 DOR 2 PE 1 0 U2X MPCM RXC this bit is set when the USART has completed receiving a byte from the host UDRE this bit set when UDR emty. UCSRB: USART Control and Status Register B Bit No 7 6 5 4 3 2 1 0 Name RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8 RXCIE: Receive Complete Interrupt Enable TXCIE: Transmit Complete Interrupt Enable RXEN: Receiver Enable TXEN: Transmitter Enable UCSZ2: USART Character Copyright © 2012 Embedded Systems Size Committee
  • 23.
    UCSRC: USART ControlAnd Status Register C Bit No 7 6 5 Name URSEL UMSEL UPM1 4 UPM0 3 2 1 USBS UCSZ1 UCSZ0 0 URSEL: USART register select. The UCSRC and the UBRRH register shares same address so to determine which register user want to write is decided with the 7th(last) bit of data if its 1 then the data is written to UCSRC else it goes to UBRRH. USART Mode Select USBS 0 1 Stop Bit(s) 1 BIT 2 BIT USBS: USART Stop Bit Select UMSEL 0 1 Mode Asynchronous Synchronous UCSZ2 0 0 0 UCSZ1 0 0 1 UCSZ0 0 1 0 Character Size 5Bit 6Bit 7Bit 0 1 1 8Bit 1 1 1 1 0 0 1 1 0 1 0 1 Reserved Reserved Reserved 9Bit Copyright © 2012 Embedded Systems Committee
  • 24.
    UDR: Data Register UBRR:USART Baud Rate Register: Copyright © 2012 Embedded Systems Committee
  • 25.
    void MCL_UART_Init(void) void MCL_UART_SendByte(unsignedchar byte) void MCL_UART_StartSendArray(unsigned char length, unsigned char * array) void MCL_UART_StartReceving(void) void MCL_UART_GetReceivedData(unsigned char length, unsigned char * arr_rx) int Compare (unsigned char * arr_rx,unsigned char length) //equal=1 //not equal=0 Copyright © 2012 Embedded Systems Committee
  • 26.
    References • ESC TrainingTeam Copyright © 2012 Embedded Systems Committee
  • 27.
    info@escommittee.net Copyright © 2012Embedded Systems Committee