J Sumey 2 Introduction serial ie bitatatime interfacing techniques are useful when parallel interfacing limitations become problematic distance limitations due to crosstalk cabling costs ID: 727074
Download Presentation The PPT/PDF document "4: Serial I/O CET360 Microprocessor Engi..." is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.
Slide1
4: Serial I/O
CET360
Microprocessor Engineering
J
. SumeySlide2
2
Introduction
serial
, i.e.
bit-at-a-time, interfacing techniques are useful when parallel interfacing limitations become problematicdistance limitations due to crosstalkcabling costswas popularized in the 1960s by teletypes and modem technologiesstandardized as RS-232C in 1969 by the EIAused by many I/O peripheralsmice, printers, digital cameras, PDAs, GPS receivers,POS terminals (cash drawers & scanners)predecessor to USB
11001010000100101110Slide3
3
Serial Interface Components
at a minimum, a serial interface requires:
transmit / receive registers
holds parallel data before/after serializationPISO/SIPO shift registershandles serialization/deserializationclock circuitry (Baud rate generator)timing signals used by shift registersreferred to as UARTs or
SCI
Universal Asynchronous Receiver/Transmitter
Serial Communication Interface (Motorola)
also:
COM
ports on PCsSlide4
4
Example:
Coldfire
/S12 SCISlide5
5
Serial Data Transmission Issues
a pair of devices communicating over a serial link must agree on a number of parameters…
communication type
data codingtransmission (Baud) rateclocking methoderror handlinghandshakingSlide6
6
1 – Communication Type
refers to how the 2 devices communicate with each other
simplex
– fixed, 1-way over a single channelhalf-duplex – 2-way over a single, shared (unidirectional but reversible) channelfull-duplex – 2-way over a pair of unidirectional channelsSlide7
7
2 – Data Coding
choice of binary code used to represent alphanumeric data
ASCII
– American Standard Code for Information InterchangeEBCDIC – Extended Binary Coded Decimal Interchange Code (IBM)proprietary – ex: credit card scanneralso may refer to the logic levels used1=mark, 0=spaceSlide8
ASCII Chart!
Hex
0
1
2
3
4
5
6
7
0
NUL
DLE
0
@
P
`
p
1
SOH
DC1
!
1AQaq2STXDC2”2BRbr3ETXDC3#3CScs4EOTDC4$4DTdt5ENQNAK%5EUeu6ACKSYN&6FVfv7BELETB’7GWgw8BSCAN(8HXhx9HTEM)9IYiyALFSUB*:JZjzBVTESC+;K[k{CFFFS,<L\l|DCRGS-=M]m}ESORS.>N^n~FSIUS/?O_oDEL
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 = DeleteSlide9
9
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
also: bit rate = number of data bits per sec.common baud rates:110, 300, 1200, 2400, 4800, 9600, 19.2k, 38.4kSlide10
10
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 LANbit rate = baud rateasynchronousno common clock, Tx & Rx run from separate clocksdata bits are framed with Start/Stop bitsStart bit: a fixed 0 bit prefixing the data bitsStop bit: a fixed 1 bit suffixing the data bitsbit rate < baud rate (because of overhead)Slide11
11
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-backbut not a requirement!ex – 2 chars using 8 data, 1 stop, no parity:challenge: show waveform for the message “Hi”Slide12
12
5 – Error Handling
deals with how errors are detected and/or corrected
parity
each sent character may have an odd or even parity bit added to it, directly before the stop bitbased on the total number of 1s in the character (including parity bit)used for simple error detection, only 50% accuratechecksumbetter method based on 1’s complement of binary sum8-bit performance: 255/256 accuracy, also 16-bit, 32-bitcyclic redundancy check (CRC)more sophisticated error detection mechanism based on polynomial math, 99.99%+ accurateSlide13
Checksum Calculation
13
/*
* 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}Slide14
14
6 - Handshaking
additional control interface signals
RTS/CTS – Request To Send/Clear To Send
DTR/DSR – Data Terminal Ready/Data Set ReadyDCD – Data Carrier DetectRI – Ring Indicateused to control / throttle the transmittermay be optional depending on hardware and software implementationSlide15
15
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-423RS-422 EIA-422RS-485 EIA-485USBSATASlide16
16
Serial Standards
20/60ma current loop
original standard used by teletypes
I=1, no I=0once popular in (noisy) industrial settingsT.T.L.simple, logic-level based+5VDC=1, 0VDC=0good for on-PCB device-to-device transfer, otherwise not useful for much distance due to noise vulnerabilitySlide17
17
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-45cable specs – upto 20kbps upto 50’voltage levels1=mark=off=-3..-25V, 0=space=on=+3..+25Vnotice avoidance of ground level!Slide18
18
RS-232C Standard
classifies devices as being either:
Data Terminal Equipment
(DTE) orData Communication Equipment (DCE)defines which pins transmit, receive, etc.requires interface drivers to convert logic levelsex: Maxim’s MAX232http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdfSlide19
MAX232/MAX232A
Charge Pump
Inverter
“Logic”
side
“EIA”
side
5V Supply!
19Slide20
20
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 ReadyDSR66Common GroundG75Carrier DetectDCD81Data Terminal ReadyDTR204Ring IndicatorRI229*with respect to DTE deviceSlide21
21
EIA-423 Standard
an improved version of RS-232 using high-performance 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 connectionsup to 10 receivers on a single lineSlide22
22
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 pairhas 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 extenderSlide23
23
EIA-422 Example
RS-422 4-wire network using balanced differential drivers (generators) and receiversSlide24
24
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 networkingex: PLCs on factory floors, home/building automationprovides up to 35 Mbps and up to 4000'Slide25
25
EIA-485 2-wire Network ExampleSlide26
26
Universal Serial Bus (USB)
similar to EIA-422 (half-duplex, differential), but uses communication protocols to
packetize
data transfersused by current PCs to support connection of modern peripheralssupports upto 127 devices, upto 16’4 different transfer speedslow speed (1.0) = 1.5Mbpsfull speed (1.1) = 12Mbpshi speed (2.0) = 480Mbpssuperspeed (3.0) = 4.8GbpsSlide27
27
References
Wikipedia Articles:
http://en.wikipedia.org/wiki/Current_loop
http://en.wikipedia.org/wiki/RS-232http://en.wikipedia.org/wiki/RS-485RS-232 tutorial:http://www.radio-electronics.com/info/telecommunications_networks/rs232/rs232-serial-interface-basics-tutorial.phpB&B Electronics RS-422 & RS-485 App Note:http://www.bb-elec.com/bb-elec/literature/tech/485appnote.pdfMaxim MAX-232 IC:
http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf