1 / 90

Week #9 Serial Communications

Week #9 Serial Communications. ENG3640 Microcomputer Interfacing. Topics. Serial I/O Background Asynchronous Communications The SCI Interface Synchronous Communications The SPI Interface SPI Topologies and Applications. Resources.

prem
Download Presentation

Week #9 Serial Communications

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Week #9 Serial Communications ENG3640 Microcomputer Interfacing

  2. Topics • Serial I/O Background • Asynchronous Communications • The SCI Interface • Synchronous Communications • The SPI Interface • SPI Topologies and Applications ENG3640 Fall 2012

  3. Resources • Huang, Chapter 9, Sections • 9.1 Objectives • 9.2 Fundamental Concepts of Serial Communication • 9.3 The RS-232 Standard • 9.4 The 68HC12 Serial Communication Interface • 9.5 Interfacing SCI with EIA-232 • 9.6 The SCI Operations • Huang, Chapter 10, Sections • 10.1 – 10.5 HC12 SPI System ENG3640 Fall 2012

  4. 1-KB SRAM Port AD Analog to Digital 4-KB EEPROM 68HC812A4 Block Diagram CPU12 Port T Timer Module I/O Ports Port S Serial Communication I/O Ports ENG3640 Fall 2012

  5. Parallel and Serial Transmission • Two types of transmission are widely used today: • Parallel Transmission (busses) • Data is transmitted in one pulse (fast) • Usually used for short distances (Why?) • Bulky and expensive (many I/O lines). • Susceptible to reflection and induced noise. • Many I/O devices do not have a high enough data rate to justify the use of parallel data transfer. • Serial (RS-232, USB) • Serial by bit (slow) • Each bit takes one pulse • Generally used for longer distances • Cheap ENG3640 Fall 2012

  6. The Serial I/O Port • The port contains a bus interface through which the microprocessor can • Send commands to the port. • Read port status • Access input/output data registers in the port. • What distinguishes this port from the general structure of an I/O port is the conversion that occurs between serial and parallel data streams. ENG3640 Fall 2012

  7. Serial I/O Background • Transmitter encodes a data signal to be sent to the receiver. • The timing of the data signal is based on the transmitter clock fT • The receiver samples the serial signal to detect/decode the data. • The timing of the receiver sampling is based on a receiver clock fR • In order to catch every data bit the receiver sampling times must be synchronized to the transmitted signal in some way! • Synchronization techniques: (a) Synchronous (b) Asynchronous Serial Communication Link Transmitter Receiver ENG3640 Fall 2012

  8. Modes of Channel Operation • Transmission is unidirectional. • Usually called receive only transmission. • Example TV, Radio, PC  Printer • Transmission is possible in both direction but not at the same time. • People communication in half-duplex. • EX: Multiple computers connected together talking • Full Duplex allows information (data) to be transferred simultaneously in both directions. • EX: Standard Telephone. ENG3640 Fall 2012

  9. Traditional Configurations • Host communicates with the terminals using a dedicated link. • Terminals can communicate with each other via host only. • Host communicates with the terminals using a shared connection. • Terminals have to identify if data is intended to them (address) • Other Topologies? • Star, Mesh, Ring ENG3640 Fall 2012

  10. The Serial Subsystems • MCU12 has 2 subsystems for serial interfacing • An Asynchronous Serial Communication Protocol: • The serial communication interface (SCI) that can be used to connect a terminal or personal computer to the microcontroller (used in our EVB Boards) • A Synchronous Serial Communication Protocol (SPI): • The serial peripheral interface (SPI) can provide high-speed serial communication to peripherals or other microcontroller units • Proposed by Motorola to facilitate the data exchange between microcontrollers and peripheral devices. • Similar protocols: I2C (Philips), Micro-wire (National Semi) ENG3640 Fall 2012

  11. I. Synchronous Serial Communication • Synchronous communication systems always transmit a clock signal with the data to synchronize the receiver to each bit time. • The clock is provided as a separate clock signal or it can be embedded in the data signal itself. Transmitter Receiver CLK ENG3640 Fall 2012

  12. Principle Binary Codes • There are many ways to encode data (i.e. identify marks (1) and the spaces (0)). • NRZ • NRZI • RZ • CMI • Manchester • Diff Manchester • They are called coding types or modulation formats. ENG3640 Fall 2012 12

  13. I. Synchronous Serial Communication • The clock is provided as a separate signal or it can be embedded in the data signal itself. • Two common ways to embed a clock into the data signal are to use (i) Manchester or (ii) variable pulse width signaling. • Notice signal change in middle of every bit  used by receiver to synchronize the sampling process. ENG3640 Fall 2012

  14. Manchester Data Encoding ENG3640 Fall 2012 14

  15. Synchronous: Separate Clock Signals • Other synchronous serial communication systems send the synchronization clock as a separate clock signal. • The clock’s rising edge always falls in the center of the data bit time. • Examples: Motorola SPI, Phillips I2C, National MicroWire. • The advantage of using a separate clock: • Circuit Simplicity (rising edge triggered shift register) • Data rate does not have to be fixed • The disadvantage? • A Separate clock signal is required (long distance, expensive, reliability!) ENG3640 Fall 2012

  16. II. Asynchronous Serial Communication • Each device uses its own clock. • The clocks must run at the same rate but do not need to be synchronized. • The receiver clock must be within 4% of the transmitter clock. ENG3640 Fall 2012

  17. UART : Universal Asynchronous Receiver Transmitter. • The UART is the interface chip that implements serial data transmission. • Also known as (ACIA) asynchronous communication interface adapter. • If you need more serial ports you would use an UART to interface with your MCU. • Six major components: • Chip select & read/write cont • Data bus buffers • Transmit data Register • Receive data Register • Status Register • Control Register ENG3640 Fall 2012

  18. Asynchronous Data Frame • The basic unit of information is the character or data frame • A Frame is a complete and non divisible packet of bits. • It includes both information (data) and overhead (extra bits) • Synchronization is achieved using Start-Stop bits. • i.e. the receiver needs to know when a character starts and when it stops => character is framed by startand stop bits Idle time ENG3640 Fall 2012

  19. Start and Stop Framing. Parity • The transmitter can send characters at any rate, so there may be delays between the transmission of each character • The receiver detects the falling edge of the start bit and then attempts to sample in the center of each bit time. • Parity is used to detect single bit errors • type: even or odd • the quantity of 1 bits in the data determine the parity bit • The receiver also needs to know (i) number of data bits in each character, (ii) type of parity used if any, (iii) number of stop bits. ENG3640 Fall 2012

  20. Start, Stop and Parity Bits ENG3640 Fall 2012

  21. Example • The letter `A’ is to be transmitted in the format with (i) 8 data bits (ii) no parity (iii) one stop bit Sketch the output • The ASCII code for `A` is $41 or %01000001 1 0 0 0 0 0 1 0 LSB Idle Stop Bit Start Bit LSB MSB ENG3640 Fall 2012

  22. Example: Using RS-232 +15V time 0 V Using RS-232 -15V 1 0 0 0 0 0 1 0 Idle Stop Bit Start Bit LSB MSB ENG3640 Fall 2012 22

  23. Example • Show the framing bits when the char B (21)16 is sent at 7 data bits, 2 stop bits, odd parity: • Solution: • start bit: 0 • data bits: 0100001 • parity bit: 1 • stop bits: 11 1 0 0 0 0 1 0 1 ENG3640 Fall 2012

  24. Data Speed, Baud • Two units of speed are employed in data transmission. • # of data bits transmitted per second (BPS) • Baud : the rate at which the signal changes • For a binary two-level signal, a data rate of one bit per second is equivalent to one Baud. • if a data transmission system uses signals with 16 possible discrete level, each signal can have 16 = 24 different values (i.e., signal element encodes 4 bits) • Example: If the 16-level signals are transmitted at 1,200 Baud, the data rate is 4 x 1,200 = 4,800 bps. • Effective BPS = (nr of data bits)/(nr of frame bits) x baud ENG3640 Fall 2012

  25. Example • How long does it take to transmit one character at a speed of 9600 bauds? Each character is transmitted using a format of seven data bits, even parity, one stop bits. • Solution: • Each character consists of 10 bits (1 start, 1 stop, 1 parity, 7 data) • Effective Data bit rate: 7/10 x 9600 = 6720 BPS • Each bit requires 104 uS = (1/9600) • Thus each character will require 10 x 104uS = 1.04 mS ENG3640 Fall 2012

  26. The RS-232 Standard • The RS-232 standard was established in 1960 by the Electronic Industry Association (EIA) for interfacing between a computer and a modem. • The standard is referred to as either • RS-232 or • EIA-232 • In data communication terms, both computers and terminals are called data terminal equipment (DTE). • Modems and routers are called Data Communication Equipment (DCE) ENG3640 Fall 2012

  27. Data Communications Interfacing ENG3640 Fall 2012

  28. Modems is a contraction of modulator-demodulator Modem is used to send and receive serial digital data over a telephone line Basics of modems Modem is connected to a serial port dedicated circuit the serial port, the RS-232 data terminal equipment (DTE) -> connected to a modem, a data communication equipment (DCE) -> to a telephone line Transmission ... Receiving ... The audio signal is known as the carrier signal Tech: PSK; DPSK; QAM Modems ENG3640 Fall 2012

  29. Carrier Modulations (Analog) ENG3640 Fall 2012

  30. Carrier Modulations (Digital) ENG3640 Fall 2012

  31. Differential Phase Modulation • Phase is shifted by multiples of 90, therefore two bits at a time can be transmitted. 31

  32. The RS-232 Standard • There are four aspects to the EIA-232 standard • Electrical specifications -- specifies the voltage level, data rates, distance of communication • Mechanical Specifications – specify the number of pins and the shape and dimensions of the connectors. • Functional Specifications – specify the function of each signal. • Procedural Specifications – specifies the sequence of events for transmitting data ENG3640 Fall 2012

  33. (1) The EIA-232 Electrical Specs • The interface is rated at a signal rate less than 20 KBPS. With good design, however, we can achieve a higher data rate. • The signal can transfer correctly within 15 meters. Greater distance can be achieved with good design. • Driver maximum output voltage is -25V to +25V • A voltage more negative than -3V at the receiver’s input is interpreted as logic one. • A voltage more positive than +3V at the receiver’s input is interpreted as logic zero. ENG3640 Fall 2012

  34. (2) The EIA-232 Mechanical Specs RJ45 (EIA-561) Connector DB9 (EIA574) Connector V.24/RS-232 DB25 Pin Connector ENG3640 Fall 2012

  35. Cont .. Mechanical: The EIA-232 Cable • The simplest RS232 cable uses just : • TXD, • RXD and • Ground with optional ground shield. • The shield provides protection from electric field interference. ENG3640 Fall 2012

  36. (3) Functional Specs DTR (Data Terminal Ready) (DTE) DSR (Data Set Ready) (DCE) RTS (Request to Send) (DTE) CLS (Clear to Send) (DCE) RI (Ring Indicator) (DCE) TX (Transmit) RX (Receive) …. ENG3640 Fall 2012

  37. Cont … Functional Specs ENG3640 Fall 2012

  38. Procedural Specification • E.g. Asynchronous private line modem (Point-to-Point Link ``Not over the phone line” ) • The modem will require only the following signals to operate: • GND, • Tx, Rx, • RTS, (Request to Send) • CTS, (Clear to Send) • DSR, (Data Set Ready) • DCD (Data Carrier Detect) ENG3640 Fall 2012

  39. (2) Functional/Procedural Specs DSR (Data Set Ready)  From DCE (i.e., Modem is ready) RTS (Request to Send)  DTE to DCE (i.e., DTE Wants to send info) CLS (Clear to Send)  ACK from DCE (i.e., Data may be transmitted now) Local Computer (i.e., DTE) sends data serially to modem. Local Modem (i.e., DCE) modulates signal but before that sends a carrier signal to remote modem. Remote Modem detects the carrier signal ring and asserts DCD to inform remote DTE that a call arrived. DCD (Data Carrier Detect)  Remote Modem (i.e., DCE) indicates that a carrier frequency has been established. Remote Modem (i.e., DCE) receives modulated data, demodulates it and sends it to remote DTE. Direct Link ENG3640 Fall 2012

  40. Sequence of events occurred during data transmission over dedicated link Time Local Remote 1. DCE asserts DSR 2. DTE asserts RTS 3. DCE asserts CTS 4. DTE starts to send data (to local DCE) 5. DCE sends out a carrier and then the modulated data 6. DCE asserts DCD 7. DTE waits for arrival of data 8. DCE sends out demodulated received data 9. DEC receives demodulated data ENG3640 Fall 2012

  41. Procedural Specification • Over the telephone line the modems will have to go through the following phases: • Phase 1: Establishing the Connection • Phase 2: Data Transmission • Phase 3: Disconnection • The modem will require more signals to operate: GND, Tx, Rx, RTS, CTS, DSR, DCD, ….. ENG3640 Fall 2012

  42. Sequence of events occur during data transmission over public phone line time Local Remote (receiving side) (transmission side) Connection establishment phase 1. DTE asserts DTR 2. DCE dials the phone number 3. DCE detects the ring and asserts RING 4. DTE asserts DTR to accept the call 5. DCE sends out a carrier and asserts DSR 6. DCE asserts DSR and DCD and also sends out a carrier for full duplex operation 7. DCE asserts DCD (full duplex operation) ENG3640 Fall 2012

  43. Sequence of events occur during data transmission (continued) time Local Remote (receiving side) (transmission side) Data transmission phase 1. DTE asserts RTS 2. DCE asserts CTS 3. DTE sends out data to DCE 4. DCE modulates data and sends it out 5. DCE demodulates data and forwards the data to DTE 6. DTE receives data Disconnection phase 1. DTE drops RTS 2. DCE drops CTS and drops the carrier 3. DCE deasserts DCD & DSR 4. DTE deasserts DTR ENG3640 Fall 2012

  44. Equipment using asynchronous serial com. normally use the RS-232 interface The logic levels used for RS-232 signals are: +12 V for logic 0; -12 V for logic 1 This is to allow signals to be transmitted over greater distances This is a bipolar form of NRZ format The standard defines 25 different signals Many signals are not used => serial ports also use a DB-9 connector Common signals: Transmit data: TxD or TD Receive data: RxD or RD Request to send: TSR Clear to send: CTS Data set ready: DSR Signal ground: SG Data carrier detect: DCD Data terminal ready: DTR Ring indicator: RI From normal HCMOS and TTL levels we need to use special driver chips for ... RS-232 Interface Standard: Summary ENG3640 Fall 2012

  45. Null Modem • The EIA standard doesn’t allow for a direct connection between two DTEs • When two DTEs wish to communicate then we have to use a DTE-DTE null modem cable configuration. • The Null Modem fools both DTEs into thinking that they are connected to modems. ENG3640 Fall 2012

  46. RS422 • To increase the baud rate and maximum distance, the balanced differential line protocols were introduced. • RS422 signal is encoded in a differential signal A-B because each signal requires two wires • RS422 can connect one transmitter to 10 receivers. ENG3640 Fall 2012

  47. RS232 vs. RS422 ENG3640 Fall 2012

  48. With additional conversion circuits the SCI can be used to communicate with remote devices SCI uses port S pin PS1 as TxD and PS0 as RxD These lines can be enabled or disabled by one of the SCI control registers (SCCR2) When enabled SCI subsystem has control of the respective port S lines and overrides DDRS settings Transmitting is a simple matter of writing bytes to a data register SCDR the SCI handles the framing requirements (no parity) The SCI receiver automatically changes each framed serial character into a byte BAUD register is used to configure the clock The Serial Communication Interface (SCI) in 68HC12 ENG3640 Fall 2012

  49. SCI Block Diagram Transmit/Receive through S0,S1 or S2, S3 ENG3640 Fall 2012

  50. Simplified Functional Block Diagram of the SCI • Consists of: • A transmit data register (SC0DRL) that acts as a buffer • A 10 or 11-bit shift register • When a byte is written to SC0DRL, that byte along with Start bit, Stop bit and optionally a Parity bit is transferred to the transmit shift register. Transmitter Receiver ENG3640 Fall 2012

More Related