UART - Universal Asynchronous Receiver Transmitter
UART - Universal Asynchronous Receiver Transmitter
UART - Universal Asynchronous Receiver Transmitter
Asynchronous
Receiver Transmitter
CONTENTS
Introduction to UART
Basic
Transmitter
block of UART
Receiver block
Programming of UART
Applications
TRANSMISSION REQUIREMENT
PC
7
7
10
Pin Symbol
Function
CD
Carrier Detect: It is used by Modem to inform PC that it has detected Carrier on Phone
Line.
RD
TD
DTR
SG
It is signal ground with reference to which voltages are interpreted as high or low.
DSR
RTS
Request to Send.
Request to send is sent from (DTE) terminal (PC) to modem (DCE) to inform it that PC
wants to send some data to modem.
CTS
Clear To Send.
Upon received RTS from DTE (PC), the modem (DCE) asserts CTS high whenever it is
ready to receive data.
RI
Ring Indicator.
It is set by modem to indicate the PC that a ringing signal has been detected on line.
11
12
13
UART/USART TRANSMITTER
14
TRANSMITTER CONTD.
TXIF bit : in the PIR1 register
It cannot be cleared in software. It will reset only when new data is loaded
into the TXREG register.
TRMT bit:
Once the data in the TSR register has been clocked out on the TX pin(at
the beginning of the STOP bit), the TRMT bit in the TXSTA register will be
set,
UART/USART RECIEVER
1. The clock of the receiver is a multiple of the bit rate, in PIC 16f877A,its x16
or x64. So, each bit is transmitted/received in 16 clock cycle.
2. If the receiver detects a start bit for a period= bit period (16 clock cycles),
then it waits for the period of half bit, and then sample the value on the RX
pin and shift it in the receiving shift register.
16
RECEIVER CONTD.
3. Every received bit is sampled at the middle of the bits time period.
4. The USART can be configured to receive eight or nine bits by the RX9 bit in the
RCSTA register.
5. After the detection of a START bit, eight or nine bits of serial data are shifted
from the RX pin into the Receive Shift Register, one bit at a time.
6. After the last bit has been shifted in, the STOP bit is checked and the data is
1 bit time
mark
space
Tim
e
18
UART REGISTERS
To use and control the UART, special internal registers are assigned to them. Usually there
will be at least four registers: control, status, receive and transmit registers. All these vary
in size depending on the MCU.
1) Control Register - Contains settings for the UART. Some common settings/features
include: Number of data bits, number of stop bits, parity control, UART TX/RX
enable/disable,
baud
rate
setting,
RX/TX
interrupt
enable,
etc.
2) Status Register - From its name, this contains information about the UART's condition
or state. During run-time, this register may be helpful in guiding the processor on the next
instruction to execute like when to retrieve data. Information that can be retrieved include:
data
send/receive
ready,
etc.
3) Receive Register - This is the where received data is temporarily stored.
4) Transmit Register - A buffer register/s for temporarily storing data to be sent.
19
UART INTERFACING
20
UART ALTERNATIVES
Becoming much less common
Largely been replaced by faster, more sophisticated interfaces
PCs: USB (peripherals), Ethernet (networking)
Still used today when simple low speed communication is needed
21
PORTB=0;
SPBRG=51;
TXSTA=0B00100010;
RCSTA=0B10010000;
TXREG=0X0;
while(!TRMT);
while(!RCIF);
PORTB=RCREG;
for(i=0;i<3000;i++)
}
while(1);
}
22
APPLICATIONS
Communication between distant computers
Serializes data to be sent to modem
De-serializes data received from modem
Serial
Cable
Phone
Line
Phone
Line
Serial
Cable
Modem
Modem
23
APPLICATIONS CONTD.
PC serial port is a UART!
Serializes data to be sent over serial cable
De-serializes received data
This determines the speed at which data is transmitted and received. One baud is
one bit per second (bps).
With modern UARTs, 230,400 baud can be achieved with a short cable length
of a few feet.
Seri
al
Cabl
e
Seri
al
Port
Serial
Cable
Seri
al
Port
Devic
e
24
SUMMARY
To make asynchronous connection using the PICs USART:
At the Transmitter end:
1. Determine the value of the SPBRG register and the BRGH-bit according to the
required baud rate.
2. The SYNC-bit [TXSTA<4>] is cleared, SPEN-bit [RCSTA<7>] is set to enable the
serial port.
3. On 9-bit data transmission, the TX9-bit [TXSTA<6>] is set.
4. TXEN-bit [TXSTA<5>] is set to enable data transmission.
5. On 9-bit data transmission, value of the ninth bit should be written to the TX9D-bit
[TXSTA<0>].
6. Transmission can be started again by writing 8-bit data to the TXREG register,
25
usually wait for at least (1ms) between every two writes.
SUMMARY CONTD.
At the Receiver end:
1.Determine the value of the SPBRG register and the BRGH-bit according to the
required baud rate.
2.The SYNC-bit [TXSTA<4>] is cleared, SPEN-bit [RCSTA<7>] is set to enable the
serial port.
3.On 9-bit data receive, the RX9-bit [RCSTA<6>] is set.
4.Data receive should be enabled by setting the CREN-bit [RCSTA<4>].
5.The RCSTA register should be read to get information on possible errors which have
occurred during transmission.
6.On 9-bit data receive, the ninth bit will be stored in RX9D-bit [RCSTA<0>].
7.Received 8-bit data stored in the RCREG register should be read.
26