Serial I/O - California University of Pennsylvania

Download Report

Transcript Serial I/O - California University of Pennsylvania

4: Serial I/O
CET360
Microprocessor Engineering
J. Sumey
Introduction

serial, i.e. bit-at-a-time, interfacing techniques are
useful when parallel interfacing limitations become
problematic



was popularized in the 1960s by teletypes and
modem technologies


distance limitations due to crosstalk
cabling costs
standardized as RS-232C in 1969 by the EIA
used by many I/O peripherals


mice, printers, digital cameras, PDAs, GPS receivers,
POS terminals (cash drawers & scanners)
predecessor to USB
2
Serial Interface Components

at a minimum, a serial interface requires:
1. transmit / receive registers
• holds parallel data before/after serialization
2. PISO/SIPO shift registers
• handles serialization/deserialization
3. clock circuitry (Baud rate generator)
• timing signals used by shift registers

referred to as UARTs or SCI



Universal Asynchronous Receiver/Transmitter
Serial Communication Interface (Motorola)
also: COM ports on PCs
3
Example: Coldfire/S12 SCI
4
Serial Data Transmission Issues

a pair of devices communicating over a
serial link must agree on a number of
parameters…
1. communication type
2. data coding
3. transmission (Baud) rate
4. clocking method
5. error handling
6. handshaking
5
1 – Communication Type

refers to how the 2 devices communicate
with each other
a. simplex – fixed, 1-way over a single channel
b. half-duplex – 2-way over a single, shared
(unidirectional but reversible) channel
c. full-duplex – 2-way over a pair of unidirectional
channels
6
2 – Data Coding

choice of binary code used to represent
alphanumeric data




ASCII – American Standard Code for Information
Interchange
EBCDIC – Extended Binary Coded Decimal
Interchange Code (IBM)
proprietary – ex: credit card scanner
also may refer to the logic levels used

1=mark, 0=space
7
Hex
0
1
0
NUL
DLE
1
SOH
DC1
2
STX
3
2
3
4
5
6
7
0
@
P
`
p
!
1
A
Q
a
q
DC2
”
2
B
R
b
r
ETX
DC3
#
3
C
S
c
s
4
EOT
DC4
$
4
D
T
d
t
5
ENQ
NAK
%
5
E
U
e
u
6
ACK
SYN
&
6
F
V
f
v
7
BEL
ETB
’
7
G
W
g
w
8
BS
CAN
(
8
H
X
h
x
9
HT
EM
)
9
I
Y
i
y
A
LF
SUB
*
:
J
Z
j
z
B
VT
ESC
+
;
K
[
k
{
C
FF
FS
,
<
L
\
l
|
D
CR
GS
-
=
M
]
m
}
E
SO
RS
.
>
N
^
n
~
F
SI
US
/
?
O
_
o
DEL
KEY
NUL = Null
SOH = Start Of Header
STX = Start of Transmission
ETX = End of Transmission
EOT = End of Text
ENQ = Enquiry
ACK = Acknowledge
BEL = Audible Bell
BS = BackSpace
HT = Horizontal Tab
LF = Line Feed
VT = Vertical Tab
FF = Form Feed
CR = Carriage Return
SO = Shift Out
SI = Shift In
DLE = Data Link Escape
DCx = Device Control x
NAK = Negative Acknowledge
SYN = Synchronization char.
ETB = End Transmission Block
CAN = Cancel
EM = End of Medium
SUB = Substitute
ESC = Escape
FS = Field Separator
GS = Group Separator
RS = Record Separator
US = Unit Separator
DEL = Delete
3 – Baud Rate

speed at which bits (per sec.) are sent over a
serial data link




may (asynchronous) or may not (synchronous)
include “overhead” bits
1
bit time 
baud rate
also: bit rate = number of data bits per sec.
common baud rates:
110, 300, 1200, 2400, 4800, 9600, 19.2k, 38.4k
9
4 – Clocking Method

determines how receiver is synchronized to
transmitter

synchronous



same clock source is either sent along with or encoded
within a continuous data stream, ex: Ethernet LAN
bit rate = baud rate
asynchronous



no common clock, Tx & Rx run from separate clocks
data bits are framed with Start/Stop bits
 Start bit: a fixed 0 bit prefixing the data bits
 Stop bit: a fixed 1 bit suffixing the data bits
bit rate < baud rate (because of overhead)
10
Asynchronous Format



line is held in inactive mark state (1) when no data to
send
data bits are sent/received LSB to MSB
characters may be sent back-to-back

but not a requirement!

ex – 2 chars using 8 data, 1 stop, no parity:

challenge: show waveform for the message “Hi”
11
5 – Error Handling

deals with how errors are detected and/or
corrected

parity




checksum



each sent character may have an odd or even parity bit
added to it, directly before the stop bit
based on the total number of 1s in the character (including
parity bit)
used for simple error detection, only 50% accurate
better method based on 1’s complement of binary sum
8-bit performance: 255/256 accuracy, also 16-bit, 32-bit
cyclic redundancy check (CRC)

more sophisticated error detection mechanism based on
polynomial math, 99.99%+ accurate
12
Checksum Calculation
/*
* checksum8: calculate & return 8-bit checksum of data array
*
p: pointer to beginning of data byte "array"
*
len: array length in bytes
*
returns: 8-bit 1's complement checksum of array
*/
byte checksum8(void *p, int len)
{
byte *q = p; // so p can point to anything
byte sum = 0;
// running sum
for (; len>0; --len) // iterate over each byte in array
sum += *q++;
// add byte value to running sum
return (byte)~sum;
// return 1's comp of sum
}
13
6 - Handshaking

additional control interface signals






RTS/CTS – Request To Send/Clear To Send
DTR/DSR – Data Terminal Ready/Data Set Ready
DCD – Data Carrier Detect
RI – Ring Indicate
used to control / throttle the transmitter
may be optional depending on hardware and
software implementation
14
Serial Communication Standards

a number of industry-wide serial standards
are commonly used, some have been defined
by the Electronic Industries Alliance (EIA)








20/60ma current loop
T.T.L.
RS-232C (1969)
RS-423  EIA-423
RS-422  EIA-422
RS-485  EIA-485
USB
SATA
15
Serial Standards

20/60ma current loop




original standard used by teletypes
I=1, no I=0
once popular in (noisy) industrial settings
T.T.L.



simple, logic-level based
+5VDC=1, 0VDC=0
good for on-PCB device-to-device transfer,
otherwise not useful for much distance due to
noise vulnerability
16
RS-232C Standard

defines many characteristics of a serial interface




20 signal names & functions: TxD, RxD, RTS, CTS, etc.
connectors & pinouts: DB-25, DE-9, RJ-45
cable specs – upto 20kbps upto 50’
voltage levels


1=mark=off=-3..-25V, 0=space=on=+3..+25V
notice avoidance of ground level!
17
RS-232C Standard

classifies devices as being either:
Data Terminal Equipment (DTE) or
Data Communication Equipment (DCE)


defines which pins transmit, receive, etc.
requires interface drivers to convert logic
levels

ex: Maxim’s MAX232
http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf
18
MAX232/MAX232A
5V Supply!
Charge Pump
Inverter
“Logic”
side
“EIA”
side
19
RS-232C Pinouts*
Signal
Name
DB-25
DE-9
Transmitted Data
TD
2
3
Received Data
RD
3
2
Request To Send
RTS
4
7
Clear To Send
CTS
5
8
Data Set Ready
DSR
6
6
G
7
5
Carrier Detect
DCD
8
1
Data Terminal Ready
DTR
20
4
RI
22
9
Common Ground
Ring Indicator
*with respect to DTE device
20
EIA-423 Standard


an improved version of RS-232 using highperformance drivers and receivers
single-ended / unbalanced like RS-232 but
with better performance


provides up to 100 kbps and up to 4000'
supports multi-drop connections

up to 10 receivers on a single line
21
EIA-422 Standard

similar to EIA-423 but with even better performance

provides up to 10 Mbps and upto 4000'

eliminates ground loop problems by transmitting bits
as a voltage difference over a unidirectional wire pair

has a very high common mode rejection ratio (CMRR)



works better with long cable runs
Note: Ethernet LANs work the same way!
great for use as an RS-232 extender
22
EIA-422 Example

RS-422 4-wire network using balanced
differential drivers (generators) and receivers
23
EIA-485 Standard


similar to EIA-422 but allows multiple
receivers and drivers (up to 32 each) to share
a single 2-wire differential pair in half-duplex
fashion
thus, is multi-point…



readily supports low-cost local networking
ex: PLCs on factory floors, home/building
automation
provides up to 35 Mbps and up to 4000'
24
EIA-485 2-wire Network Example
25
Universal Serial Bus (USB)




similar to EIA-422 (half-duplex, differential), but uses
communication protocols to packetize data transfers
used by current PCs to support connection of modern
peripherals
supports upto 127 devices, upto 16’
4 different transfer speeds




low speed (1.0) = 1.5Mbps
full speed (1.1) = 12Mbps
hi speed (2.0) = 480Mbps
superspeed (3.0) = 4.8Gbps
26
References

Wikipedia Articles:




RS-232 tutorial:


http://www.radioelectronics.com/info/telecommunications_networks/rs232/rs232serial-interface-basics-tutorial.php
B&B Electronics RS-422 & RS-485 App Note:


http://en.wikipedia.org/wiki/Current_loop
http://en.wikipedia.org/wiki/RS-232
http://en.wikipedia.org/wiki/RS-485
http://www.bb-elec.com/bb-elec/literature/tech/485appnote.pdf
Maxim MAX-232 IC:

http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf
27