440 likes | 681 Views
Serial Communication Interface (SCI). Harrison Jones Alexis Noel William Allen. Introduction & Outline. Alexis Noel Types of data transmission Parallel & Serial Serial Communication Synchronous & Asynchronous Harrison Jones Baud & Bit Rates Asynchronous Serial Transmission
E N D
Serial Communication Interface(SCI) Harrison Jones Alexis Noel William Allen
Introduction & Outline • Alexis Noel • Types of data transmission • Parallel & Serial • Serial Communication • Synchronous & Asynchronous • Harrison Jones • Baud & Bit Rates • Asynchronous Serial Transmission • Start, Data, Stop, Parity Bits • Noise • William Allen • Registers • Examples of data transmission
Serial Communication • Serial = one after the other • Serial Communication = sending one bit at a time over a channel Serial Communication Byte Byte b0 b1 b2 b0 b1 b2 b1 b3 b4 b5 b6 b0 b2 b7 b3 b4 b5 b3 b4 b5 b7 b7 b6 b6
Parallel Communication • Parallel Communication = several bits sent at a time on several parallel channels Parallel Communication b0 Byte b1 Byte b0 b0 b2 b1 b1 b2 b3 b2 b3 b3 b4 b4 b4 b5 b5 b5 b6 b6 b6 b7 b7 b7
Which of these does not send data in a serial stream? USB Fiber Optic Cable Ethernet Parallel Port HDMI Serial Port
Parallel Communication Issues Parallel communication is faster than serial for short distances • Issues with parallel communication: • Inter-symbol interference (ISI) and noisecause corruption over long distances • Wires have small amounts of capacitance and mutual inductance • Bandwidth of parallel wires is much lower than bandwidth of serial wires
Serial Communication for Long Distances • Why serial connection is better for long distances: • Differential signals are used to increase power • Double the signal to noise ratio (SNR) • Reach higher bitrate without noise • USB 2.0 is capable of 480Mbits/sec! • (At this rate, it would take only 46.5 seconds to transfer a 2.19GB BluRay movie over from a hard drive) Differential Signal Fun Fact: Longest ever deep sea Fiber-Optic cable will run through thawing artic between UK and Japan (that’s 9,693 miles of cable!)
Synchronous vs. Asynchronous Communication Synchronous Serial Transmission Asynchronous Serial Transmission • Stream of data is encoded in chunks • Various bytes at the beginning of the data provide an embedded clock • The data stream can also be synchronized by an external clock • Data transmitted one character at a time • Each character contains its own clock • Start bits and stop bits • Resynchronizes with each character
Synchronous Communication Synchronous used for high-speed communication between computers Synchronous Serial Transmission • Advantages • Amount of transmission information restricted to few characters for each block • Not prone to distortion • Can be used at higher speeds • Disadvantages • If error were to occur, whole block of data is lost (100+characters) • User cannot transmit characters instantaneously • Requires storage
Asynchronous Communication Used for speeds up to 3000 bits/second with only simple single-character error detection Asynchronous Serial Transmission • Advantages • Each character is its own complete timer system • Corruption will not spread • Good for irregular interval character generation • Keyboards • Disadvantages • Dependence on recognition of start bits • Many bits are used only for control purpose and carry no useful information • Limits transmission speed
Data Word and Control Bits Asynchronous Serial Transmission • Start Bit • Signals start of transmission of data bits • Transition from logic 1 to logic 0 • Data Bits • Typically 8 data bits (not including parity bit) • Least significant bit is transmitted and received first • Stop Bit • Signals end of data word
BAUD Rates • The rate at which symbols are sent • Measured in symbols per second (Bd) • Also known as baud or modulation rate • Often incorrectly referred to as bits per second • Important Baud Variables • Bd – Baud rate • M – Number of symbols used (voltages, tones, etc) • Number of symbols used (M) = 2N where N = bits / symbol • N – Bits per symbol (binary = 1)
Bit Rates • The rate at which bits are transmitted • Baud * Bits / Symbol • Measured in bits per second (bps) NOT bytes per second (Bps) • Often incorrectly referred to as data rate • Gross Bit Rate – total number of bits transmitted per second • Includes protocol overhead bits and data bits • Rb = 1 / Tb where Tb is the bit transmission time • Symbol Rate ≤ Gross Bit Rate • Only equal when 2 bits per symbol (binary) • Information Rate– rate at which useful data is transmitted • Information rate ≤ Gross Bit Rate • Unless there is no protocol (risky!) • IR = Rb * Data Bit Number / Total Bit Number
Baud Rates Examples • Symbol Number (M) • Analog modem capable 64 different voltage levels (symbols) sends out how many bits per symbol? • M = 65 = 2N. N = 6 bits per symbol • Baud Rate • A baud rate of 100 Baud = 100 symbols / second • Bit Rate • At 9,600 Baud with 3 voltage levels what is the bits per second? • Bits • BPS = 9,600 * 1.5850 = 15,216 bps • Information Rate • Given a protocol with 3 bits of protocol, 8 bits of data, 9600 baud, and 1 bit per symbol (binary) what is the IR? • IR = 9600 * log2(2) * 8/11 = 6981 data bits per second
Asynchronous Serial Transmission • Overhead Bits • Start bit – Start of “frame” bit • Parity Bit – Error check bit • Stop Bits – End of “frame” bit • Data Bit – the actual data
Start Bit • One bit • The first bit of a serial data word • Signals the start of data transmission • Detected as a transition from the idle state to the active state • Referred to as a “mark-to-space” transition • Idle state for HCS12 is high (“1”) • Active state for HCS12 is low (“0”)
Parity Bit • One bit • Used as a crude form of error detection • Even / Odd / No Parity • Even – Start Bit + Data Bits + Stop Bits + Parity = 0 • Odd – Start Bit + Data Bits + Stop Bits + Parity = 1 • None – No parity bit included • IMPORTANT: for this class, simply count Data Bits + Parity Bit • Calculated by transmitter, checked by receiver • User specified on the HCS12
Stop Bits • One+ bits • Indicate the end of transmission • Usually 1 or 2 idle state bits • One stop bit on the HCS12
Data BitS • Number of data bits established by protocol • Common Transmission Mode • 7 bits of data + 1 parity bit = 8 total data bits • Other Mode • 8 bits of data (full byte) + 1 parity bit = 9 total data bits • Bit order is hardware dependent • HCS12 sends LSB first
Example • Sending #$AB with one start bit, one stop bit, even parity, and 8 bit data • Binary is #%1010 1011 • Parity Bit is 0 : 0+1+0+1+0+1+0+1+1+P+1 = EVEN Parity Bit 1 0 1 1 0 0 1 0 1 0 1 Start Bit Stop Bit Data Bits Direction of Transmission
Transmission Errors • Noise – Noisy signals cause bits to “flip” • Overrun – Slow receivers cause loss of data • Framing Error – Timing errors cause issues
Noise • Noise can cause “1” to appear to be “0” and vice verse • Effect lessened by sampling
Noise • Each bit after start bit is sampled X pules after center of start bit. X depends on the mode (1,16, and 64)
Overrun • Very simple concept • Receiver doesn’t read data in SCI data register fast enough • New data lost
Framing Error • The result of reading incoming bits using the wrong starting point • Can be detected by using the parity bit • Often the result of mismatched baud rates
SCI module on the HCS12Billy Allen • The SCI Module communicates over PS1 (Tx) and PS0 (Rx). • Writing to the SCI Data Registers transmits data over the Tx line. • Incoming Rx data is automatically stored in the SCI Data Register. • Flags in the SCI Status Registers can be used to trigger interrupts.
SCI Data Registers • $00CE • $00CF • Reading from this register accesses the data received by the SCI receiver. • Writing to this register transmits the data through the SCI. • T8 and R8 are the 9th data bit when the SCI is in 9-bit mode. • R0-R7 is the data received by the SCI.
Setting the Baud Rate • Writing to SCBIR to set the Baud Rate: • $00C8 • $00C9 • Baud rate = SCI module clock / (16 * SCIBR[12:0])
Setting the Baud Rate • Example: To achieve a baud rate of 9600 with an 8MHz module clock: • LDX #0052 (loads 52 into X) • STX $00C8 (stores X into the SCIBR Registers $00C8 and $00C9) • Note that due to the way the baud rate is calculated, there will be some error in the actual rate that the 12C32 uses. • This example actually yields a baud rate of 9615, but that error (0.156%) is small enough to be safely ignored.
SCI Control Register 1 • $00CA • LOOPS: If set to 1, connects the output of TX to the input of RX. • SCISWAI: If set to 1, disabled the SCI while in wait mode. • RSRC: If LOOPS = 1, RSRC selects the source of the incoming TX signal. • If RSRC = 0, the receiver is connected to the transmitter internally. • If RSRC = 1, the receiver is connected to an external TX signal. • M: Controls the number of data bits. • If M = 0, the SCI uses one start bit, eight data bits, one stop bit. • If M = 1, the SCI uses one start bit, nine data bits, one stop bit.
SCI Control Register 1 • $00CA • WAKE: Defines the input condition that wakes up the receiver. • If WAKE = 0, an idle input (0) will wake up the receiver. • If WAKE = 1, a high input (1) wakes up the receiver. • ILT: Defines when the SCI starts counting to wait for idle bits. • If ILT = 0, the counter begins when the start bit is sensed. • If ILT = 1, the counter begins when the stop bit is sensed. • PE: If PE = 1, a parity bit is added to the data being transferred. • PT: Defines how the parity bit it set. • If PE = 0, parity bit it set for ODD parity. • If PE = 1, parity bit is set for EVEN parity.
SCI Control Register 2 • $00CB • TIE: If TIE = 1, the Transmit Data Register Empty flag, TDRE, can generate interrupt requests. • TCIE: If TCIE = 1, the Transmission Complete flag, TC, can generate interrupt requests. • RIE: If RIE = 1, the Receive Data Register Full flag, RDRF, or the OverRunflag, OR, can generate interrupt requests. • ILIE: If ILIE = 1, the idle line flag, IDLE, can generate interrupt requests.
SCI Control Register 2 • $00CB • TE: Transmitter Enable. If TE = 1, the transmitter is enabled. • RE: Receiver Enable. If RE = 1, the receiver is enabled. • RWU: Receiver Wakeup Bit. If RWU = 1, the SCI goes into a standby state and will not trigger interrupt requests until it wakes up from an external signal. • SBK: Sent Break Bit. If SBK = 1, sends a pattern of break characters on the TX line.
SCI Status Register 1 • $00CC • TDRE: Transmit Data Register Empty Flag • This is set to 1 if the transmit data register becomes empty. • TC: Transmit Complete Flag • This is set to 1 if the transmission is done and nothing new is being sent. • RDRF: Receive Data Register Full Flag • Set to 1 if there is received data available in the SCI data register. • IDLE: Idle Line Flag • Set to 1 if 10 or 11 consecutive logic 1 signals appear on the receiver input line.
SCI Status Register 1 • $00CC • OR: OverRun Flag • Is set to 1 if the software fails to read the contents of the data register before the shift register receives more data. • NF: Noise Flag • Is set to 1 if the SCI detects noise on the receiver input. • FE: Framing Error Flag • Is set to 1 If the SCI detects that a framing error has occurred. • PF: Parity Error Flag • Is set to 1 if the parity bit is incorrect.
SCI Status Register 2 • $00CD • BK13: Break Transmit Character Length • Defines the length of the break character used. • If BK13 = 0, break character is 10 or 11 bits long. • If BK13 = 1, break character is 13 or 14 bits long. • TXDIR: Transmitter Pin Data Direction in Single-wire mode • If single wire mode is active, this controls the data direction for TXD. • If TXDIR = 0, TXD is an input. • If TXDIR = 1, TXD is an output. • RAF: Receiver Active Flag • This is set to 1 if the receiver is currently receiving data.
Data Transmit Example • After a short delay, send the value $AB over the Tx line with an ODD parity bit .
Data Receive Example • Wait until data is received on Rx, then load it into Accumulator X.