Presentation is loading. Please wait.

Presentation is loading. Please wait.

Serial Communication Interface

Similar presentations


Presentation on theme: "Serial Communication Interface"— Presentation transcript:

1 Serial Communication Interface
Chapter 3

2 Objectives Upon completion of this chapter, you will be able to:
Explain serial communication protocol Describe the serial communication features of the PIC18 Program the PIC18 serial port in C

3 Introduction Computers transfer data in two ways: Parallel and Serial.
Parallel: Eight or more data lines, few feet only, short time Serial: Single data line, long distance The PIC18 has serial communication capability built into it.

4 Basics of Serial Communication
The byte of data must be converted to serial bits using a parallel-in-serial-out shift register Serial versus Parallel Data Transfer

5 Basics of Serial Communication (cont’d)
The receiving end must be a serial-in-parallel-out shift register and pack them into a byte. Two methods of serial data communication: Synchronous and Asynchronous Transfers a block of data at a time Transfers a single byte at a time

6 Half-and Full-Duplex Transmission

7 Start and Stop Bits In the asynchronous method, each character is placed between start and stop bits (framing) Framing ASCII ‘A’ (41H) LSB MSB

8 Data Transfer Rate Rate of data transfer: bps (bits per second)
Another widely used terminology for bps is baud rate For Asynchronous serial data communication, the baud rate is generally limited to 100,000bps

9 RS232 Standard Input-output voltage are not TTL compatible
Standard for serial comm (COM port) 1: -3V to -25V; 0: +3V to +25V Reason: for long distance wired line Input-output voltage are not TTL compatible So, we need MAX232/233 for voltage converter. Commonly known as line drivers

10 RS232 Pins Connectors: Minimally, 3 wires: RxD, TxD, GND
Could have 9-pin or 25-pin DB-9 9-Pin Connector DB-25 25-Pin Connector

11 RS232 Pins (cont’d) IBM PC DB-9 Signals
Pin 1 – Data Carrier Detect (DCD) Pin 2 – Received Data (RxD) Pin 3 – Transmitted Data (TxD) Pin 4 – Data Terminal Ready (DTR) Pin 5 – Signal Ground (GND) Pin 6 – Data Set Ready (/DSR) Pin 7 – Request to Send (/RTS) Pin 8 – Clear to Send (/CTS) Pin 9 – Ring Indicator (RI) DB-9 9-Pin Connector Data in Data out

12 PIC18 Connection to RS232 Line driver
(a) Inside MAX (b) its Connection to the PIC18

13 PIC18 Connection to RS232 (Cont’d)
Line driver (a) Inside MAX (b) Its Connection to the PIC18

14 The baud rate in the PIC18 is programmable
SPBRG (Serial Port Baud Rate Generator) Register and Baud Rate in the PIC18 The baud rate in the PIC18 is programmable The value loaded into the SPBRG decides the baud rate Depend on crystal frequency Baud Rate SPBRG (Hex Value) 38400 3 19200 7 9600 F 4800 20 2400 40 1200 81 *For XTAL = 10MHz only!

15 Baud rate Formula (pg.397) X (SPBRG) = (156250/Desired Baud Rate) - 1
Example: Desired baud rate = 1200, Clock Frequency = 10MHz X (SPBRG) = (156250/1200) – 1 X (SPBRG) = = 129 = 81H

16 TXREG Register 8-bit register used for serial communication in the PIC18 For a byte of data to be transferred via the Tx pin, it must be placed in the TXREG register

17 RCREG Register 8-bit register used for serial communication in the PIC18 When the bits are received serially via the Rx pin, the PIC18 deframes them by eliminating the START and STOP bit, making a byte out of data received and then placing in the RCREG register

18 TXSTA (Transmit Status and Control Register)

19 TXSTA (Transmit Status and Control Register) (Cont’d)

20 RCSTA (Receive Status and Control Register) _used to enable the serial port to receive data

21 RCSTA (Receive Status and Control Register) (Cont’d)

22 PIR1 (Peripheral Interrupt Request Register 1)

23 Programming the PIC18 to Transfer Data Serially
TXSTA register = 20H: Indicating asynchronous mode with 8-bit data frame, low baud rate and transmit enabled Set Tx pin an output Loaded SPBRG for baud rate Enabled the serial port (SPEN = 1) Character byte to transmit is write into TXREG Keep Monitor TXIF bit To transmit next character, go to step 5

24 Example1 Write a C program to transfer the letter ‘G’ serially at 9600, continuously. Use 8-bit data and 1 stop bit. Assume XTAL = 10MHz.

25 Example 1 (cont’d)

26 Example2 Write a C program to transfer the message “YES” serially at 9600, continuously. Use 8-bit data and 1 stop bit. Assume XTAL = 10MHz.

27 Example2 (cont’d)

28 Example 3 Write a C program to receive bytes of data serially and put them on PORTB. Set the baud rate at 9600, 8-bit data and 1 stop bit.

29 Example 3 (cont’d)

30 End of Chapter 3


Download ppt "Serial Communication Interface"

Similar presentations


Ads by Google