0% found this document useful (0 votes)
102 views39 pages

Unit3 - S5 UART

The document provides information about UART interfaces for ARM microcontrollers. It discusses UART registers including buffer registers, line control registers, baud rate registers, and status registers. It describes functions of the line control register including data bits, stop bits, and parity checking. The document also covers the divisor latch register, FIFO control register, transmit and receive blocks, and the line status register. It includes examples of UART initialization code, transmitting and receiving data, and controlling an LED using UART input. It concludes with several quiz questions about UART interfaces.
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)
102 views39 pages

Unit3 - S5 UART

The document provides information about UART interfaces for ARM microcontrollers. It discusses UART registers including buffer registers, line control registers, baud rate registers, and status registers. It describes functions of the line control register including data bits, stop bits, and parity checking. The document also covers the divisor latch register, FIFO control register, transmit and receive blocks, and the line status register. It includes examples of UART initialization code, transmitting and receiving data, and controlling an LED using UART input. It concludes with several quiz questions about UART interfaces.
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/ 39

Embedded Systems for IOT

Unit3: ARM Microcontroller Architecture Part2 &


Peripherals Interfacing-Part2
Session5 : UART Interface
Table of Contents
• UART Registers (continued from Unit3_S4 PinConnect)
• Interfacing UART
• Flashing hex to the target
• Working with terminal
• Quiz

Company Confidential www.industry-mitra.com 2


UART - Registers

1. Buffer Registers
2. Line control Register (Line/bus)
3. Baud rate Register
4. Status Register
Company Confidential www.industry-mitra.com 3
Line Control Register

Company Confidential www.industry-mitra.com 4


Parity checking
• Parity checking is used to eliminate data
communication errors
• Parity bit is appended to the data bits
• Types:
– even parity
– odd parity
• Ex:
• original data is 1010001 (there are three 1s)
• When even parity checking is used, a parity bit = 1
is appended, to make the number of 1s even in
transmitted data (11010001)
• if odd parity checking is used, then parity bit = 0
transmitted data (01010001)

Company Confidential www.industry-mitra.com 5


Divisor Latch Access bit
UART
Buffer Registers
0 Line Control register
[7] Divisor Latch Access bit
1
Baud rate Registers

LCD

Command Register 0
RS

Data Register 1

Company Confidential www.industry-mitra.com 6


Divisor Latch Register

Company Confidential www.industry-mitra.com 7


FIFO Control Register
• Both the UART’s have inbuilt 16byte FIFO for
Receiver/Transmitter
• Thus it can store 16-bytes of data received on UART
without overwriting
• If the data is not read before the Queue(FIFO) is filled
then the new data will be lost and the OVERRUN error
bit will be set
• Both blocks also contain 2 registers each, for data
access and assembly

Company Confidential www.industry-mitra.com 8


FIFO Control Register

• Bit 0: This bit is used to enable/disable the FIFO for the data
received/transmitted
• 0--FIFO is Disabled
• 1--FIFO is Enabled for both Rx and Tx
• Bit 1: This is used to clear the 16 byte Rx FIFO
• 0 – No impact
• 1 – clears Rx FIFO
• Bit 2: This is used to clear the 16 byte Tx FIFO
• 0 – No impact
• 1 – clears Tx FIFO

Company Confidential www.industry-mitra.com 9


FIFO Control Register

• Bit 6:7: RX trigger


• These bits are used to select the number of bytes of the
receiver data to be written so as to enable the interrupt
or DMA
• 00 – 1 character
• 01 – 4 characters
• 10 – 8 characters
• 11 – 14 characters

Company Confidential www.industry-mitra.com 10


Tx and Rx Block
• Tx block has THR(Transmit Holding Register) and
TSR(Transmit Shift Register)
• When we write Data to be sent into THR, it is then
transferred to TSR which assembles the data to be
transmitted via Tx Pin
• Rx block has RSR(Receive Shift Register) and
RBR(Receive Buffer Register)
• When a valid data is Received at Rx pin, it is first
assembled in RSR and then passed into Rx FIFO which
can be then accessed via RBR
• Tx block Rx block
Tx Rx
THR TSR RSR RBR

Company Confidential www.industry-mitra.com 11


Line Status Register

Company Confidential www.industry-mitra.com 12


Line Status Register

Company Confidential www.industry-mitra.com 13


Line Status Register

Company Confidential www.industry-mitra.com 14


Line Status Register

Company Confidential www.industry-mitra.com 15


Buffer Registers
THR (Transmit Hold Register)

U0THR=‘A’;

RBR(Receive Buffer Register)

char ch;
ch=U0RBR

Company Confidential 16
UART – Block Diagram

Company Confidential www.industry-mitra.com 17


Sample program
void init_uart0();
void init_uart0(){
PINSEL0=0x00000005; /p0.0 as Tx, P0.1 Rx
U0LCR=0x83;
U0DLM=0x00;
U0DLL=0x61;
Program to read and display text on uart terminal
U0LCR=0x03;
Develop the program in Keil IDE
}
Flash the hex file to the target
int main(){ Open flashmagic, tools → terminal
char ch; Specify the COM port, Baud rate as shown in the
init_uart0(); next slide
while(1){
while(!(U0LSR&0x01)); //chk whether receiver buffer is full or not
ch=U0RBR;
while(!(U0LSR&0x20)); //chk whether tr buff is empty
U0THR=ch;
}
}
Company Confidential www.industry-mitra.com 18
Sample program
• Show how to flash the hex file to the board
• Discuss the linker settings
• Flash the hex file using flash magic
• How to select the comport

Company Confidential www.industry-mitra.com 19


Flashmagic-Terminal

• Click ok to open the terminal, the terminal screen is in


the next slide
Company Confidential www.industry-mitra.com 20
Flashmagic-Terminal

• Type input in the input window


• Output will be displayed in the output window
Company Confidential www.industry-mitra.com 21
UART-Proteus

Company Confidential www.industry-mitra.com 22


Controlling led connected to p.0.4 via uart

//1 - led on
//2 - led off
#include <LPC21xx.H>
void init_uart0();
void init_uart0(){
PINSEL0=0x00000005;
U0LCR=0x83;
U0DLM=0x00;
U0DLL=0x61;
U0LCR=0x03;
}
void delay(int count){
int i,j;
for(i =0;i < count;i++)
for(j = 0;j < 5000;j++);
}

Company Confidential www.industry-mitra.com 23


Controlling led connected to p.0.4 via uart

int main(){
char ch;
IO0DIR=0xFF; //Set the Direction of Pin as out
IOCLR0=0xFF; //Set the Initial state as off
init_uart0();
while(1){
while(!(U0LSR&0x01)); //chk whether receiver buffer is full or not
ch=U0RBR;
if(ch=='1'){
IOSET0=1<<4;
}
if(ch=='2'){
IOCLR0=1<<4;
}
}
}

Company Confidential www.industry-mitra.com 24


Debug the following program
//uart0 transmitting and receiving
//Debug this program
#include <LPC21xx.H>
void init_uart0();

void init_uart0(){
PINSEL0=0x00000005;
U0LCR=0x83;
U0DLM=0x00;
U0DLL=0x61;
}
int main(){
char ch;
init_uart0();
while(1){
while(!(U0LSR&0x01)); //chk whether receiver buffer is full or not
ch=U0RBR;
while(!(U0LSR&0x20)); //chk whether tr buff is empty
U0THR=ch;
}
}

Company Confidential www.industry-mitra.com 25


Debug the following program
The previous code will not be able to
transmit/receive data since we have not provided
access to data registers
Provide access to data register using the below
instruction

U0LCR=0x03;

Company Confidential www.industry-mitra.com 26


Quiz - 1
Which of the following are both input/output
devices
a) Switch
b) LCD
c) UART
d) Both UART and LCD

Company Confidential www.industry-mitra.com 27


Quiz – 1 Answer
Which of the following are both input/output
devices
a) switch
b) LCD
c) UART
d) Both UART and LCD

Company Confidential www.industry-mitra.com 28


Quiz - 2
LPC2148 has
a) 1 UART
b) 2 UART’s
c) 3 UART’s
d) No UART interface

Company Confidential www.industry-mitra.com 29


Quiz – 2 Answer
LPC2148 has
a) 1 UART
b) 2 UART’s
c) 3 UART’s
d) No UART interface

Company Confidential www.industry-mitra.com 30


Quiz - 3
Which of the following is false w.r.t UART
a) It is a serial communication protocol
b) Data is transmitted as frames
c) A low stop bit indicates that serial communication
has ended
d) A low start bit indicates that serial communication
has started

Company Confidential www.industry-mitra.com 31


Quiz – 3 Answer
Which of the following is false w.r.t UART
a) It is a serial communication protocol
b) Data is transmitted as frames
c) A low stop bit indicates that serial
communication has ended
d) A low start bit indicates that serial communication
has started

Company Confidential www.industry-mitra.com 32


Quiz – 4
UART stands for
a) User Area Receiver/Transmitter
b) User Active Receiver/Transmitter
c) Universal Asynchronous Receiver/Transmitter
d) Universal Active Receiver/Transmitter

Company Confidential www.industry-mitra.com 33


Quiz – 4 Answer
UART stands for
a) User Area Receiver/Transmitter
b) User Active Receiver/Transmitter
c) Universal Asynchronous Receiver/Transmitter
d) Universal Active Receiver/Transmitter

Company Confidential www.industry-mitra.com 34


Quiz – 5
Which of the following is false
a) Transfer of data using parallel lines is faster than
serial
b) Serial communication is less costly than parallel
c) The start and stop bits are used in serial
communication
d) The start and stop bits are used in parallel
communication

Company Confidential www.industry-mitra.com 35


Quiz – 5 Answer
Which of the following is false
a) Transfer of data using parallel lines is faster than
serial
b) Serial communication is less costly than parallel
c) The start and stop bits are used in serial
communication
d) The start and stop bits are used in parallel
communication

Company Confidential www.industry-mitra.com 36


Quiz – 6
Which of the following is true w.r.to LCD
a) In LCD data is transmitted serially
b) In LCD data transmission is parallel, full duplex form
c) In LCD data transmission is parallel, the same bus is
used to transmit data and instructions, half duplex
d) In LCD there are two sets of data transmission
buses, one bus to transmit data and the other for
instructions

Company Confidential www.industry-mitra.com 37


Quiz – 6
Which of the following is true w.r.to LCD
a) In LCD data is transmitted serially
b) In LCD data transmission is parallel, full duplex form
c) In LCD data transmission is parallel, the same
bus is used to transmit data and instructions,
half duplex
d) In LCD there are two sets of data transmission
buses, one bus to transmit data and the other for
instructions

Company Confidential www.industry-mitra.com 38


Thank You

Company Confidential www.industry-mitra.com 39

You might also like