28
Asynchronous Serial I/O Unit 12 - Part 1

Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Embed Size (px)

Citation preview

Page 1: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Asynchronous Serial I/O

Unit 12 - Part 1

Page 2: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 3: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

SCI Registers – Channel 0

• SCI0BDH – SCI Baud Rate Register High Byte• SCI0BDL – SCI Baud Rate Register Low Byte• SCI0CR1 – SCI Control Register 1• SCI0CR2 – SCI Control Register 2• SCI0SR1 – SCI Status Register 1• SCI0SR2 – SCI Status Register 2• SCI0DRH – SCI Data Register High Byte• SCI0DRL – SCI Data Register Low Byte

Page 4: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

SCI Register DefinitionsChannel 0

#define SCI0BDH _P(0xC8)#define SCI0BDL _P(0xC9#define SCI0CR1 _P(0xCA)#define SCI0CR2 _P(0xCB)#define SCI0SR1 _P(0xCC)#define SCI0SR2 _P(0xCD)#define SCI0DRH _P(0xCE)#define SCI0DRL _P(0xCF)

Page 5: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 6: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 7: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Baud Rate Generation

BAUD RATE = 2 MHZ 16 * (BAUD RATE DIVISOR)

THEREFORE,

SET BAUD RATE DIVISOR = 2MHZ 16 * (DESIRED BAUD RATE)

Page 8: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Example – Baud Rate Initialization

Let Desired Baud = 9600

Using formula:Baud Rate Divisor = 2000000 16*9600

= 13.0208

(Use integer value of 13)

Register Initialization: SCIOBDH= 0SCIOBDL=13

(Max value of Baud Rate Divisor = 213 - 1 = 8192

Page 9: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Parity Type1: Odd0: Even

Parity Enable

0: 9 data bits1: 8 data bits

Select Loop-BackMode

Wake-up Condition Selection

Page 10: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 11: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 12: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 13: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Interrupt Enables Transmitter and Receiver Enables

Enter Sleep Mode

Send Break Character

Page 14: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 15: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 16: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Break Character

• Start Bit = “0”

• All Data Bits = “0”

• Parity Bits if present = “0”

• Stop Bit = “0”

• 68HC12 keeps line in “0” for additional bit times

Page 17: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 18: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 19: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 20: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 21: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 22: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low
Page 23: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Example: Initialize SCI Channel 0 /* Baud = 9600 */int divisor = 125000/9600; // divisor = 13SCI0BDH = divisor>>8; // SCIOBDH= 0 SCI0BDL = divisor; // SCIOBDL=13

/* Standard OperationM=0 – 8 data bitsPE =0 – No Parity PT =0 – Parity type*/

SCI0CR1 = 0x00;

/* TE = 1 – Enable TransmitterRE = 1 – Enable Receiver */

SCI0CR2 = 0x0C;

Page 24: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Parity Type1: Odd0: Even

Parity Enable

0: 9 data bits1: 8 data bits

Select Loop-BackMode

Wake-up Condition Selection(repeated slide)

Page 25: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Interrupt Enables Transmitter and Receiver Enables

Enter Sleep Mode

Send Break Character

(repeat slide)

Page 26: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Serial I/O Procedures

/* Receive a Character */unsigned char ci(void) {while((SCI0SR1&0x20)==0); return SCI0DRL; }

Checking RDEF flag

Page 27: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

(repeated slide)

Page 28: Asynchronous Serial I/O Unit 12 - Part 1. SCI Registers – Channel 0 SCI0BDH – SCI Baud Rate Register High Byte SCI0BDL – SCI Baud Rate Register Low

Serial I/O Procedure

/* Transmit a Character */void co(unsigned char c) {while((SCI0SR1&80)==0); SCI0DRL=c; }

Checking TDRE flag