1 / 54

Serial Communication Interface

Serial Communication Interface. Andrew Byrley Evan Johnson Jeff Kornuta John Dykes ME 6405 – Fall 2009 November 10, 2009. Outline. Serial vs Parallel Communication Synchronous vs Asynchronous Data Format Baud rate Register descriptions Implementation Specific Features Examples.

Download Presentation

Serial Communication Interface

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. Serial Communication Interface Andrew Byrley Evan Johnson Jeff Kornuta John Dykes ME 6405 – Fall 2009 November 10, 2009

  2. Outline • Serial vs Parallel Communication • Synchronous vs Asynchronous • Data Format • Baud rate • Register descriptions • Implementation Specific Features • Examples Andrew Byrley

  3. Introduction to Data Transmission “transfer of data from point-to-point” http://en.wikipedia.org/wiki/Data_transmission PURPOSE: It provides a method for electronic devices to communicate with each other Andrew Byrley

  4. Parallel Data Transmission N bits transmitted at a time over N data lines Synchronization among all N bits Note: each N bit is called a word RECEIVER TRANSMITTER Andrew Byrley

  5. Serial Data Transmission Transfers one bit at a time on one data line RECEIVER TRANSMITTER Andrew Byrley

  6. Parallel vs. Serial Parallel requires more transfer lines Bits have to be synchronized Fast, but expensive • Serial requires less transfer lines • Transfers one bit at a time • Slow comparatively, but less expensive Andrew Byrley

  7. Bit Rate Comparison Parallel Serial Smaller maximum cable length for parallel due to skewing Andrew Byrley

  8. Simplex Communication • Communication that occurs in one direction only • Commercial radio broadcast • Television broadcast Andrew Byrley

  9. Duplex Communication • Half-Duplex • Communication in both directions, but only one direction at a time • Walkie-Talkies • Full-Duplex • Communication in both directions, simultaneously • Cell Phones Andrew Byrley

  10. Synchronous Serial Communication Requires clock signal to synchronize transmitter and receiver Continuous transmission to keep clock synchronized Data transfer rate is determined by clock rate Andrew Byrley

  11. Asynchronous Serial Communication Transmitter and Receiver operate independently Transmitter sends data at any time Receiver is ready to accept data at all times No need for clock signals Instead uses Start and Stop bits …but during transmission, format and transfer rate of data must match Andrew Byrley

  12. Main Differences Andrew Byrley

  13. Asynchronous Data Transmission • How does the receiver know what is actual data? • Transmitter & receiver know SCI settings being used • Start, parity, and stop bits are for receiver Evan Johnson

  14. Overhead Bits • Start Bit • Idle transmissions are constant 1 bits • Start bit is a 0 bit preceded by three 1s • Alerts the receiver that data is about to be sent • Stop Bit • Receiver knows how many data bits to expect and if parity is being used • One or two 1 bits following the last data bit or parity bit Evan Johnson

  15. Overhead Bits • Parity Bit • Used to determine if an error occurred during data transmission • Error Detection • Transmitter calculates proper parity bit • Receiver calculates parity bit based on data it received • Receiver compares its parity bit to the one it received Evan Johnson

  16. Overhead Bits • 2 types of parity functionality • Even Parity • Parity bit is set to 1 if there is an odd number of 1s in data bits (Total # of 1s becomes even) • Odd Parity • Parity bit is set to 1 if there is an even number of 1s in data bits (Total # of 1s becomes odd) • Even/Odd Parity is set by user on HCS12 Evan Johnson

  17. Data Bits • Actual data being sent/received + Parity • 8-9 Bits • Most common mode : 8 data bits • Can be used with parity if sending ASCII code since ASCII code is represented with 7 bits • Alternate mode : 9 data bits • Can be used for parity • Can be used as an address marker (in “address-mark variation”)  telling a microprocessor when to sleep or wake up Evan Johnson

  18. Data Bits • Endianness • Which bit is sent first? • Big Endian • Most significant bit sent first • Little Endian • Least significant bit sent first • HCS12 uses little endian communication Evan Johnson

  19. Start Bit Data Bit 0 Data Bit 1 Parity Bit Stop Bit Stop Bit Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 0 1 1 1 0 0 1 0 1 0 0 1 Asynchronous Data Transmission • Example 1: • Hex# 4A16 is to be sent with one start bit, even parity, 8-bit data length and two stop bits • 4A16 = 0100 10102 Evan Johnson

  20. Start Bit Data Bit 0 Data Bit 1 Parity Bit Stop Bit Stop Bit Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 1 0 1 1 0 0 0 1 0 1 1 0 Asynchronous Data Transmission • Example 2: • Hex# B416 is to be sent with one start bit, even parity, 8-bit data length and two stop bits • B416 = 1011 01002 Evan Johnson

  21. Start Bit Data Bit 0 Data Bit 1 Parity Bit Stop Bit Stop Bit Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 1 1 1 1 0 0 0 1 0 1 1 0 Asynchronous Data Transmission • Example 3: • Hex# B416 is to be sent with one start bit, odd parity, 8-bit data length and two stop bits • B416 = 1011 01002 Evan Johnson

  22. Error and Issues Noise Detection Overrun Framing Error Parity Error Evan Johnson

  23. Noise Detection • Receiver samples the data after detecting “start bit” • 16 RT cycles during 1 bit transmission • Samples on RT3,5,7 • Determines if noise is present based on samples Evan Johnson

  24. Noise Detection • If two samples are 1s, start bit is a false start • If one sample is 1, start bit is verified and noise flag is set Evan Johnson

  25. Noise Detection • RT3=1, RT5,7=0 • Start bit is verified but noise flag is set Evan Johnson

  26. Overrun • Software fails to read the SCI data register before it receives the next frame RECEIVER SOFTWARE REGISTER TRANSMITTER Evan Johnson

  27. Framing Error • Error occurs when stop bit is not where receiver expects it to be • Ex: “4” bit is skipped and stop bit is one bit before it should be 1 2 3 4 5 6 7 Evan Johnson

  28. Parity Error • Transmitter computes proper parity bit • Receiver computes parity bit based on data it received • If parity bits differ, an error occurred during transmission • Parity does not detect if an even number of errors occurs Evan Johnson

  29. Baud & Bit rate • Baud rate and bit rate are NOT the same • Bit rate (bps) is the number of bits transmitted per second Jeff Kornuta

  30. Baud & Bit rate • Baud rate (Bd) is the number of “symbols” transmitted per second • # of symbol changes (signaling events) made to the transmission medium per second. • The hardware we are using has two line states, high/low • Two line states can be represented with one bit • In our hardware, 1 baud = 1 bit Jeff Kornuta

  31. Baud & Bit rate • Other hardware can produce and recognize more than two line states using voltage, frequency, or phase modulation resulting in more bits per baud • bps = baud rate × number of bits per baud • In our hardware, given a 9600 baud rate Jeff Kornuta

  32. Baud & Bit rate • Not all bits transmitted are data • Start/stop/parity bits are transmission overhead • Throughput = data transmission excluding overhead • A useful unit for describing throughput is characters per second (cps) • A standard character is one byte of data • cps is not the same as bytes per second • bytes per second is ambiguous on whether overhead is subtracted out or not Jeff Kornuta

  33. Baud & Bit rate • Assuming 9600 bd line speed, 8 bit data format with no parity, 1 start bit and 1 stop bit, calculate the throughput in cps using the following equation Jeff Kornuta

  34. Baud & Bit rate • Assuming 9600 bd line speed, 8 bit data format with no parity, 1 start bit and 1 stop bit, calculate the throughput in cps using the following equation => Don’t forget to convert bauds to bps first! Jeff Kornuta

  35. Baud & Bit rate • Baud set by the equation: • Where BR is the content of Baud Rate Register (described later) • Value 0 to 8191 • Serial communication uses only 2 line states thus Bd = bps Jeff Kornuta

  36. Baud & Bit rate • Table with sample Baud Rates • Can’t always get the exact baud rate due to division of the clock Jeff Kornuta

  37. Implementation Specific Features (S12SCIV2) • Full Duplex • 13-bit baud rate selection • 8- or 9-bit data format • Separate TxD and RxD enable • Programmable output parity and Hardware parity checking • Two receiver wake up methods • Interrupt driven operation with 8 flags • 8 registers used to control SCI ($00C8-$00CF) • Uses Port S pins 0 & 1 for RXD and TXD respectively John Dykes

  38. Register descriptions • Key settings will be discussed in detail • Safe to use defaults for all other settings • Summarizes pages 383-393 in Family Reference Manual John Dykes

  39. $00C8/C9 – SCIBDH/SCIBDL • 13-Bit register determines SCI Baud rate • Baud rate generator is Disabled until TE or RE bit is set after reset. • You MUST write to SCIBDH and then SCIBDL. • Baud rate generator is turned off when this register contains $0000 John Dykes

  40. $00CA – SCICR1 • M (data format mode) – 0: 8-bit, 1: 9-bit. Both 8- and 9-bit data have 1 start and 1 stop bit. • PE (parity enable) – 0: OFF, 1: ON • PT (parity type) – 0: EVEN, 1: ODD John Dykes

  41. $00CB – SCICR2 • TIE (transmit interrupt enable) – 0: disables interrupts for transmit data register empty, 1: enables • TCIE (transmit complete interrupt enable) – 0: disables interrupts for transmit complete, 1: enables • RIE (receiver interrupt enable) – 0: disables interrupts for receiver full and overrun , 1: enables John Dykes

  42. $00CB – SCICR2 • ILIE (idle line interrupt enable) – 0: disables interrupts for idle line, 1: enables • TE (transmit enable) – 0: disable transmitter, 1: enable • RE (receiver enable) – 0: disable receiver, 1: enable John Dykes

  43. $00CC – SCISR1 • Read only • TDRE (transmit data register empty) – 1: byte successfully transferred to transmit shift register • TC (transmit complete) – 0: no transmit in progress, 1: transmit in progress • RDRF (receive data register full) – 0: no data in SCIDRL, 1: data in SCIDRL John Dykes

  44. $00CC – SCISR1 • OR (overrun) – 0: no overrun, 1: overrun (overrun happens when new data is received before old data is read) • NF (noise flag) – 0: disable, 1: enable • FE (framing error flag) – 0: disable, 1: enable • PF (parity error) – 0: No parity error, 1: parity error John Dykes

  45. $00CD – SCISR2 • Not a very interesting register • TXDIR (transmitter pin direction) – 0: TXD pin used as input, 1: TXD pin used as output. (used only in single wire mode) John Dykes

  46. $00CE/CF – SCIRDH/SCIRDL • SCIRDL contains incoming bytes of data from serial port • R8 – bit 8 of received 9-bit data • T8 – bit 8 of transmitted 9-bit data John Dykes

  47. SCI is easy • SCI module makes it easy to send/receive data • SCI module encodes data into standard NRZ format! • Hardest part is setting up baud rate • Can use either flag based or interrupt based logic to drive SCI • One interrupt vector associated with all 8 flags • SCIDRH/SCIDRL are like two registers in one. • Read this register to receive data • Write to this register to send data John Dykes

  48. Example • First, calculate baud rate. Assume 8MHz bus and desired baud rate is 9600 • SCI module runs at bus speed John Dykes

  49. Example • First, calculate baud rate. Assume 8MHz bus and desired baud rate is 9600 • SCI module runs at bus speed • Desired value for SCIBR is 52 • You will have some error margin • Exact solution is 52.0833 • Actual baud rate is 9615.3 (0.160% error) John Dykes

  50. Example • Write SCIBR ($34) to SCIBDH/SCIBDL • For 8-bit, no parity, no interrupts, default values will work • Simply enable transmit and receive in SCICR2 • Read from SCIDRL to receive 8-bit data • Write data to SCIDRL to send 8-bit data • Program will do a remote echo John Dykes

More Related