/
Serial Communication Interface (SCI) Serial Communication Interface (SCI)

Serial Communication Interface (SCI) - PowerPoint Presentation

lois-ondreau
lois-ondreau . @lois-ondreau
Follow
414 views
Uploaded On 2016-02-18

Serial Communication Interface (SCI) - PPT Presentation

1 Ellenor Brown Howard Liles Algan Samur Presentation Outline Types of data transmission Parallel Serial Serial Communication Synchronous Asynchronous Baud and Bit Rates Asynchronous Serial Transmission ID: 223617

data bit sci parity bit data parity sci bits register rate receiver stop baud start transmitter transmission serial transmit

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Serial Communication Interface (SCI)" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Serial Communication Interface (SCI)

1

Ellenor

Brown

Howard Liles

Algan

SamurSlide2

Presentation Outline

Types of data transmission

Parallel

Serial

Serial CommunicationSynchronousAsynchronousBaud and Bit RatesAsynchronous Serial TransmissionStart BitData BitStop BitParity BitNoiseSCI RegistersShow two examples of how data words are transmitted

2

Howard Liles

Ellenor Brown

Algan

SamurSlide3

Data Transmission

3

Electronic devices communicating with each other

Desktop computer

Turbine generators

Hard drive

Printer

Lights

Power supply circuitSlide4

Types of Data Transmission

4

Serial Data Transmission

One bit at a time

Parallel Data Transmission

One word (N bits) at a time

Transmitter (microprocessor)

Receiver (printer)

Word

Receiver (Monitor)

Transmitter (CPU)

= bitsSlide5

Parallel vs. Serial

5

Parallel

requires more transfer lines

Bits have to be synchronized

Fast, but expensive

Examples:

Printer cables

Serial

requires less transfer

lines

Transfers one bit at a

time

Slow comparatively, but less

expensive

Examples:

USB,

Firewire

,

ethernetSlide6

Receiver

Receiver

Transmitter

Transmitter

Serial Communication

6

Synchronous Serial Communication

Transmitter and Receiver have synchronized clocks

Data must be sent constantly in order for them to stay synchronized

Any data not sent on a regular clock cycle is considered noise

Transmission parameters are set up before sending data

30% faster than asynchronous transmission for large continuous blocks of data

Clock rate determines data transfer rate

Asynchronous Communication

Transmitter and receiver do not have synchronized clocks and act independently

Simpler and less expensive than synchronous

Start, Stop and Parity “caution” bits are sent with each word of data

WordSlide7

Comparisons

Andrew Byrley

 

SYNCHRONOUS

ASYNCHRONOUS

How It Works

Clock

Start

and

Stop bits

Advantages

Lower overhead

Greater

throughput

Faster

Simple

Cheap

hardware

Disadvantages

More complex hardware

More expensive

Large

overhead

Slower

7Slide8

Baud and Bit Rates

8

Baud Rate

(

Bd) is the rate at which Symbols are transferred. A symbol is a given signaling event ‘Symbols/second’Number of bits per Symbol is Hardware Specific (our hardware uses 1 baud/bit)Conversion factor: 1 bit = 1 Symbol = 1 baudBit rate (bps) - the rate at which bits are transmitted or “bits/second” Conversion Equation: Bit rate (bps) = baud rate × number of bits per baudSlide9

Baud and Bit Rates Cont.’d

9

Some bits are data and some are not!

Remember the start, stop, and parity bits

which are also known as “overhead bits”Data throughput can be determined by Characters per second (cps) Cps = actual rate of data being sent 1 Standard Character = 1 BitCharacters per second (cps)=Bit rate*(character bits/total bits)*Remember CPS is not same as bytes/second. CPS does not include overhead!Slide10

Baud and Bit Rates Example

10

Example 1:

You have an asynchronous serial connection. Assuming 2 bits per symbol, 9600

bd line speed, 8 bit data format with no parity, 1 start bit and 1 stop bit, calculate the throughput in cps. Bit rate (bps) = baud rate × number of bits per baud bps= 9600x2=19200 (cps)=Bit rate*(character bits/total bits) cps=19200*(8/10)= 15360Slide11

Presentation Outline

Types of data transmission

Parallel

Serial

Serial CommunicationSynchronousAsynchronousBaud and Bit RatesAsynchronous Serial TransmissionStart BitData BitStop BitParity BitNoiseSCI RegistersShow two examples of how data words are transmitted

Howard Liles

Ellenor

Brown

Algan

Samur

11Slide12

Asynchronous Serial Communication

Transmitter and Receiver are independent

Transmitter sends ‘Start’, ‘Parity’ and ‘Stop’ bits with each word of data

Data received between a Stop bit and the next Start bit is ignored

ParityStart

Transmitter

Receiver

Data

Stop

12Slide13

Data Frame Format

Start bit – Indicates beginning of dataData bit – Data being transmitted

Parity bit –

I

ntegrity checkStop bit – Indicates end of data wordData frame size: 10 or 11 bitsParityStart

Transmitter

Receiver

Data

Stop

13Slide14

Start Bit

One bitIndicates the beginning of wordOpposite polarity from idle bit state

Idle state for HCS12 is 1’s

Start bit = 0

14Slide15

Data Bits

Actual data being transmitted plus a parity bitMost common mode:

8-bit transmission

Used for ASCII character transmission (

7-bit ASCII + 1-bit parity = 8-bit)Less common mode:9-bit transmissionCan be used to send a full byte of data + parity bitHCS12 sends least significant bit (LSB) first15Slide16

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 receivedReceiver compares its parity bit to the one it receivedEvan Johnson

16Slide17

Parity Bit

2 types of Parity functionalityEven Parity

Parity bit is set to 1 if there is an odd number of 1’s in data bits

# of 1’s becomes evenOdd ParityParity bit is set to 1 if there is an even number of 1s in data bits  # of 1’s becomes odd)Even/Odd Parity is set by user on HCS12

Evan Johnson

17Slide18

Stop Bit

1 or 2 bitsUsed due to asynchronous nature

D

irectly after the parity bit

Stop bit is the same as the polarity of the data-line’s idle stateIdle state for HCS12 = all 1’sStop bits = 118Slide19

Asynchronous Data Transmission

Example 1:

Hex# 4A

16

is to be sent with one start bit, even parity, 8-bit data length and one stop bit4A16 = 0100 10102

Start Bit

Data 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

Stop Bit

0

0

1

0

1

0

0

1

0

1

1

LSB

19Slide20

Asynchronous Data Transmission

Example 2:

Hex# B4

16

is to be sent with one start bit, even parity, 8-bit data length and one stop bitB416 = 1011 01002

Start Bit

Data 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

Stop Bit

0

0

0

1

0

1

1

0

1

0

1

20Slide21

Asynchronous Data Transmission

Example 3:

Hex# B4

16

is to be sent with one start bit, odd parity, 8-bit data length and one stop bitB416 = 1011 01002

Start Bit

Data 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

Stop Bit

0

0

0

1

0

1

1

0

1

1

1

21Slide22

Error sources

Frame shift

Detected when

a logic 0 is accepted as the stop bit

OverrunSoftware fails to read the SCI data register before the shift register receives the next frameNoiseSCI detects noise on the receiver input22Slide23

Framing Error

O

ccurs

when stop bit is not where receiver expects it to be

Detected when a logic 0 is accepted as the stop bitEx:“4” bit is skipped and stop bit is one bit before it should be

1

2

3

4

5

6

7

23Slide24

Overrun

Software fails to read the SCI data register before it receives the next frame

Data

in the

shift register is lostData already in the SCI data registers is not affected

RECEIVER

REGISTER

SOFTWARE

TRANSMITTER

24Slide25

Noise Detection

SCI detects noise on the receiver

input

25Slide26

Presentation Outline

Types of data transmission

Parallel

Serial

Serial CommunicationSynchronousAsynchronousBaud and Bit RatesAsynchronous Serial TransmissionStart BitData BitStop BitParity BitNoiseSCI RegistersCoding example

Howard Liles

Ellenor Brown

Algan Samur

26Slide27

SCI Baud Rate Registers

SCIBDH & SCHBDL - $00C8-$00C9

13-Bits register determines SCI Baud rate

Baud rate generator is

d

isabled 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

27Slide28

Implementation Specific Features (S12SCIV2)

13-bit baud rate selection

8- or 9-bit data format

Separately enabled transmitter and

receiverProgrammable transmitter output parityInterrupt driven operation with 8 flags8 registers used to control SCI ($00C8-$00CF)Uses Port S pins 0 & 1 for RXD and TXD respectively28Slide29

SCI Control Register 1

SCICR1 - $00CA

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

29Slide30

SCI Control Register

2SCICR2 - $00CB

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: enablesILIE (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

30Slide31

SCI Status Register 1

SCISR1 - $00CC

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

31Slide32

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: enableFE (framing error flag) – 0: disable, 1: enablePF (parity error) – 0: No parity error, 1: parity error

SCI Status Register 1

SCISR1 - $00CC

32Slide33

SCI Status Register 2

SCISR2 - $00CD

BK13 (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 progress33Slide34

SCI Data Registers

SCIDRH &SCIDRL - $00CE - $00CF

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

34Slide35

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 polling or interrupt based logic to drive SCISCIDRH/SCIDRL are like two registers in one. Read this register to receive dataWrite to this register to send data35Slide36

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 marginExact solution is 52.0833Actual baud rate is 9615.3 (0.160% error)36Slide37

Example

Write SCIBR

($0034

) to SCIBDH/SCIBDL

For 8-bit, no parity, no interrupts, default values will workSimply enable transmit and receive in SCICR2Read from SCIDRL to receive 8-bit data Write data to SCIDRL to send 8-bit data37Slide38

Code Example

38Slide39

Code Example

39Slide40

#include <

hidef.h

> /* common defines and macros */

#include <mc9s12c32.h> /* derivative information */

#pragma LINK_INFO DERIVATIVE "mc9s12c32"void SCI_init(void){

int BR = 0x0034; SCIBDH = BR>>8; //stores high Byte

SCIBDL = BR; //stores low Byte SCICR2 = 0x0C; //sets TE and RE to 1}

char SCI_getByte(void){

while (!(SCISR1_RDRF))

;//waits FOREVER until receive register is full

return SCIDRL;

}

void

SCI_sendByte

(char data){

while (!(SCISR1_TDRE))

;//waits FOREVER until transmit register is empty

SCIDRL = data;

//return void;

}

void main(void) {

//variable declarations must go at beginning

/* put your own code here */

EnableInterrupts

;

//required code as per instructions

MISC = 0x03;

PEAR = 0x0C; MODE = 0xE2;

//Call function to setup SCI

SCI_init

();

//Main loop

while(1) { char data = SCI_getByte(); SCI_sendByte(data); } /* loop forever */ /* please make sure that you never leave this function */}40Slide41

Thank You!

Any Questions?

41