0% found this document useful (0 votes)
5 views36 pages

Understanding Serial Communication Basics

Uploaded by

POOJA DHAKANE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views36 pages

Understanding Serial Communication Basics

Uploaded by

POOJA DHAKANE
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

What is Serial Communication

• In serial communication, data is in the form of binary pulses.

• In other words, we can say Binary One represents a logic HIGH or 5 Volts, and zero represents a

logic LOW or 0 Volts.

• Serial communication can take many forms depending on the type of transmission mode and

data transfer.

• The transmission modes are classified as Simplex, Half Duplex, and Full Duplex. There will be a

source (also known as a sender) and destination (also called a receiver) for each transmission

mode.
Serial communication with Universal Asynchronous Receive Transmit (UART) protocol
• Synchronous Serial Interface:
• It is a point-to-point connection from a master to slave. In
this type of interface, all the devices use single CPU bus to
share data and clock.

• The data transmission becomes faster with same bus to share


clock and data. Also there is no mismatch in baud rate in this
interface. In transmitter side, there is a shift of the data onto
serial line providing the clock as a separate signal as there is no
start, stop and parity bits are added to data.

• In receiver side, the data is being extract using the clock


provided by the transmitter and converts the serial data back to
the parallel form. The well-known examples are I2C and SPI.
1 What is Baud rate?

Baud rate is the speed of


transferring data from the
transmitter to a receiver in the
form of bits per second. Some of
the standard baud rates are 1200,
2400, 4800, 9600, 57600.

You have to set the same baud


rate on both sides (Mobile and
Laptop).

Note: The Higher a baud rate, more


data can be transferred in less
amount of time.
•In case of even parity − If number of 1s is even, parity
bit value is 0. If number of 1s is odd, parity bit value is 1.

•In case of odd parity − If number of 1s is odd, parity bit


value is 0. If number of 1s is even, parity bit value is 1.
SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Bit 2 - RB8: 9th Receive Bit


This is the 9th received bit in mode 2 & 3 (9-bit mode), whereas in mode 1 if SM2 = 0
then RB8 hold the stop bit that received
Bit 1 - TI: Transmit Interrupt Flag
This bit indicates the transmission is complete and gets set after transmitting the byte
from the buffer. Normally TI (Transmit Interrupt Flag) is set by hardware at the end of
the 8th bit in mode 0 and at the beginning of stop bit in other modes.
Bit 0 – RI: Receive Interrupt Flag
This bit indicates reception is complete and gets set after receiving the complete byte in
the buffer. Normally RI (Receive Interrupt Flag) is set by hardware in receiving mode at
the end of the 8th bit in mode 0 and at the stop bit receive time in other modes.
SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Mod Bit 5 - SM2: for Multiprocessor Communication


SM0 SM1 Mode
e
1/12 of Osc frequency shift register mode This bit enables a multiprocessor communication feature in mode 2 &
0 0 0 3.
fixed baud rate
8-bit UART with timer 1 determined baud Bit 4 - REN: Receive Enable
1 0 1
rate
9-bit UART with 1/32 of Osc fixed baud 1 = Receive enable
2 1 0
rate 0 = Receive disable
9-bit UART with timer 1 determined baud
3 1 1 Bit 3 - TB8: 9th Transmit Bit
rate
This is the 9th bit which is to be transmitted in mode 2 & 3 (9-bit mode)
Normally mode-1 (SM0 =0, SM1=1) is used with 8 data bits, 1
start bit, and 1 stop bit.
Microcontrolle Microcontrolle
r r

S SBUF SBUF S
B B
U U
F F
Transmitter Receiver
TXD RXD

SBUF SBUF
Shift Register Shift Register
(write only) (Read only)

Internal 8 bit data bus

S SBUF SBUF S
B B
U U
F F

Transmitter Receiver
8051 Pin Diagram
P1.0 1 40 Vcc
P1.1 2 39 P0.0(AD0)

PORT1 P1.2
P1.3
3
4
38
37
P0.1(AD1)
P0.2(AD2)
PORT0
P1.4 5 36 P0.3(AD3)
Pin 1 to 8 P1.5
P1.6
6
7
35
34
P0.4(AD4)
P0.5(AD5) Pin 39 to 32
P1.7 8 33 P0.6(AD6)
RST 9 32 P0.7(AD7)
(RXD)P3.0
8051
10 31 EA/VPP
(TXD)P3.1 11 (8031) 30 ALE/PROG

PORT3 (INT0)P3.2
(INT1)P3.3
12
13
29
28
PSEN
P2.7(A15)
(T0)P3.4 14 27 P2.6(A14)
Pin 10 to 17 (T1)P3.5
(WR)P3.6
15
16
26
25
P2.5(A13)
P2.4(A12)
PORT2
(RD)P3.7 17 24 P2.3(A11)
XTAL2 18 23 P2.2(A10) Pin 21 to 28
XTAL1 19 22 P2.1(A9)
GND 20 21 P2.0(A8)
27
Reading and Writing

• After all that we went through to configure the port, reading and writing bytes
is easy. We simply read from and write to the SBUF register. For example:
• inByte = SBUF; // Read a character from the UART
• SBUF = outByte; // Write a character to the UART
• The register SBUF is used for both reading and writing bytes. Internally, there
are two separate registers. They are both represented as SBUF for the
convenience of the programmer.
SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Bit 2 - RB8: 9th Receive Bit


This is the 9th received bit in mode 2 & 3 (9-bit mode), whereas in mode 1 if SM2 = 0
then RB8 hold the stop bit that received
Bit 1 - TI: Transmit Interrupt Flag
This bit indicates the transmission is complete and gets set after transmitting the byte
from the buffer. Normally TI (Transmit Interrupt Flag) is set by hardware at the end of
the 8th bit in mode 0 and at the beginning of stop bit in other modes.
Bit 0 – RI: Receive Interrupt Flag
This bit indicates reception is complete and gets set after receiving the complete byte in
the buffer. Normally RI (Receive Interrupt Flag) is set by hardware in receiving mode at
the end of the 8th bit in mode 0 and at the stop bit receive time in other modes.
SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Mod Bit 5 - SM2: for Multiprocessor Communication


SM0 SM1 Mode
e
1/12 of Osc frequency shift register mode This bit enables a multiprocessor communication feature in mode 2 &
0 0 0 3.
fixed baud rate
8-bit UART with timer 1 determined baud Bit 4 - REN: Receive Enable
1 0 1
rate
9-bit UART with 1/32 of Osc fixed baud 1 = Receive enable
2 1 0
rate 0 = Receive disable
9-bit UART with timer 1 determined baud
3 1 1 Bit 3 - TB8: 9th Transmit Bit
rate
This is the 9th bit which is to be transmitted in mode 2 & 3 (9-bit mode)
Normally mode-1 (SM0 =0, SM1=1) is used with 8 data bits, 1
start bit, and 1 stop bit.
SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Mode SM0 SM1 Mode

0 0 0 1/12 of Osc frequency shift register mode fixed


baud rate
1 0 1 8-bit UART with timer 1 determined baud rate

2 1 0 9-bit UART with 1/32 of Osc fixed baud rate

3 1 1 9-bit UART with timer 1 determined baud rate


SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Bit 5 - SM2: for Multiprocessor Communication


This bit enables a multiprocessor communication feature in mode 2 & 3.
SCON: Serial Control Register
Serial control register SCON is used to set serial communication operation modes. Also it is used to control
transmit and receive operations.

Bit 5 - SM2: for Multiprocessor Communication


This bit enables a multiprocessor communication feature in mode 2 & 3.
Baud Rate = Oscillator frequency in HZ / N [256-(TH1)]

Clock frequency of timer clock: f = (11.0592 MHz / 12)/32 = 28,800Hz


Time period of each clock tick: T = 1/f = 1/28800
Duration of timer : n*T (n is the number of clock ticks)
Baud Rate TH1 (Hex)
9600 baud ->duration of 1 symbol: 1/9600
1/9600 = n*T0 = n*1/28800 9600 FD

n = f/9600 = 28800/9600 = 3 ->TH1 =-3 (256-3)=FD 4800 FA

n = f/4800 = 28800/4800 = 6 ->TH1 =-6 (256-6)=FA 2400 F4


n = f/2400 = 28800/2400 = 12 ->TH1 =-12 (256-12)=F4 1200 E8
n = f/1200 = 28800/1200 = 24 ->TH1 =-24 (256-24)=E8

You might also like