Top Banner
4: Serial I/O CET360 Microprocessor Engineering J. Sumey
27

4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

Dec 23, 2015

Download

Documents

Blaze Wiggins
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

4: Serial I/O

CET360Microprocessor Engineering

J. Sumey

Page 2: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

2

Introduction

serial, i.e. bit-at-a-time, interfacing techniques are useful when parallel interfacing limitations become problematic

distance limitations due to crosstalk cabling costs

was popularized in the 1960s by teletypes and modem technologies

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

Page 3: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

3

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

Page 4: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

4

Example: Coldfire/S12 SCI

Page 5: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

5

Serial Data Transmission Issues

a pair of devices communicating over a serial link must agree on a number of parameters…

1. communication type2. data coding3. transmission (Baud) rate4. clocking method5. error handling6. handshaking

Page 6: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

6

1 – Communication Type

refers to how the 2 devices communicate with each othera. simplex – fixed, 1-way over a single

channelb. half-duplex – 2-way over a single, shared

(unidirectional but reversible) channelc. full-duplex – 2-way over a pair of

unidirectional channels

Page 7: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

7

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

Page 8: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

Hex 0 1 2 3 4 5 6 7

0 NUL DLE

0 @ P ` p

1 SOH DC1

! 1 A Q a q

2 STX DC2

” 2 B R b r

3 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

KEYNUL = NullSOH = Start Of HeaderSTX = Start of TransmissionETX = End of TransmissionEOT = End of TextENQ = EnquiryACK = AcknowledgeBEL = Audible BellBS = BackSpaceHT = Horizontal TabLF = Line FeedVT = Vertical TabFF = Form FeedCR = Carriage ReturnSO = Shift OutSI = Shift InDLE = Data Link EscapeDCx = Device Control xNAK = Negative AcknowledgeSYN = Synchronization char.ETB = End Transmission BlockCAN = CancelEM = End of MediumSUB = SubstituteESC = EscapeFS = Field SeparatorGS = Group SeparatorRS = Record SeparatorUS = Unit SeparatorDEL = Delete

Page 9: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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.4k

rate baud

1 time bit

Page 10: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 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)

Page 11: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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-back

but not a requirement! ex – 2 chars using 8 data, 1 stop, no parity:

challenge: show waveform for the message “Hi”

Page 12: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 bit based on the total number of 1s in the character

(including parity bit) used for simple error detection, only 50% accurate

checksum 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

Page 13: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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}

Page 14: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

14

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

Page 15: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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-423 RS-422 EIA-422 RS-485 EIA-485 USB SATA

Page 16: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

16

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

Page 17: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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-45 cable specs – upto 20kbps upto 50’ voltage levels

1=mark=off=-3..-25V, 0=space=on=+3..+25V notice avoidance of ground level!

Page 18: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 levels ex: Maxim’s MAX232

http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pdf

Page 19: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

MAX232/MAX232A

Charge Pump

Inverter

“Logic”side

“EIA”side

5V Supply!

19

Page 20: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 Ready DSR 6 6

Common Ground G 7 5

Carrier Detect DCD 8 1

Data Terminal Ready DTR 20 4

Ring Indicator RI 22 9

*with respect to DTE device

Page 21: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 connections up to 10 receivers on a single line

Page 22: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 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

Page 23: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

23

EIA-422 Example

RS-422 4-wire network using balanced differential drivers (generators) and receivers

Page 24: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

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 networking ex: PLCs on factory floors, home/building

automation provides up to 35 Mbps and up to 4000'

Page 25: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

25

EIA-485 2-wire Network Example

Page 26: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

26

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

Page 27: 4: Serial I/O CET360 Microprocessor Engineering J. Sumey.

27

References

Wikipedia Articles: http://en.wikipedia.org/wiki/Current_loop http://en.wikipedia.org/wiki/RS-232 http://en.wikipedia.org/wiki/RS-485

RS-232 tutorial: http://www.radio-electronics.com/info/telecommunications_

networks/rs232/rs232-serial-interface-basics-tutorial.php B&B Electronics RS-422 & RS-485 App Note:

http://www.bb-elec.com/bb-elec/literature/tech/485appnote.pdf

Maxim MAX-232 IC: http://datasheets.maxim-ic.com/en/ds/MAX220-MAX249.pd

f