ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 •...

24
Lecture #24 1 ECE251: Thursday November 14 Universal Asynchronous Receiver & Transmitter Text Chapter 22, Sections 22.1.1-22.1.4-read carefully TM4C Data Sheet Section 14-no need to read this A key topic but not a lab HW #7 due next Thursday; Homework #8 due Dec 5 Lab #8 this week & next; deliverables weeks of Nov 18 & Dec 2 Lab #9 week of Dec. 2; due week of Dec. 9 Practical #2 is week of Dec. 9 in lab. Final Exam on Thursday, Dec. 19, 9:40am 2 hour exam

Transcript of ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 •...

Page 1: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 1

ECE251: Thursday November 14• Universal Asynchronous Receiver & Transmitter

– Text Chapter 22, Sections 22.1.1-22.1.4-read carefully– TM4C Data Sheet Section 14-no need to read this– A key topic but not a lab

• HW #7 due next Thursday; Homework #8 due Dec 5• Lab #8 this week & next; deliverables weeks of Nov 18 & Dec 2• Lab #9 week of Dec. 2; due week of Dec. 9• Practical #2 is week of Dec. 9 in lab.• Final Exam on Thursday, Dec. 19, 9:40am

2 hour exam

Page 2: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 2

Types of Serial Communications• Simplex--1 wire, 1 direction (TV, Radio, etc.)

• Half-Duplex--1 wire, 2 directions (Telephone)– Line is switched: Protocol to determine how switched

• Full-Duplex--2 wires, 2 simultaneous directions

Page 3: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 3

What does “UART” Mean?

• Universal– UART is programmable.

• Asynchronous– NO clock signal sent

• Receive & Transmit

Page 4: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 4

Serial Communication Terminology• Clock: Defines the rate of data transfers (in Hz)• Bit rate: The number of bits transmitted per second. It equals the

clock signal rate (in bits/sec vs Hz)• Bit time: Reciprocal of bit rate (sec) i.e. bit period• Baud: Unit of bits transmitted per second. Baud = bits/sec.• NRZ line code: Non-Return to Zero.

– “Line Code” describes the format used to transfer each information bit– NRZ: The bit (1 or 0) is place on the transmission line for the entire bit

cell: e.g.:

• MODEM: MOdulator/DEModulator– Used to turn digital signals into audio (telephone) signals and vice-

versa.

Serial bit stream

Bit data 1 0 1 1 0 1 0 0 1 1 0

Page 5: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 5

Serial Communication Terminology• ASCII: American Standard Code for Information Interchange

– 7 bit code--all numbers + upper/lower case characters + many more– E.g. “h” = $68 “D” = $44 “?” = $3F “ ” = $20– See Appendix C on Lab page

• Parity Bit: Additional bit (usually most significant bit) used to detect a single error in a sequence of bits– Typically done at character level: Use 8 bits to send a 7 bit ASCII

character + parity– May be Odd (extra bit makes entire sequence have odd # of ones) or

may be Even (extra bit makes entire sequence have even # of ones)

• Example: What is “D” in an Odd Parity transmission? In Even?– $44 = 2_0100 0100 → 2_1100 0100 = $C4 odd– $44 = 2_0100 0100 → 2_0100 0100 = $44 even

Page 6: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 6

Serial Communication Standards• RS-232: Historically the most common asynchronous standard

– Established in 1960 By Electronic Industry Association (EIA) for interfacing between a computer and a modem.

– Revised in 1991and renamed: EIA-232-E. Still called RS-232.– Computers and Terminals are “Data Terminal Equipment”– Modems, Bridges, Routers, etc. are “Data Communications Equipment”– Four aspects of standard

• Electrical--voltage levels, rise times, fall times, data rates, distances, … • Functional--function of signals• Mechanical--# of pins, shape/dimensions of connectors• Procedural--sequence of events for transmitting data

Data

Communications

Equipment

Data

Terminal

Equipment

Page 7: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 7

Down and Dirty with RS-232• Signal levels: (large, “ugly" voltages)

– “0” --between +3 and +25 v. (Typically +12 v)– “1” --between -3 and -25 v. (Typically -12 v)

• Signal format: Start and Stop bit used to Synchronize signals

– Receiver must have a clock running at 16X the transmitter’s bit rate.

• At 28.8 Kbaud, how long does it take to send “TM4C12”, including start and stop bits ? What speed is the internal receiver clock?– 6 char. x 10 bits/char ÷ 28.8 Kbits/sec = 2.083 msec for 6 chars– 28.8 KHz*16 = 460 KHz receiver clock frequency

Idle (high) Start bit 8-bit ASCII Code (least significant first) Stop bit

1 frame ~ 10 bit times

Page 8: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 8

UART HardwareUART = Universal Asynchronous Receiver/Transmitter• It’s the hardware (IC components in our processor/I/O

subsystem) that is used to handle the asynchronous communications, at the heart of a modem’s or computer’s serial communication functionality.

• It performs Parallel → Serial (transmit) and Serial → Parallel (receive) conversion. See ECE102

• It has a sophisticated programmable clock generator to handle multiple data frequencies veryaccurately.

• It often has a multi-byte buffer to reduce frequency of CPU interrupts to transfer more data.

Page 9: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 9

TM4C UART Capability

• 8 Separate UART systems on chip• Half-duplex operation—each UART can do both

transmit and receive, but not at exactly same time • FIFO Buffers• NRZ (Non-Return-to-Zero) signal format.• Baud rate selection using baud rate registers.• Programmable 5 to 8 data bit (excluding parity) format.• Interrupt generation capability.• Receiver noise error detection.• Framing error detection (If stop bit is not detected).• Transmitter parity creation and receiver parity error

detection.

Page 10: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 10

UART Block Diagram

Page 11: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

UART Character Framefrom TM4C Data Sheet

n is the TM4C UART number: 0-7

Lecture #24 11

Page 12: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

12

Details of Character Frame

Least significantbit first

Paritybit last

Always a logic 0One Start bit

Always a logic 1One or moreStop bits

May be a logic 0 or 1

Lecture #24

7 bits plus parity

8 bits plus parity

Page 13: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Transmitting Bytes 0x32 and 0x3C

13

1 start bit, 1 stop bit, 8 data bits, no parity, baud rate = 9.6 KbaudHow would this change with even parity? With odd parity? With 7 data bits no parity? With even parity? With odd parity? With 2 stop bits? Can these transmissions represent ASCII?

104µsec

Lecture #24

Page 14: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

14

UART SynchronizationUnderstand this concept!

IDLE SIGNAL-Stop Bit

START Bit

ECE102 State Machine

Lecture #24

Page 15: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Practice with RS-232 Signals

15

• What is the Baud rate?• If I told you there are 7-8 data bits & one stop bit per frame, with

one starting on left side of slide, how many frames are being sent?• Can you tell if this is 8 bits of data vs. 7 bits of data + parity

– If it’s 7 bits of data + parity, what IS the parity– So, can you tell which by looking at this chart?

• If it is 7 bits + parity, can it represent ASCII? If so, what ASCII characters are being transmitted?

• If it is 8 bits without parity, what are the bytes being transmitted (in time order)?

• From end of first stop bit to end of last stop bit above, how long does this transmission take?

• Other questions about this?

Lecture #24

52.08 µsec time

Page 16: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Practice with RS-232 Signals

16

• What is the Baud rate?• If I told you there are 7-8 data bits & one stop bit per frame, with

one starting on left side of slide, how many frames are being sent?• Can you tell if this is 8 bits of data vs. 7 bits of data + parity

– If it’s 7 bits of data + parity, what IS the parity– So, can you tell which by looking at this chart?

• If it is 7 bits + parity, can it represent ASCII? If so, what ASCII characters are being transmitted?

• If it is 8 bits without parity, what are the bytes being transmitted (in time order)?

• From end of first stop bit to end of last stop bit above, how long does this transmission take?

• Other questions about this?

Lecture #24

52.08 µsec time

Page 17: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Practice with RS-232 Signals

17

• What is the Baud rate?• If I told you there are 7-8 data bits & one stop bit per frame, with

one starting on left side of slide, how many frames are being sent?• Can you tell if this is 8 bits of data vs. 7 bits of data + parity

– If it’s 7 bits of data + parity, what IS the parity– So, can you tell which by looking at this chart?

• If it is 7 bits + parity, can it represent ASCII? If so, what ASCII characters are being transmitted?

• If it is 8 bits without parity, what are the bytes being transmitted (in time order)?

• From end of first stop bit to end of last stop bit above, how long does this transmission take?

• Other questions about this?

Lecture #24

52.08 µsec time

Page 18: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Practice with RS-232 Signals

18

• What is the Baud rate?• If I told you there are 7-8 data bits & one stop bit per frame, with

one starting on left side of slide, how many frames are being sent?• Can you tell if this is 8 bits of data vs. 7 bits of data + parity

– If it’s 7 bits of data + parity, what IS the parity– So, can you tell which by looking at this chart?

• If it is 7 bits + parity, can it represent ASCII? If so, what ASCII characters are being transmitted?

• If it is 8 bits without parity, what are the bytes being transmitted (in time order)?

• From end of first stop bit to end of last stop bit above, how long does this transmission take?

• Other questions about this?

Lecture #24

52.08 µsec time

Page 19: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

More Practice with RS-232

19

• Suppose baud rate is 19.2 Kbaud/sec with one stop bit per frame and 7-8 data bits

• How long is a bit cell? Use correct engineering units!• What else can you tell me about this specific signal?

Lecture #24

bit cell time

Page 20: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Even More Practice

20

• We want to send “2Pi” at 4.8Kbaud rate, using one stop bit per frame with even parity.

• What is the bit cell width?• Show the signal above• What clock rate should the receiver be using to decode this signal?

• OK! Do you understand RS-232 signals well enough for a similar question on the final exam? Good chance there will be one!

Lecture #24

bit cell time

Page 21: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

21

TM4C UART Interfaces • External Interfaces

– Each module uses two signal pins (n is module number 0-7)• UnRX receives data• UnTX transmits data

– These pins are alternate functions for GPIO pins (next slide)• UART supports hardware parity for transmit and

receive– When enabled, parity bit is generated for transmitted data and

computed/compared for received data. Received parity errors are flagged in hardware and can generate interrupts.

• UART Baud Rate Generator– Uses Bus Clock or Precision Clock– See slides from next lecture for more details and examples

Lecture #24

Page 22: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

22

UART Signals

• GPIO pins used for UART Signals– AFSEL Register set to specify something other than GPIO function– Which other function? PMCn field of GPIO PCTL register assigns

UART signal to the specified GPIO Port pin—see next slideLecture #24

Page 23: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

23

UART Alternate Function Select - ReviewAlternate function selected as in Timer Module:• Uses GPIO DIR, AFSEL, PCTL, and AMSEL for particular port

to be used• Clear DIR register bits corresponding to input pins and set DIR

register pins corresponding to output pins (0 thru 7 for both)• Enable alternate function in AFSEL register for port to be used

and for the 2 bits corresponding to pins using as Rx and Tx• In Register PCTL for port to be used, set appropriate bits (4 per

pin) to choose UART (value 1). E.g. for U3Rx, which uses PC6, set bits 27:24 of GPIO_PORTC_PCTL to 0x01

• Disable analog for both Rx and Tx pins by clearing corresponding bits of AMSEL register for the port to be used.

See Timer Module Lecture for a complete example Do you need to remember all this? NO. Just know where to find it!

Lecture #24

Page 24: ECE251: Thursday November 14 · 2019-11-14 · Lecture #24 1 ECE251: Thursday November 14 • Universal Asynchronous Receiver & Transmitter – Text Chapter 22, Sections 22.1.1-22.1.4-read

Lecture #24 24

Next Lecture

• More on UART– UART Signal Review– Baud Rate Generation– TM4C Registers– TM4C Setup and Operation

• USB– Section 22.4 of text– Chapter 18 of TM4C Data Sheet– NOT an exam question