Serial Communications Interface SCI Michael Lennard Zachary Peters

  • Slides: 32
Download presentation
Serial Communications Interface (SCI) Michael Lennard Zachary Peters Bao Nguyen

Serial Communications Interface (SCI) Michael Lennard Zachary Peters Bao Nguyen

Overview v Types • • v of Data Transmission Parallel Serial Michael Lennard Serial

Overview v Types • • v of Data Transmission Parallel Serial Michael Lennard Serial Communication • Synchronous • Asynchronous v Baud and Bit Rates v Asynchronous Serial Transmission Zachary Peters v Serial Communication With the HCS 12 v Examples of data words are transmitted Bao Nguyen

Parallel Data Transmission Receiver Simultaneous transmission Requires separate data lines synchronized One ‘Word’ Transmitter

Parallel Data Transmission Receiver Simultaneous transmission Requires separate data lines synchronized One ‘Word’ Transmitter Presenter: Michael Lennard Uses a clock to keep bits Fast but Expensive Requires short cables to prevent Cross-

Serial Data Transmission Receiver One Word Transmitter Presenter: Michael Lennard One bit sent at

Serial Data Transmission Receiver One Word Transmitter Presenter: Michael Lennard One bit sent at a time Slow compared to Parallel Requires only a single transmission line & port Cheap! Can often be clocked faster than parallel data Example: USB, Firewire, Ethernet

Serial Data Transmission Two Basic Types of Serial Data Transmission Synchronous Asynchronous Two solutions

Serial Data Transmission Two Basic Types of Serial Data Transmission Synchronous Asynchronous Two solutions to same problem - Receiver needs to know When data starts When data stops If data was processed correctly Presenter: Michael Lennard

Synchronous Serial Communication Transmitter and Receiver have synchronized clocks Continuous data must be sent

Synchronous Serial Communication Transmitter and Receiver have synchronized clocks Continuous data must be sent to maintain synchronization Any data not on a clock cycle is considered noise Establish transmission parameters before sending data 30% faster than asynchronous transmission for large continuous blocks of data. Data Receiver Transmitter 3 Presenter: Michael Lennard 2 1 Clock Ticks

Asynchronous Serial Communication Transmitter & Receiver are independent Transmitter sends ‘Start’, ‘Stop’ and ‘Parity’

Asynchronous Serial Communication Transmitter & Receiver are independent Transmitter sends ‘Start’, ‘Stop’ and ‘Parity’ bits with each word of data Simpler to implement and less expensive than synchronous Data received between a Stop bits and the next Start bit is ignored Data Word Receiver Transmitter Stop Presenter: Michael Lennard Parity Start

Baud Rate vs. Bit Rate Baud Rate (Bd) is the rate at which Symbols

Baud Rate vs. Bit Rate Baud Rate (Bd) is the rate at which Symbols (Signaling Events) are transferred Number of bits per Symbol is Hardware Specific Our hardware uses just 1’s and 0’s and thus just 1 bit/Symbol Bit rate is the absolute rate at which bits are transmitted Can be changed for each port Presenter: Michael Lennard

Baud Rate vs. Characters Per Second Presenter: Michael Lennard

Baud Rate vs. Characters Per Second Presenter: Michael Lennard

Example Problem You have an asynchronous serial connection with 2 bits/Symbol and a 9600

Example Problem You have an asynchronous serial connection with 2 bits/Symbol and a 9600 bd line speed. You want to send data in an 8 bit data format with 1 parity, 1 start bit and 1 stop bit. Calculate throughput in cps. Presenter: Michael Lennard

Overview v Types of Data Transmission • • Michael Lennard Parallel Serial v Serial

Overview v Types of Data Transmission • • Michael Lennard Parallel Serial v Serial Communication • • Synchronous Asynchronous v Baud and Bit Rates v Asynchronous Serial Transmission Zachary Peters v Serial Communication With the HCS 12 v Examples of data words are transmitted Bao Nguyen

Asynchronous Serial Communication Transmitter and Receiver Operate independently Transmitter sends data at any time

Asynchronous Serial Communication Transmitter and Receiver Operate independently Transmitter sends data at any time Receiver is always ready to accept data No need for clock signals However… format and transfer rate must match during transmission Presenter: Zachary Peters

Asynchronous Transmission Data word contains information before and after that specifies the beginning and

Asynchronous Transmission Data word contains information before and after that specifies the beginning and end of word This synchronizes transmitter and receiver during transmission Bit transfer rate is determined by programmer, but limited by interfaces Presenter: Zachary Peters

Data Format Start bit – indicates the beginning of word Data bit – data

Data Format Start bit – indicates the beginning of word Data bit – data user is transmitting Parity bit – checks integrity of data Stop bit – indicates the end of the word Presenter: Zachary Peters

Start Bit Opposite polarity from idle bit state Idle state for HCS 12 =

Start Bit Opposite polarity from idle bit state Idle state for HCS 12 = all 1’s so start bit = 0 Alerts receiver that the data transmission is about to begin Accuracy verification methods to reduce noise (discussed later) Presenter: Zachary Peters

Data Bits Actual Data being sent or received plus parity bit Most common mode:

Data Bits Actual Data being sent or received plus parity bit Most common mode: 8 -bit transmission Less common mode: 9 -bit transmission Used for ASCII character transmission (ASCII code is 7 -bit + 1 parity bit = 8 -bit) Can be used to send a full byte of data + parity bit Example: sending an address LSB transmitted first Presenter: Zachary Peters

Data Bits Example: 8 -bit mode: 1100010101111 ASCII Code in Data “T” Data Stop

Data Bits Example: 8 -bit mode: 1100010101111 ASCII Code in Data “T” Data Stop Bits Start Bit Parity Bit 9 -bit mode: 11011010100011 $2 B Data Stop Bits Start Bit Parity Bit Presenter: Zachary Peters Hex equivalent in Data

Parity Bit 1 Bit Even Parity Located at end of data bits Used as

Parity Bit 1 Bit Even Parity Located at end of data bits Used as a method of ensuring proper data transmission Parity bit = 1, if # of ones in the set is odd (makes the total # of ones even) Odd Parity bit = 1, if # of ones in the set is even (makes the total # of ones odd) Presenter: Zachary Peters

Stop Bit 1 or 2 bits Only used due to asynchronous nature (Synchronous transmitters/receivers

Stop Bit 1 or 2 bits Only used due to asynchronous nature (Synchronous transmitters/receivers don’t need start/stop bits) Occurs directly after the parity bit Bit is the same as the polarity of the data-line’s idle state Idle state for HCS 12 = all 1’s so stop bits = 1 Presenter: Zachary Peters

Noise Detection Problem: Solution: Sample at higher freq than baud rate and take “average”

Noise Detection Problem: Solution: Sample at higher freq than baud rate and take “average” of samples RT Clock = Baud rate * 16 A premature bit (1 or 0) can cause the receiver to think it is receiving data before it should be, or receive incorrect data 16 samples of each bit RT 3, RT 5, RT 7 are recorded Presenter: Zachary Peters

Noise Detection for Start Bit Samples taken after the signal falls to 0 to

Noise Detection for Start Bit Samples taken after the signal falls to 0 to verify if it is indeed a start bit If two ‘ 1’s in sample then not a start bit If one ‘ 1’ in sample then noise bit flagged Presenter: Zachary Peters

Overview v Types of Data Transmission • • Michael Lennard Parallel Serial v Serial

Overview v Types of Data Transmission • • Michael Lennard Parallel Serial v Serial Communication • • Synchronous Asynchronous v Baud and Bit Rates v Asynchronous Serial Transmission v Serial Zachary Peters Communication With the HCS 12 Bao Nguyen v Examples of data words are transmitted

SCI Baud Rate Registers SCIBDH & SCHBDL - $00 C 8 -$00 C 9

SCI Baud Rate Registers SCIBDH & SCHBDL - $00 C 8 -$00 C 9 13 -Bit register determines SCI Baud rate generator is Disabled until TE or RE bit is set for the first time after reset. Baud rate generator is turned off when this register contains $0000 Note: Writing to SCIBDH has no effect w/out writing to SCIBDL Presenter: Bao Nguyen

SCI Control Register 1 SCICR 1 - $00 CA LOOPS (loop operation enable) –

SCI Control Register 1 SCICR 1 - $00 CA LOOPS (loop operation enable) – 0: Normal, 1: Loop Operation SCISWAI (SCI wait mode enable) – 0: Off 1: On M (data format mode) – 0: 8 data bits, 1: 9 data bits. Both use 1 start bit and 1 stop bit PE (parity enable) – 0: Off, 1: On PT (parity type) – 0: Even, 1: Odd Presenter: Bao Nguyen

SCI Control Register 2 SCICR 2 - $00 CB TIE (transmit interrupt enable) –

SCI Control Register 2 SCICR 2 - $00 CB 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 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 Presenter: Bao Nguyen

SCI Status Register 1 SCISR 1 - $00 CC Read only register Can be

SCI Status Register 1 SCISR 1 - $00 CC Read only register Can be used to provide input to the microcontroller for generation of SCI interrupts TDRE (transmit data register empty) – 0: No byte transferred, 1: byte successfully transferred to transmit shift register TC (transmit complete flag) – 0: transmission in progress, 1: no transmission in progress RDRF (receive data register full) – 0: no data in data register, 1: data in data register IDLE (idle flag) – 0: receiver input is active, 1: receiver input has become idle Presenter: Bao Nguyen

SCI Status Register 2 SCISR 2 - $00 CD BK 13 (break transmit character

SCI Status Register 2 SCISR 2 - $00 CD BK 13 (break transmit character length) – 0: 10 or 11 bit, 1: 13 or 14 bit TXDIR (transmitter pin direction) – 0: TXD pin used as input, 1: TXD pin used as output. (used only in single wire mode) RAF (receiver active flag) – 0: no reception in progress, 1: reception in progress Presenter: Bao Nguyen

SCI Data Registers SCIDRH &SCIDRL - $00 CE - $00 CF SCIRDL contains incoming

SCI Data Registers SCIDRH &SCIDRL - $00 CE - $00 CF SCIRDL contains incoming bytes of data from serial port R 8 – bit 8 of received 9 -bit data T 8 – bit 8 of transmitted 9 -bit data Presenter: Bao Nguyen

Asynchronous Data Transmission Example 1: Hex# 4 A 16 is to be sent with

Asynchronous Data Transmission Example 1: Hex# 4 A 16 is to be sent with one start bit, even parity, 8 -bit data length and two stop bits 4 A 16 = 0100 10102 Note: Little endian communication used (LSB sent first) Start Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 0 1 Presenter: Bao Nguyen 0 1 0 Parity Bit 1 Stop Bit 1 1

Asynchronous Data Transmission Example 2: Hex# B 416 is to be sent with one

Asynchronous Data Transmission Example 2: Hex# B 416 is to be sent with one start bit, even parity, 8 -bit data length and two stop bits B 416 = 1011 01002 Start Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 Parity Bit 0 0 Presenter: Bao Nguyen 1 0 1 0 Stop Bit 1

Asynchronous Data Transmission Example 3: Hex# B 416 is to be sent with one

Asynchronous Data Transmission Example 3: Hex# B 416 is to be sent with one start bit, odd parity, 8 -bit data length and two stop bits B 416 = 1011 01002 Start Bit 0 Data Bit 1 Data Bit 2 Data Bit 3 Data Bit 4 Data Bit 5 Data Bit 6 Data Bit 7 Parity Bit 0 0 Presenter: Bao Nguyen 1 0 1 1 Stop Bit 1

Thank You! Any Questions?

Thank You! Any Questions?