0% found this document useful (0 votes)
13 views25 pages

Ch5 UART

Uploaded by

navena1606
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views25 pages

Ch5 UART

Uploaded by

navena1606
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

APPLICATION OF

MICROCONTROLLER
EC501

TOPIC 6: HARDWARE INTERFACING – Serial Communication (UART)


Lecture: En. King Diaw A/L Eh Sut
JAB. KEJ. ELEKTRIK
PTSS
CHAPTER 6

SERIAL COMMUNICATION
PROTOCOL
Outline
 SERIAL COMMUNICATION PROTOCOL
◼ Basic Serial Communication
◼ USART

4 February, 2024 KingDiaw 3


Basic Serial Communication

4 February, 2024 KingDiaw 4


Basic Serial Communication
Communication Method

1 2
SYNCHRONOUS ASYNCHRONOUS
transfers a transfers a single
BLOCK BYTE
of data at a time at a time
use has NO
SEPARATE CLOCK SEPARATE CLOCK
and DATA LINE accompanying the data

4 February, 2024 KingDiaw 5


Basic Serial Communication
Data Transmission

4 February, 2024 KingDiaw 6


USART
>>Asynchronous Serial Data Formats

4 February, 2024 KingDiaw 7


RS232 Standard
 Was set by the Electronics Industries Association (EIA) in 1960,
before the advent of TTL logic family.
 Therefore, logic 1 is represented by “-3 to -25V”, and logic 0 is “+3
to +25V”.
 Two types of RS232 pins: DB-25 and DB-9. Most important pins
are Tx, Rx, and ground.
 To interface with PIC, we need line driver such as MAX232 (need
capacitors) or MAX233 (no capacitors).

4 February, 2024 KingDiaw 8


USART
>>PIC18 Connection to RS232

4 February, 2024 KingDiaw 9


Rehat Sebentar…
 “Life is like riding a bicycle. To keep
your balance you must keeping
moving”
-Albert Einstein

4 February, 2024 mfauzi 10


PIC18F Connection to RS232
(continue…)

4 February, 2024 KingDiaw 11


USART
>>PIC18F4520 USART REGISTER
 Normal USART has 6 major register:
◼ SPBRG (serial port baud rate generator)
◼ TXREG (Transfer register BUFFER)
◼ RCREG (Receive register BUFFER)
◼ TXSTA (Transmit status and control register)
◼ RCSTA (Receive status and control register)
◼ PIR1 (peripheral interrupt request register 1)

 In EUSART (e.g: PIC18F4520/4550) has extra register involve


i.e.: BAUDCON (Baud rate control)
4 February, 2024 KingDiaw 12
EUSART
 The Enhanced USART module implements additional features,
including:
◼ automatic baud rate detection and calibration
◼ automatic wake-up on Sync Break reception
◼ 12-bit Break character transmit.

 These make it ideally suited for use in Local Interconnect Network


bus (LIN bus) systems.

4 February, 2024 KingDiaw 13


TXSTA
Transmit
Status
and
Control
Register

4 February, 2024 mfauzi 14


RCSTA
Receive
Status
and
Control
Register

4 February, 2024 mfauzi 15


BAUDCON
Baud Rate
Control
Register

4 February, 2024 mfauzi 16


Baud Rate Generator (BRG)
 The BRG is a dedicated 8-bit or 16-bit generator that supports
both the Asynchronous and Synchronous modes of the EUSART.
 By default, the BRG operates in 8-bit mode; setting the BRG16 bit
(BAUDCON<3>) selects 16-bit mode.
 The SPBRGH:SPBRG register pair controls the period of a free
running timer.
 In Asynchronous mode, bits BRGH (TXSTA<2>) and BRG16
(BAUDCON<3>) also control the baud rate.
 In Synchronous mode, BRGH is ignored.

4 February, 2024 KingDiaw 17


Baud Rate Formula
High Baud Rate Select

WE ONLY
FOCUS THIS
PART

4 February, 2024 KingDiaw 18


Calculating the Baud Rate Error

4 February, 2024 KingDiaw 19


Baud Rate for Asynchronous Mode
FOR 8-bit Baud Rate

4 February, 2024 KingDiaw 20


RCIF and TXIF Bit

4 February, 2024 KingDiaw 21


Asynchronous Transmission
Programming
• Load TXSTA = 0x20 for asynchronous mode, 8-bit data
1 frame, low baud rate, and transmit enabled.

• Make Tx pin (RC6) an output


2

• Configure BRG16 in BAUDCON to select 8-bit and then


3 set baud rate by loading SPBRG

4 February, 2024 KingDiaw 22


Asynchronous Transmission Setup
• Enable the entire Serial Port (SPEN) in RCSTA
4

• Put character byte into TXREG buffer


5

• Monitor TXIF bit of PIR1 to make sure UART is ready for


6 next byte.

• Go to step 5 to transfer next character


7

4 February, 2024 KingDiaw 23


Asynchronous Reception Programming
• Load RCSTA = 0x90 to enable receiving 8-bit data size.
OR configure [RCSTAbits.SPEN=1; and
1 RCSTAbits.CREN = 1;]

• Configure BRGH. Set TXSTA= 0x00 for low baud rate


2 option (BRGH = 0).

• Configure BRG16 in BAUDCON to select 8-bit and then


3 set baud rate by loading SPBRG

4 February, 2024 KingDiaw 24


Asynchronous Reception Setup
• Make Rx pin (RC7) an input
4

• Monitor RCIF.
5

• If RCIF == 1, move RCREG content into safe place


6

• Go to step 5 to receive the next character


7

4 February, 2024 KingDiaw 25

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy