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

EE260 Lecture 11A

Serial Communications
EE260 Lecture 11A: Serial Communication
Serial Vs. Parallel
Serial Parallel
one bit at a time one byte/word at a time
sync or async sync
no data skew data skew
noise immunity crosstalk
simplex, half, or full duplex simplex or half duplex
complex design simple design
two/four wires n-wires
EE260 Lecture 11A: Serial Communication
Types of Serial Comm
RS232. Peer-to-peer (i.e. communications between two devices)
RS485. Multi-point (i.e. communications between two or more devices)
USB (Universal Serial Bus). Replaced RS232 on desktop computers.
CAN (Controller Area Network). Multi-point. Popular in the
automotive industry.
SPI (Serial Peripheral Interface). (1979) Developed by Motorola.
Synchronous master/slave communications.
I2C (Inter-Integrated Circuit). (1982) Developed by Philips. Multi-
master communications. Also called two-wire interface (TWI).
EE260 Lecture 11A: Serial Communication
Serial Comm. Comparisons
S/A Type Duplex #Device
speed
(kbps
distance (ft Wires
RS-232 A peer full 2 20 30(3) 2+
RS-422 A multi-drop half 10 10,000 4,000 1+
RS-485 A multi-point half 32 10,000 4,000 2
I S multi-master half ? 3,400 <10 2
SPI S multi-master full ? >1,000 <10 3+
Microwire S master/slave full ? >625 <10 3+
1-Wire A master/slave half ? 16 1,000 1
EE260 Lecture 11A: Serial Communication
Serial Port Connectors
EE260 Lecture 11A: Serial Communication
Serial Comm?
Serial data is transmitted between devices one bit at a
time using agreed upon electrical signals.
In what order are the series of bits shifted across the
data line?
What constitutes a CLK event?
How does the peripheral know when it is supposed to
receive bytes and when it is supposed to transmit
bytes?
Universal Asynchronous
Receiver/Transmitter
EE260 Lecture 11A: Serial Communication
The USART
Universal Asynchronous Receiver/ Transmitter.
The interface between the microprocessor and the
serial port.
responsible for breaking apart bytes of data and
transmitting them one bit at a time
receives serialized bits and converts them back
into bytes
EE260 Lecture 11A: Serial Communication
EE260 Lecture 11A: Serial Communication
USART Specifics
Two wires !" and #"
Full duplex
Synchronous or Asynchronous?
Requires:
start/stop bit
parity
pre-dened timing
frame size
EE260 Lecture 11A: Serial Communication
USART Options
$%&'%
)*%+
,
-&'*%.
/012345536721
8'&91 $*:1+
;<=<><?<@
$%7A
)*%+
,< B
EE260 Lecture 11A: Serial Communication
USART Frames
!"#$%& !"#$%& ' ( ) * + ,-. ,/. ,0. ,1. ,2.
3
4
5
6
4
3
4
7
8
,
3
4
7
8
.
!
"
: (;!<5=# 654%&
!
#
Start bit, always low
Parity bit, can be even, odd, or none
Stop bit, always high
Idle, not transfers, always high
EE260 Lecture 11A: Serial Communication
USART Frames
8*'+%
8'&91
!"#$%& ' ( ) * + , - . /
0
1
2
3
1
0
1
4
5
' ( ) * + , - . /
0
1
2
3
1
0
1
4
5
$1C725
8'&91
P
even
= b
7
b
6
b
5
b
4
b
3
b
2
b
1
b
0
0
P
odd
= b
7
b
6
b
5
b
4
b
3
b
2
b
1
b
0
1
EE260 Lecture 11A: Serial Communication EE260 Lecture 11: Serial Communication
D$E!#F Control and Status
Registers
DG$!FE
Mostly for status
DG$!F)
Enable interrupts, Tx, Rx
D$G!FG
Modes, Frame Size
D)!!FH3I
Baud rate high and low bytes
DJ!F
RX and TX data register
EE260 Lecture 11A: Serial Communication
D$E!#F Control and
Status Registers
F"GF > = ; M N B , F
6&91 !KGF #KGF DJ!/F 8/F J4!F D-/F DBKF L-GLF
!1&53O'*%1 ! !3P ! ! ! ! !3P !3P
J1Q&RS% F F , F F F F F
D
G
$
!
F
E
!KGF Receive Complete. Data received
but not yet read.
#KGF Transmit Complete. Set when all
data has transmitted.
DJ!/F Data Register Empty. Set when
DJ!F register is ready for new data.
8/F Frame Error. Set when DJ!F has data
in which the rst stop bit is zero (Frame
Error)
J4!F Data Overrun. Set when the DJ!F was
not read before the next frame arrived.
D-/F Parity Error. Set when the next frame in
DJ!F has a parity error.
DBKF Double Transmission speed. For
asynchronous operation to speed double
L-GLF Multi-processor communication mode.
If no addressing information is provided,
incoming data is ignored when this is set.
EE260 Lecture 11A: Serial Communication
D$E!#F Control and
Status Registers
F"G, > = ; M N B , F
6&91 !KGT/F #KGT/4 DJ!T/F !K/6F #K/6F DG$UFB !K)?F #K)?F
!1&53O'*%1 !3P !3P !3P !3P !3P !3P ! !3P
J1Q&RS% F F F F F F F F
D
G
$
!
F
)
!KGT/F RX Complete Interrupt Enable.
Allows interrupts upon receive completes.
#KGF Transmit Complete Interrupt Enable.
Allows interrupts upon transmit completes.
DJ!T/F Data Register Empty Interrupt Enable.
Allows interrupts upon empty data reg.
!K/6F Receive Enable. Allows data receive,
and recongures the pin for receives.
#K/6F Transmit Enable. Allows data transmits,
and recongures the pin for transmission.
DG$UFB Character size bit 2. The other bits are
in register DG$!FG.
!K)?F Receive Data Bit 8. This is the 8th data
bit of a received character. The other bits
are in DJ!F.
#K)?F Transmit Data Bit 8. This is the 8th data
bit of a character to be transmitted. The other
bits go in DJ!F. This bit must be written
rst.
EE260 Lecture 11A: Serial Communication
D$E!#F Control and
Status Registers
F"GB > = ; M N B , F
6&91 DL$/IF, DL$/IFF D-LF, D-LFF D$)$F DG$UF, DG$UFF DG-4IF
!1&53O'*%1 !3P !3P !3P !3P !3P !3P !3P !3P
J1Q&RS% F F F F F , , F
D
$
G
!
F
G
DL$/I
MODE
FF
Asynch USART
F, Synch. USART
,F
----
,, Master SPI (MSPIM)
D-LF Parity MODE
FF
Disabled
F, ----
,F
Enabled, Even
,,
Enabled, Odd
DG$U
Frame Size
FFF
5-bit
FF,
6-bit
F,F
7-bit
F,,
8-bit
,FF
---
,F,
---
,,F
---
,,,
9-bit
DG-4IF Clock Polarity. Set to transmit on falling edge
and sample on rising edge. Clear to transmit on
rising edge and sample on falling edge.
EE260 Lecture 11A: Serial Communication
D$E!#F Baud Rate
Registers
F"G; > = ; M N B , F
6&91 V V V V D)!!F,, D)!!F,F D)!!F@ D)!!F?
!1&53O'*%1 ! ! ! ! !3P !3P !3P !3P
J1Q&RS% F F F F F F F F
D)!!FH
F"GM > = ; M N B , F
6&91 D)!!F> D)!!F= D)!!F; D)!!FM D)!!FN D)!!FB D)!!F, D)!!FF
!1&53O'*%1 !3P !3P !3P !3P !3P !3P !3P !3P
J1Q&RS% F F F F F F F F
D)!!FI
EE260 Lecture 11A: Serial Communication
D$E!#F Baud Rates
Baud Rate
(bps)
DBKFWF
D)!!F
DBKFW,
D)!!F
2400
F"F,EF F"FNMF
4800
F"FFG8 F"F,EF
9600
F"FF=> F"FFG8
14400
F"FFMM F"FF?E
19200
F"FFNN F"FF=>
28800
F"FFBB F"FFMM
38400
F"FF,@ F"FFNN
57600
F"FF,F F"FFBB
76800
F"FFFG F"FF,@
115200
F"FFF? F"FF,F
230400
F"FFFN F"FFF?
250000
F"FFFN F"FFF>
500000
F"FFF, F"FFFN
100000
F"FFFF F"FFF,
DBKF W F
DBKF W ,

10
6
Baud Rate

1 D)!!F W
D)!!F W

2 10
6
Baud Rate

1
EE260 Lecture 11A: Serial Communication
DJ!F:
UARTF I/O Data Register
F"G= > = ; M N B , F
6&91 DJ> DJ= DJ; DJM DJN DJB DJ, DJF
!1&53
O'*%1
!3P !3P !3P !3P !3P !3P !3P !3P
J1Q&RS% F F F F F F F F
EE260 Lecture 11A: Serial Communication
Group Exercise
Determine what is happening
DG$!FE W XFYY#KGFZ[XFYYDBKFZ[XFYYL-GLFZ\
DG$!F) W FYY!KGT/F[FYY#KGT/F[FYYDJ!T/F[FYY!K/6F[,YY#K/6F[FYYDG$UFB[FYY#K)?F\
D$G!FG W FYYDL$/IF,[FYYDL$/IFF[FYYD-LF,[FYYD-LFF[FYD$)$F[,YYD$GUF,\
D$G!FG [W ,YYD$GUFF[FYYDG-4IF\
EE260 Lecture 11A: Serial Communication
Group Exercise
normal transmission speed
(not x2)
multi-processor mode
disabled
turn on RX complete and data
register empty interrupts
turn off TX complete interrupt
10.1 Determine the appropriate bit settings for DG$!FE,
DG$!F), DG$!FG, and D)!!F to manage a serial interface
using the following:
turn on the RX, and turn off
the TX
character size = 8 bits
asynchronous mode
no parity
1 stop bit
baud rate 115200 bps.
EE260 Lecture 11A: Serial Communication
USART Example Initialize
]51Q*21 )EDJ^-!/$GEI/! F"FF=> 33@=FF _&R5
07*5 D$E!#^*2*%X07*5Z
`
33 $1% %a1 _&R5 '&%1 A'1+C&S1 '&%1 '1b*+%1'
D)!!F W )EDJ^-!/$GEI/!\
33 $1% Q'&91 Q7'9&%c ?5&%&< , +%7A _*%d
DG$!FG W XXFYYD$)$FZ[X, YY DG$UF,Z[X,YYDG$UFFZZ\
33 /2&_S1 '1C1*01' &25 %'&2+9*%%1'
DG$!F) W XX,YY!K/6FZ[X,YY#K/6FZZ\
e
EE260 Lecture 11A: Serial Communication
USART Example TX
write the bytes to be transmitted to the UDR register.
make sure that this register is empty before doing this
avoid overwriting data that has not yet been transmitted.
keep checking the DJ!/ bit in the DG$!FE register before writing
07*5 D$E!#^+125X R2+*b215 Ca&' 5&%&Z
`
33Oa*S1 %a1 %'&2+9*% _RQQ1' *+ 27% 19A%. S77A
Oa*S1XfXDG$!FE g X,YYDJ!/FZZZ\
33Oa12 %a1 _RQQ1' *+ 19A%. O'*%1 5&%& %7 %a1 %'&2+9*%%15
DJ!F W 5&%&\
e
EE260 Lecture 11A: Serial Communication
USART Example Program
07*5 +1%RAX07*5Z
`
D$E!#^*2*%XZ\
D$E!#^+125Xh&hZ\ 33 $125 &
D$E!#^+125XF"=,Z\ 33 $125 &
D$E!#^+125Xhi'hZ\ 33 $125 C&''*&b1 '1%R'2
D$E!#^+125Xhi2hZ\ 33 $125 S*21Q115
e
EE260 Lecture 11A: Serial Communication
USART Example Send String
33 +125+ %a1 Ca&'&C%1'+ Q'79 %a1 +%'*2b 721 &% &
33%*91 %7 %a1 D$E!#
07*5 D$E!#^AR%+%'*2bXCa&'j $%'*2b-%'Z
`
Oa*S1Xj$%'*2b-%' fW F"FFZ
`
D$E!#^+125Xj$%'*2b-%'Z\
$%'*2b-%'kk\
e
e
Usage: D$E!#^AR%+%'*2bXlH1SS7 #a1'1dlZ\
07S&%*S1 R*2%?^% _RQQ1'mBFn\
D$E!#^AR%+%'*2bX_RQQ1'Z\
EE260 Lecture 11A: Serial Communication
USART Example TX
keep checking the !KG bit in the DG$!FE register to see if data has
been received
read the data from the DJ!F register.
R2+*b215 Ca&' D$E!#^!1C1*01X07*5Z
`
3j P&*% Q7' 5&%& %7 _1 '1C1*015 j3
Oa*S1 XfXDG$!FE g X,YY!KGFZZZ\
3j o1% &25 '1%R'2 '1C1*015 5&%& Q'79 _RQQ1' j3
'1%R'2 DJ!F\
e
EE260 Lecture 11A: Serial Communication
USART Interrupts
]51Q*21 )EDJ^-!/$GEI/! F"FF=>
07*5 D$E!#^*2%1''RA%^*2*%X07*5Z
`
CS*XZ\
33 $1% %a1 _&R5 '&%1 A'1+C&S1 '&%1 '1b*+%1'
D)!!F W )EDJ^-!/$GEI/!\
33 /2&_S1 '1C1*01' &25 %'&2+9*%%1' &25 !" *2%1''RA%
DG$!F) W XX,YY!K/6FZ[X,YY#K/6FZ[X, YY !KGT/FZZ\
33 $1% Q'&91 Q7'9&%c ?5&%&< , +%7A _*%d
DG$!FG W XXFYYD$)$FZ[X, YY DG$UF,Z[X,YYDG$UFFZZ\
+1*XZ\
e
EE260 Lecture 11A: Serial Communication
USART Interrupts
07S&%*S1 *2% *WF\
07S&%*S1 R*2%?^% _RQQ1'mBFn\
07S&%*S1 R*2%?^% $%'!"8S&bWF\
T$!XD$E!#F^!K^01C%Z
`
_RQQ1'm*nWDJ!F\ 33!1&5 D$E!# 5&%& '1b*+%1'
33Ca1Cp Q7' C&''*&b1 '1%R'2 %1'9*2&%7' &25 *2C'1912%
33_RQQ1' *251"
*Q X_RQQ1'm*kknWWhi'hZ
`
33 *Q %1'9*2&%7' 51%1C%15
$%'!"8S&bW,\ 33$1% $%'*2b '1C1*015 QS&b
_RQQ1'm*q,nWF"FF\ 33$1% +%'*2b %1'9*2&%7' %7 F"FF
*WF\ 33!1+1% _RQQ1' *251"
e
e

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