0% found this document useful (0 votes)
63 views44 pages

01 (Handout)

This document provides a 3-sentence summary of the key topics in the document "Microprocessor Theory and Applications": It discusses serial port programming for AVR microcontrollers and covers topics such as parallel vs. serial communication, synchronous vs. asynchronous communication, data transmission modes, data formatting, and baud rate vs. bit rate calculations. Special integrated circuits like UARTs and USARTs are used for asynchronous serial communication in applications like RS-232 between computers and external devices.

Uploaded by

snualpe
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)
63 views44 pages

01 (Handout)

This document provides a 3-sentence summary of the key topics in the document "Microprocessor Theory and Applications": It discusses serial port programming for AVR microcontrollers and covers topics such as parallel vs. serial communication, synchronous vs. asynchronous communication, data transmission modes, data formatting, and baud rate vs. bit rate calculations. Special integrated circuits like UARTs and USARTs are used for asynchronous serial communication in applications like RS-232 between computers and external devices.

Uploaded by

snualpe
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
You are on page 1/ 44

Microprocessor Theory and Applications

CHAPTER 11

AVR Serial Port Programming

Are adolwfaraowfnrowolniassnlrmnr,n&D8W9n4% awwww


ur

kowtow work
IWSI :

show :B bqitna internal


data bus
07mi

CPV Vma D bit or


register ( f- PR > → Ro -
est

aur D bit
Assoc.Prof. Dr.Yuttapong Rangsanseri
Ubm's
I/O

Dts
cnonivoowriv
{ ter
Cpu
ex '

cow
inv prog IDATA
.
"' VII )
port Timer

-71
trini:c:[
'

:c:c::
t DIA
Snow WIE ovolo
Parallel vs. Serial Communication
Group o's roup
tr d
Rx Tx

2 Microprocessor Theory and Applications


Parallel vs. Serial Communication (2)
Transmission
Parallel Serial
Characteristics
Transmission All bits in a single character One bit comes after another,
Description and transmit simultaneously one by one
Comparative Faster Slower. Latest techniques
Speed offer comparable rates,
⑦ironer hard
e.g. SATA, PCI Express
Distance Shorter 22451% , Farther disk
knowing war
Limitation h9hiinwrialn.no

Application Within a computer along Between two computers, from


computer buses, between computer to external devices,
drive controller to hard drive local and wide area network
Cable Description Each bit travel down its own All bits travel down in single
wire simultaneously with wire, one bit at one time
other bits
"
bitodrvvrosriao
{ Dun '
bit inundation
limo
.
,

logo
'
shoutout win 9mm's ions-

3 Microprocessor Theory and Applications


Synchronous vs Asynchronous
♦ Synchronous serial communication
The clocks of the sender and receiver are synchronized.
A block of characters, enclosed by synchronizing bytes,
is sent at a time. 's

riiidwsyncw moonyBoynton
Faster transfer and less overhead.
,

Example: Serial Peripheral Interface (SPI)


④ # IRI
W rrrrrr

♦ Asynchronous serial communication doggy


The clocks of the sender and receiver are not synchronized.
One character (8 or 7 bits) is sent at a time, enclosed between
a start bit and one or two stop bits. A parity bit may be included.
Example: RS-232

Special IC chips: UART, USART ④ -

V
10
AVR chip has a built-in USART I

4 Microprocessor Theory and Applications


Transmission Modes

lardon

5
① y Microprocessor Theory and Applications
Asynchronous Serial Communication
♦ With asynchronous communication, the transmitter and
receiver do not share a common clock
Add: Start, Stop, Parity Bits Remove: Start, Stop, Parity Bits

Transmitter + – Receiver
Data

1 byte-wide Data 1 byte-wide Data

The Transmitter The Receiver

♦ Shifts the parallel data ♦ Extracts the data using its


onto the serial line using own clock
its own clock
♦ Converts the serial data back to
♦ Also adds the start, stop the parallel form after stripping
and parity check bits off the start, stop and parity bits

6 Microprocessor Theory and Applications


Data Format
♦ Start bit – indicates the beginning of word
♦ Data bit – data user is transmitting
♦ Parity bit – checks integrity of data error detection
♦ Stop bit – indicates the end of word
lriwllalimwnen
R
Start Bit Parity Bit
DATA rimosmsn's O
1 orO
2 Stop Bits
l l U

O D0 D1 D2 D3 D4 D5 D6 D7
n ablution
GB w MSB

↳ 7ms
1 Asynchronous Byte

siuiisrishriuo's rioomnosriwinmuh bit = ?


ex 7- Ims
.

.
.

. Sampling rate Cfg ) : 7 kHz


7 Microprocessor Theory and Applications
Parity bit

coil ow vosiov 1
:

even parity .
a. of slums duo's Nonpolar serial

Baud & Bitrate 8 miso's bitrate mind 90 baud rate Irisher


& o's baud mine's nd
mm
♦ Baud rate is the number of line state changes
possible per second
$ 01 him
♦ Bit rate (bps) is the number of bits transmitted per
second

♦ Direct wired connection (without modulation) has two line


states (high/low), can be represented with one bit
1 baud = 1 bit → shinny baud rate bitrate
: . n =

♦ If a hardware can produce and recognize more than two


line states using voltage, frequency, or phase modulation
resulting in more bits per baud
bps = baud rate x number of bits per baud

8 Microprocessor Theory and Applications


#
5- V
T
-

l baud : i bit
or

't
wool

it ÷÷÷::.÷:
'
do
.

:*
#¥1111
ro

Ht T
y baud : 2 bit r
bitrate
1000×6
:
bitrate : Ishii bit

Baud & Bitrate (2) tiring n


's's
bit ri 01007 who
'

data

ex

♦ Not all bits transmitted are data 7=7 ng bit I start


stop
bit two g
- -

.
unman

♦ Start/stop/parity bits are transmission overhead


*
♦ Throughput = data transmission excluding overhead
n9 wins in Wii data Taiwu overhead

Example: 115200 baud = 115200 bits/sec


bit twin , of Vodnz bit
+ 7ns d de

If using 8-bit data, 1 start, 1 stop, and no parity


bits, the effective throughput is:
throughput

bitrate

115200 * 8 / 10 = ↳
92160 bits/sec

tho bit D data n' mhm


UH
idoosbit#
D
stop bit 2 do bit
In :
g
9 Microprocessor Theory and Applications
DIV quoi , ,wv
serial

Tx 9 Rx

?
Mosfet Otsu ,
( Data
1 Data format framing l Protocol

:{
.

ow data bit = ?
6,718,9

}gn÷I
.

" 'v ?
'

'"

OY
"
%
"

aging
'

. .

Wounded , I stop bit


1g 2 bit ?

2 .
Munn baud rate
ex . 4800 bps
9600
:

775.200

Tx NLM ex .
baud rate
-
-
1kHz
T =
1ms

Rx TT TT TT TT
Mifune sampling
safmpling
w i.

1ms
uhsriwims

mwbavdratennhewnlwa.fm/umintso:W error
i. ring's error Ivo :p n' lihhifvinlstop bit

( Wh
:
Olooiisgiin error Toi
-

50%

t.in:im:*
Assignment tab not .

""

[ Attendance
.

Chiodos )
serial communication riwnnTNw Hardware module ringworm's
UART -
↳ N' w Hardware nd support Nos serial port to ,

♦ The UART, or Universal Asynchronous Receiver


Transmitter, provides hardware support for a serial
port on AVR processors
Signaling is compatible with PC/Mac/Unix serial (RS-232C)
♦ The UART provides:now Uhrinoooh UART Vos
ivoownounhr parallel
town parallel muosivodowiuw serial ridin
'

I ruin serial
Parallel-to-Serial and Serial-to-Parallel conversion
Start and Stop Bit framing
Parity Generation Cpu speed a. IS baud

Baud-Rate Generation (2400-115.2kbps)


rate

µ 1- serial

Interrupts bus DATA


¢ UHH im
Transmit Complete
④¥ →
8 bit 1 bit
Transmit Data Register Empty u
Receive Complete 070
interrupt Cpu

10 Microprocessor Theory and Applications


RS-232 Standards
♦ An old standard for serial communication
♦ Data UART 0700-1 wtiiuwn
Anew noncom's
'

Start bit & iron RS -

232
urn
oioiwriiv serial VARI 2
"
6,7,8,9 data bits
Eto
,
'
-

It
Parity bit optional rioiwniwsn level rundownis
Stop bit
Nfu wit wins Nunn w
♦ Voltage levels
:

“1” (mark) is represented by -3


un
to -25 V
“0” (space) is represented by +3
mm
to +25 V
Signal levels of ±5 V, ±10 V, ±12 V, and ±15 V are all commonly seen
depending on the voltages available to the line driver circuit

11 Microprocessor Theory and Applications


RS232 Character Transmission

minion
n' ovine in {
-

3h33

I
Tindouf
Hornik noise

12 Microprocessor Theory and Applications


&
= bid Modem
RS-232 Null Modem Connection orion inv
-

?
I

÷
" '

?
♦ 2 types of connectors: DB-25 andO
.

DB-9 9 Tv 9 -

timer
♦ Since it is asynchronous, no external clock is .
mssriw

needed, only 3 wires are required for the simplest


RS232 connection (GND, TxD, RxD)
rio computer
}
ivviv modem msg

Nain modem

Nos uh , computer Noory


:

if ur Null modem

rioslvihiv

13 Microprocessor Theory and Applications


:÷÷÷÷¥÷÷:÷÷÷÷
i
.
Connecting AVR to RS-232 Port
♦ The first step to connecting a device to the RS-232 port is to transform
the RS-232 levels into 0 and 5 V
♦ This is done by RS-232 Level Converters
IC
♦ MAX232 includes a Charge Pump, which generates +10V and -10V

(
from a single 5V supply. This IC also includes two receivers and two
transmitters in the same package
suywo su-
YWIOV - - -

Dumb

D
converse

"
ii:
0108MW Mcintyre

14 Microprocessor Theory and Applications


TV
" N,
.
. .

sin controller
' ,
T


WMU "
system
www.onsdo
(

embedded
9
font ,

pconnnuoilrq.IM?MffYwinxmet
(
goes
Kyung roup

FEI


Yhisdwinwrws uh & Pc ohoioiv


: ,
µc
DA
parity
-

ENE Uonlhirvsriu
I 0
quickie:& ,
-

Protocol :
8E2 219600 d8E49b00
"
ow .

stop bit →

Baud rate : 9600 bps ( noiuwniminushloi )
Df Df ,
-
. . .

Do
Data : O O 7 O O 7 O 2
Even

avant 's O parity


stop bit
!
bit
stay
° 1 01 00 , o o

Bitstream :
-w
Do Dt

transfer file size 96000 bytes :


How much time ?
Tho :O's file vwin 96000 bytes ( protocol SEZ rate 9600 bps ) Trini ?
I frame

③ I 0100 100 ①④

I framed 8-11+21-1 = 12 bits W data 8 bits


viii. whiffs
i.
throughput ribs 9600 D data
Iz

%×8bit=€ (9600×82)
85-2/9600

f ( www.umoiw )

bit
start
stop bit
-9
UART '
-

USA RT
AVR Serial Port Programming / Cortinarius
AVR I built in UART Tsd support mode sync Won VSART
y
. .
.

There are 5 registers associated with USART


Finnian setting
① 9bundYnl0m
♦ UDR
O
.

ruwnasync
(USART Data Register)
.

A
=


②♦ UCSRA,
O UCSRB, UCSRC
(USART Control Status Register)
Z z
( register
Luo

Mw :
ninth
♦ UBRR 4jm%J7
D prog .

(USART Baud Rate Register) e


Writhing't "
a
" book
control baud rate open

15 Microprocessor Theory and Applications



UBRR and Baud Rate in AVR
minister.se: Iit VCSRC
.
no a
12 bit


UBBRH I It
UBRRH
UBRRL 8 bit

fat
CPU 8 bit ( Register mm;D 8 bits 9MW 72bithoimosdzm.mn otw '

(byte
)

♦ USART Baud Rate Register (12 bits) control status


High byte ,

♦ The most significant byte has a shared address with UCSRC


XTAL
find load • a

Desired Baud Rate = Fosc / (16(X+1)) 8=28


ojogw register 2
wit
out
X = (Fosc / (16(Desired Baud Rate))) – 1 z 40
96
Low .in
's v.
" '
X is the value we load into the UBRR[11:0] → Co ,z -

①I
'

viuoinloimhsrwdgunuu iiwrttsvono
♦ Assuming that Fosc = 8 MHz
-

Desired Baud Rate = Fosc/16(X+1) = 8MHz/16(X+1) = 500kHz/(X+1)


X = (500 kHz/ Desired Baud Rate) - 1

D

16 Microprocessor Theory and Applications


Typical Baud Rate

17 Microprocessor Theory and Applications


DBR 11059200
9600
=

b9Vdr⇒
With XTAL
=

:
11.0592 MHZ lbcxtl )

11059200
=
153600kt 153600
VBRR= ? to have a 9600
X I
77

18 Microprocessor Theory and Applications


UDR and USART Data I/O
♦ To provide a full-duplex, there are 2 shift registers referred to as
Transmit Shift Register and Receive Shift Register
♦ Share the same address and named USART Data Register (UDR)

19 Microprocessor Theory and Applications


UCSRs and USART Configurations

♦ USART Control and Status Registers


♦ Three 8-bit registers to control the USART
operation
♦ They are UCSRA, UCSRB, and UCSRC

20 Microprocessor Theory and Applications


UCSRA

21 Microprocessor Theory and Applications


UCSRA (2)

22 Microprocessor Theory and Applications


UCSRB

23 Microprocessor Theory and Applications


UCSRB (2)

24 Microprocessor Theory and Applications


UCSRC

Note on bit7: UCSRC and UBRR share the same


address. Set URSEL=1 when you want the data to
be written to UCSRC, otherwise set URSEL=0 to
write to UBRR

25 Microprocessor Theory and Applications


UCSRC (2)

26 Microprocessor Theory and Applications


UCSZ (3 bits)

27 Microprocessor Theory and Applications


UCSRB RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8

UCSRC URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL

28 Microprocessor Theory and Applications


UCSRB RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8

UCSRC URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL

29 Microprocessor Theory and Applications


USART in Tx Mode

UCSRA RXC TXC UDRE FE DOR PE U2X MPCM

UCSRB RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8

UCSRC URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL

30 Microprocessor Theory and Applications


USART in Rx Mode

0
2 I
UCSRA RXC TXC €0543
UDRE FE DOR PE U2X MPCM

UCSRB RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8

UCSRC URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL

31 Microprocessor Theory and Applications


Doubling the Baud Rate in AVR
♦ There are two ways to increase the baud rate of
data transfer in AVR:

32 Microprocessor Theory and Applications


Doubling the Baud Rate in AVR (2)

33 Microprocessor Theory and Applications


AVR Serial Port Programming in C

"

6%0009

WT U 3MW .

75 hint redo register


=3 reserve Morons
a

2 0
3 I
UCSRB RXCIE TXCIE UDRIE RXEN TXEN UCSZ2 RXB8 TXB8

UCSRC URSEL UMSEL UPM1 UPM0 USBS UCSZ1 UCSZ0 UCPOL

34 Microprocessor Theory and Applications


AVR Serial Port Programming in C (2)

oshin RXD ( receive )


baud rate 9600
f-
noiworroinandoscilator 8MHz

Bavdrale character
(
sent
Img, ,vr
new

rite owns UDR lini ion write muosionriowoi oh > To


]

35 Microprocessor Theory and Applications


AVR Serial Port Programming in C (3)

36 Microprocessor Theory and Applications

You might also like