eet 2261 unit 11 serial communications interface read almy, chapter 24. homework #11 and lab #11...

41
EET 2261 Unit 11 Serial Communications Interface Read Almy, Chapter 24. Homework #11 and Lab #11 due next week. Quiz next week.

Upload: dwayne-hines

Post on 11-Jan-2016

224 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

EET 2261 Unit 11Serial Communications Interface

Read Almy, Chapter 24.

Homework #11 and Lab #11 due next week.

Quiz next week.

Page 2: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• We’ve used the HCS12’s general-purpose I/O ports (Ports A, B, E,…) to communicate with simple devices, such as switches and LEDs, that use standard TTL-level signals (0 V for LOW and 5 V for HIGH).

• In addition to this low-tech form of communication, our HCS12 contains several blocks that implement more complicated communication bus standards.

Communicating with External Devices

Page 3: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• The HCS12 has two asynchronous serial communications interface blocks named SCI0 & SCI1.

• Each SCI block has two I/O pins: RXD for receiving data, TXD for transmitting data. These pins are shared with the general-purpose I/O port S.

• Figure from p. 6 of textbook or page 23 of Device User Guide).

Serial Communications Interface (SCI) Blocks on the HCS12

Page 4: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• The board has movable jumpers that let us reconfigure the board’s communication resources for different needs. But we’ll leave these jumpers alone.

SCI0 and SCI1 on the Dragon12• On the Dragon12 board:

• The HCS12’s SCI0 is normally connected to the board’s USB port, through which the chip communicates with CodeWarrior on the personal computer.

• The HCS12’s SCI1 is normally connected to the RS232 interface.

Page 5: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Block Diagram of Serial Communications Interface (SCI) Block

Diagram from page 12 of the SCI Block User Guide.

• Remember: there are two separate copies of this circuit on our HCS12 chip. One is called SCI0, and the other is SCI1. We’ll use SCI1.

Page 6: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Special-Function Registers Associated with the SCI Block

• The 8 special-function registers located at addresses $00C8 to $00CF let us control the operation of the SCI0 block.

• The 8 registers at addresses $00D0 to $00D7 are for the SCI1 block.

• See p. 37 of Device User Guide.

Page 7: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

SCI Baud Rate Registers (SCInBDH and SCnIBDL)

• SCInBDH and SCnIBDL combined hold 16 bits, of which 13 form a number called SBR.

• The SCI’s baud rate depends on SBR and the system’s bus clock frequency, as follows: Baud rate = Bus clock freq / (16 × SBR)

• Figure from p. 5 of SCI Block User Guide.

Page 8: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Possible Baud Rates• As stated on the previous slide, the SCI’s baud

rate is given by Baud rate = Bus clock freq / (16 × SBR)where SBR is a 13-bit number.

• So it’s usually not possible to set the baud rate exactly to one of the standard values used by other communications devices (such as 300, 600, 1200, 2400, 4800, 9600, 19200).

• But usually we can get close enough for communication to take place successfully.

Page 9: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

SCI Data Registers (SCInDRH and SCInDRL)

• The SCInDRH and SCInDRL registers hold the data that is being either transmitted or received.

• For 8-bit data (the most common situation), only SCInDRL is used.

• Figure from p. 11 of SCI Block User Guide.

Page 10: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

SCIn Control Register 1 (SCInCR1)

• The bits we care most about in this control register are:• M, which we use to specify whether we’re

working with 8-bit or 9-bit data.• PE, which we use to enable or disable parity

generation/checking.• PT, which (if parity is enabled) we use to

specify whether even or odd parity is used.• Figure from p. 6 of SCI Block User Guide.

Page 11: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

SCIn Control Register 2 (SCInCR2)

• The bits we care most about in this control register are:• TE, which we use to enable or disable data

transmission.• RE, which we use to enable or disable data

reception.

• Figure from p. 7 of SCI Block User Guide.

Page 12: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

SCIn Status Register 1 (SCInSR1)• The bits we care most about in this status

register are:• TDRE, which tells us whether the

transmission data register is empty.• RDRF, which tells us whether the receive

data register is full.

• Figure from p. 8 of SCI Block User Guide.

Page 13: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Steps for Transmitting Data• Programming the SCI to transmit data

(without using interrupts):1. Set baud rate using SCInBDH:SCInBDL registers.

2. Write $00 to SCInCR1 register, indicating 8-bit data frame, no parity bit.

3. Write $08 to SCInCR2 register to enable transmission, also disabling interrupts.

4. Monitor the TDRE bit of the SCInSR1 register to make sure data register is empty before sending a byte to SCInDRL. If TDRE = 1, then go to the next step.

5. Write the byte to be transmitted to SCInDRL.

6. To transfer another byte, go to Step 4.

Page 14: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Steps for Receiving Data• Programming the SCI to receive data

(without using interrupts):1. Set baud rate using SCInBDH:SCInBDL registers.

2. Write $00 to SCInCR1 register, indicating 8-bit data frame, no parity bit.

3. Write $04 to SCInCR2 register to enable reception, also disabling interrupts.

4. Monitor the RDRF bit of the SCInSR1 register to see if an entire byte has been received. If RDRF = 1, then go to the next step.

5. Read the received byte from SCInDRL.

6. To receive another byte, go to Step 4.

Page 15: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• The two previous slides assumed that we’re not using interrupts. Without interrupts, our program will sit in a loop, polling the TDRE bit (or the RDRF bit) repeatedly until it is set, at which point the program proceeds to take some other action:

Over: BRCLR SCI1SR1, %10000000, Over

• Another way is to use interrupts instead of repeatedly polling the TDRE bit (or the RDRF bit).

Polling Versus Interrupts for Serial Communications

Page 16: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Each SCI module has its own interrupt, which can be caused by either the receive data register being full or the transmit data register being empty:

• Enabled or disabled by TIE and RIE in SCInCR2:

• We’re familiar with the TDRE and RDRF flag bits in SCInSR1:

Serial Communications Interface (SCI) Interrupt

Page 17: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• In the interrupt vector table, the two words starting at $FFD6 and $FFD4 are reserved for the starting addresses of the service routines for SCI0 and SCI1 interrupts, respectively.

• Remember: the programmer is responsible for setting up correct addresses in the vector table.

Interrupt Vectors for SCIn Interrupts

From table on page 75 of the Device User Guide.

Page 18: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• A Microsoft Windows accessory program named HyperTerminal lets you send or receive data over your computer’s RS-232 port.

• Shown here is a dialog box for configuring HyperTerminal.

Microsoft HyperTerminal

Page 19: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• In previous weeks we used the HCS12’s general-purpose I/O ports (Ports A, B, E,…) to communicate with simple devices, such as switches and LEDs, that use standard TTL-level signals (0 V for LOW and 5 V for HIGH).

• In addition to this low-tech form of communication, our HCS12 contains many blocks that implement more complicated communication bus standards.

Review: Communicating with External Devices

Page 20: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• These blocks include:

• Two serial communications interface (SCI) blocks.

• Three serial peripheral interface (SPI) blocks.

• Two controller area network (CAN) blocks.

• One inter-integrated circuit (IIC) block.

• Figure from p. 6 of textbook or page 23 of Device User Guide).

Communication Blocks in the HCS12

Page 21: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Sometimes the term bus simply refers to a group of conductors (wires or circuit board traces) that carry signals from one device to another.

• Examples: address bus, data bus

• At other times it refers to a standard set of specifications (voltage levels, timing specs, connectors, etc.) used for communication between devices.

• Examples: RS-232, SPI, USB

Two Meanings of “Bus”

Page 22: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• There are dozens of bus standards in common use. From Wikipedia’s article on the USB bus:

Many Bus Standards

Page 23: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

We’ll Focus on the SCI Blocks

• With all of these HCS12 blocks and bus standards, this is a large and complex topic.

• We’ll restrict our attention the HCS12’s SCI blocks (Chapter 24).

• If you’re interested in the SPI blocks, see Chapter 25. For the IIC block, see Chapter 26.

Page 24: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Some bus standards apply to serial communication (1 data bit transferred at a time).

• Others apply to parallel communication (several data bits—usually 8—transferred at a time).

Terminology: Serial vs. Parallel

Page 25: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• These are two common measures of speed in communications. Many writers loosely treat these as being synonyms, but this is not strictly correct.

• Bits per second (bps) is the easier to understand. Often expressed as kbps or Mbps.

• In the simplest cases, baud rate equals bps. In more sophisticated schemes, the two are related but not equal. Traditional baud rates are 300, 600, 1200, 2400, 4800, 9600, 19200.

Terminology: Bits per Second and Baud Rate

Page 26: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Simplex: Information flows in one direction only. • Example: a temperature sensor sending

data to a personal computer.

• Half-duplex: Information can flow in both directions, but only one at a time.• Example: walkie-talkie.

• Full-duplex: Information can flow in both directions at the same time. • Example: telephone.

Terminology: Simplex vs. Duplex

Page 27: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• In asynchronous communication, the two devices do not share clock signals, so they use “handshaking” signals or some other method to coordinate their activity.

• Widely used serial asynchronous standards:• RS-232• RS-423• RS-422• RS-485• USB (Universal Serial Bus): can operate

synchronously or asynchronously.

Communications Terminology: Asynchronous vs. Synchronous

Page 28: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• In synchronous communication, the sender and receiver share a clock signal.

• Widely used serial synchronous standards:

• SPI (“four-wire,” or “three-wire” variant)

• IIC or I2C (also called “two-wire”)

• 1-wire

Communications Terminology: Asynchronous vs. Synchronous

Page 29: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Ports on a Typical Laptop Computer

USB(Serial)

IEEE 1394(Serial)

RS-232(Serial)

Printer (Parallel)

PS/2 Mouse (Serial)

VGA (Analog video)

Page 30: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

Ports on a Fluke 45 DMM

RS-232(Serial)

IEEE 488 (“GPIB”) option not installed (Parallel)

Page 31: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• The terms “mark” and “space” are old terms from the days of telegraphs. These terms are still often used when discussing serial communication.

• Mark simply means a binary 1 level on the serial line. (When no data is being transmitted, the line sits high, and we are “marking time.”)

• Space simply means a binary 0 level on the line.

Communications Terminology: Mark and Space

Page 32: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Asynchronous communication standards such as RS232 generally use start bits and stop bits at the beginning and end of a transmitted byte.• The start bit is binary 0. • The stop bits—there may be one or two—are binary 1.

• These bits are not part of the data being transmitted. They form a “frame” around the data.

Communications Terminology: Start Bits, Stop Bits

Figure from page 229 of the textbook.

Page 33: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Parity is an error-checking system that attaches an extra bit (called the parity bit) to a byte when the byte is transmitted.

• When we configure a serial device, we often have the choice of using odd parity, even parity, or no parity.

Communications Terminology: Parity Bits

Figure from page 229 of the textbook.

As shown here, we transmit the data byte’s LSB first.

Page 34: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• First version created in early 1960’s.

• Obsolete in some respects, but still very widely used.

• In recent years, has been applied in ways that its original creators never imagined, sometimes leading to problems.

• Original spec defined 25 pins (signals), but often only 9 or fewer are used.

RS-232 Standard

Page 35: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• In any RS-232 application, each device is designated as either Data Terminal Equipment (DTE) or Data Communications Equipment (DCE).

• Simple case: When you connect a personal computer to a modem, the computer is the DTE and the modem is the DCE.

Terminology: DCE vs DTE

Page 36: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Original RS-232 standard called for a DB-25 connector. Since many later applications didn’t use most of the pins, it became common to use DE-9 connectors (often incorrectly referred to as DB-9).

Connectors

Page 37: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• The nine most important signals:

RS-232 Signals

Description Abbrev. DirectionDTE - DCE

DB-25 Pin #

DE-9 Pin #

Transmitted data TxD 2 3

Received data RxD 3 2

Request to send RTS 4 7

Clear to send CTS 5 8

Signal Ground 7 5

Protective Ground 1

Data set Ready DSR 6 6

Data carrier detect DCD 8 1

Data terminal ready DTR 20 4

Page 38: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• As we’ve seen, the original RS-232 standard defines 25 lines, but most applications make do with far fewer than 25—usually 9 or even less.

• With the HCS12’s Serial Communications Interface, we use only three lines: RxD, TxD, and Signal Ground.

• So we’re not using any of the handshaking lines (such as CTS, RTS, DSR, DTR). As a result, data can be lost if the sender transmits data when the receiver is not ready to receive it.

HCS12 Uses a Scaled-Down RS-232 Interface

Page 39: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• TTL voltage levels are:• 0 V for a binary 0.• +5 V for a binary 1.

• This scheme is “unipolar” because it doesn’t use negative voltages.

• For transmission over a cable, it’s undesirable to have either logic level close to 0 V.

• So RS-232 uses a “bipolar” scheme, with:• +3 V to +25 V for a binary 0 (“space”)• -3 V to -25 V for a binary 1 (“mark”)

RS-232 Voltage Levels

Page 40: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• Since TTL voltage levels are incompatible with RS-232 voltage levels, many digital systems need to translate from one to the other.

• A popular chip for this purpose is Maxim’s MAX232A.

MAX232 Chip

Page 41: EET 2261 Unit 11 Serial Communications Interface  Read Almy, Chapter 24.  Homework #11 and Lab #11 due next week.  Quiz next week

• The Dragon12 board contains an RS-232 interface, which consists of a MAX232A chip and a DE9 connector.

• See the Dragon12 Schematic Diagram 3.

RS-232 on the Dragon12