Вы находитесь на странице: 1из 28

8051 Microcontroller:

Serial Communication
Virendra Singh
Associate Professor
Computer Architecture and Dependable Systems Lab
Department of Electrical Engineering
Indian Institute of Technology Bombay
http://www.ee.iitb.ac.in/~viren/
E-mail: viren@ee.iitb.ac.in

EE-309: Microprocessors

Lecture 13 (18 Aug 2014)

CADSL

8051
Pin
Diagram

P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
P1.6
P1.7
RST
(RXD)P3.0
(TXD)P3.1
(INT0)P3.2
(INT1)P3.3
(T0)P3.4
(T1)P3.5
(WR)P3.6
(RD)P3.7
XTAL2
XTAL1
GND

19 Aug 2014

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

EE-309@IITB

8051
(8031)
(8751)
(8951)

40
39
38
37
36
35
34
33
32
31
30
29
28
27
26
25
24
23
22
21

Vcc
P0.0(AD0
)P0.1(AD1)
P0.2(AD2
)P0.3(AD3)
P0.4(AD4)
P0.5(AD5)
P0.6(AD6)
P0.7(AD7)
EA/VPP
ALE/PROG
PSEN
P2.7(A15)
P2.6(A14
)P2.5(A13
)P2.4(A12
)P2.3(A11)
P2.2(A10)
P2.1(A9)
P2.0(A8)

CADSL

Data
Communication
19 Aug 2014

EE-309@IITB

CADSL

8051 and PC
The 8051 module connects to PC by using RS232.
RS232 is a protocol which supports half-duplex,
synchronous/asynchronous, serial communicaLon.
We discuss these terms in following secLons.
RS232
PC

COM 1 port

19 Aug 2014

8051

MAX232

EE-309@IITB

UART

CADSL

Parallel vs. Serial Data Transfer


Computers transfer data in two ways:
Parallel
data is sent a byte or more a Lme (fast)
Only short distance between two systems
The 8-bit data path is expensive
Example: printer, hard disks

Serial
The data is sent one bit at a Lme (slow)
Long distance (rarely distorLon)
cheap
The data can be transferred on the telephone line (by using modem.)
19 Aug 2014

EE-309@IITB

CADSL

Serial vs Parallel Data Transfer

Parallel Transfer

Serial Transfer
Sender

Receiver

Sender

D0

Receiver

D7

19 Aug 2014

EE-309@IITB

CADSL

Serial vs. Parallel Data Transfer

Parallel Transfer

Serial Transfer
D0
Sender

D0-D7
Receiver

Sender

Receiver

Other control lines

Other control lines

19 Aug 2014

EE-309@IITB

CADSL

Serial
Communication
19 Aug 2014

EE-309@IITB

CADSL

Serial Communication
How to transfer data?
Sender:
The byte of data must be converted to serial bits using a
parallel-in-serial-out shiV register.
The bit is transmiWed over a single data line.

Receiver
The receiver must be a serial-in-parallel-out shiV register
to receive the serial data and pack them into a byte.
8

register

11101000001011
1

parallel-in serialout
19 Aug 2014

EE-309@IITB

register
8-bit character
serial-in parallelout
9

CADSL

Asynchronous Serial Communication


With asynchronous communicaLon, the transmiWer and
receiver do not share a common clock
Remove: Start, Stop, Parity Bits

Add: Start, Stop, Parity Bits

Transmitter

Receiver

Data

1 byte-wide Data

1 byte-wide Data

The Transmitter
Shifts the parallel data onto
the serial line using its own
clock
Also adds the start, stop and
parity check bits
19 Aug 2014

The Receiver
Extracts the data using its own
clock
Converts the serial data back to
the parallel form after stripping off
the start, stop and parity bits
EE-309@IITB

10

CADSL

Synchronous Serial Communication


In the synchronous mode, the transmiWer and receiver share a common clock
The transmiWer typically provides the clock as a separate signal in addiLon to
the serial data
Clock

Receiver

Transmitter
Data

1 byte-wide Data

1 byte-wide Data

The Transmitter
Shifts the data onto the serial
line using its own clock

The Receiver
Extracts the data using the
clock provided by the
transmitter

Provides the clock as a separate


signal
Converts the serial data
back to the parallel form
No start, stop, or parity bits
added to data
19 Aug 2014

EE-309@IITB

11

CADSL

Asynchronous vs. Synchronous


Serial communicaLon uses two methods:
In synchronous communicaLon, data is sent in
blocks of bytes.
byte

byte

byte

byte

0101111101010101

preamble

sender

receiver

In asynchronous communicaLon, data is sent in


bytes.
byte
sender

19 Aug 2014

byte

byte
stop bit

EE-309@IITB

receiver

start bit
12

CADSL

UART and USART


It is possible to write soVware to use both
methods, but the programs can be tedious
and long.
Special IC chips are made for serial
communicaLon:
USART (universal synchronous-asynchronous
receiver-transmiWer)
UART (universal asynchronous receiver-
transmiWer)

The 8051 chip has a built-in UART.


19 Aug 2014

EE-309@IITB

13

CADSL

UART Block Diagram

19 Aug 2014

EE-309@IITB

14

CADSL

8051 Serial Communication


The 8051 has serial communicaLon capability
built into it.

How to detect that a character is sent via the


line in the asynchronous mode?
Answer: Data framing!

19 Aug 2014

EE-309@IITB

15

CADSL

Framing
Framing: Each character is placed in between
start and stop bits
Framing ASCII A (41H)
Time (D0 first)

mark

goes out last

stop
bit

D7

start
mark
bit

D0
goes out first

19 Aug 2014

EE-309@IITB

16

CADSL

Framing
We have a total of 10 bits for each character:
8-bits for the ASCII code
2-bits for the start and stop bits
25% overhead

In some systems in order to maintain data integrity,


the parity bit is included in the data frame.
In an odd-parity bit system the total number of bits,
including the parity bit, is odd.
UART chips allow programming of the parity bit for
odd-, even-, and no-parity opLons.
19 Aug 2014

EE-309@IITB

17

CADSL

Data Transfer Rate


How fast is the data transferred?
Three methods to describe the speed:
Baud rate is dened as the number of signal changes per sec.
The rate of data transfer is stated in Hz (used in modem).
Date rate is dened as the number of bits transferred per sec.
Each signal has several voltage levels.
The rate of data transfer is stated in bps (bits per second).
EecLve data rate is dened as the number of actual data bits
transferred per second.
Redundant bits must be removed

19 Aug 2014

EE-309@IITB

18

CADSL

Data Transfer Rate


The data transfer rate depends on
communicaLon ports incorporated into that
system.
Ex: 100-9600 bps in the early IBM PC/XT
Ex: 56 kbps in PenLum-based PC
The baud rate is generally limited to 100kHz.

19 Aug 2014

EE-309@IITB

19

CADSL

Example of Data Transfer Rate


Data is sent in the following asynchronous mode:
2400 baud rate
each signal has 4 voltage levels (-5V, -3V, 3V, 5V)
one start bit, 8-bit data, 2 stop bits
Time (D0 first)

stop stop
mark
bit bit

00

11

10

01

10

00

11

11

start
mark
bit

8-bit character
19 Aug 2014

EE-309@IITB

20

CADSL

Example of Data Transfer Rate


2400 baud = 2400 signals per second =2400 Hz
4 voltage level: Log24=2
2 bits is sent in every signal change

Data rate = 2 * 2400 Hz = 4800 bps


EecLve raLo = 8 / (1+8+2) =8/11
EecLve data rate = data rate * eecLve raLo
= 4800 * 8 /11=3490.9

19 Aug 2014

EE-309@IITB

21

CADSL

RS232 Standard
RS232 is an interfacing standard which is set
by the Electronics Industries AssociaLon (EIA)
in 1960.
RS232 is the most widely used serial I/O
interfacing standard.
RS232A (1963), RS232B (1965) and RS232C (1969),
now is RS232E

Dene the voltage level, pin funcLonality,


baud rate, signal meaning, communicaLon
distance.
19 Aug 2014

EE-309@IITB

22

CADSL

RS232 Voltage Level


The input and output voltage of
RS232 is not of the TTL
compaLble.
RS232 is older than TTL.

We must use voltage converter


(also referred to as line driver)
such as MAX232 to convert the
TTL logic levels to the RS232
voltage level, and vice versa.
MAX232, TSC232, ICL232
19 Aug 2014

EE-309@IITB

RS 232 Voltage

25V
logic 0
3V
-3V

undefined
logic 1

-25V
23

CADSL

MAX232
MAX232 IC chips are commonly referred to
as line drivers.
RS232
PC

COM 1 port

TTL voltage
level

19 Aug 2014

8051

MAX232

RS232 voltage
level

EE-309@IITB

UART
TTL voltage
level

24

CADSL

RS232 Pins for DTE


1

13

14

25

19 Aug 2014

Pin
1
2
3
4
5
6
7
8
9/10
11
12
13

Descrip0on
ProtecLve ground
TransmiWed data (TxD)
Received data (RxD)
Request to send (RTS)
Clear to send (CTS)
Data set ready (DSR)
Signal ground (GND)
Data carrier detect (DCD)
Reserved for data tesLng
Unassigned
Secondary data carrier detect
Secondary clear to send

EE-309@IITB

25

CADSL

RS232 Pins for DTE


1

13

14

25

19 Aug 2014

Pin
14
15
16

Descrip0on
Secondary transmiWed data
Transmit signal element Lming
Secondary received data

17
18
19
20
21
22
23
24
25

Receive signal element Lming


Unassigned
Secondary request to sent
Data terminal ready (DTR)
Signal quality detector
Ring indicator
Data signal rate select
Transmit signal element Lming
Unassigned

EE-309@IITB

26

CADSL

RS232 Handshaking Signals


Many of the pins of the RS232 connector are
used for handshaking signals.
DTR (data terminal ready)
DSR (data set ready)
RTS (request to send)
CTS (clear to send)
RTS and CTS are hardware control ow signals.
DCD (carrier detect, or data carrier detect)
RI (ring indicator)

They are not supported by the 8051 UART chips.


19 Aug 2014

EE-309@IITB

27

CADSL

Thank You
19 Aug 2014

EE-309@IITB

28

CADSL

Вам также может понравиться