0% found this document useful (0 votes)
15 views

Unit 3 UART

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

Unit 3 UART

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

Go, change the

RV College world
of
Engineering
Course Code:CS344AI
IOT & Embedded Computing

Programming LPC 2148 UART[Serial Port] Programming


RV College
of Go, change the
Engineerin
g world
RV College
of Go, change the
Engineerin
g world
LPC 2148 UART0 & UART1 Unit...
RV College
of Go, change the
Engineerin
g world
LPC 2148 UART0 & UART1 Unit...
RV College
of Go, change the
Engineerin
g world
Asynchronous Serial Data Format...
RV College
of Go, change the
Engineerin
g world
RS 232 Interface
RV College
of Go, change the
Engineerin
g world

UART Registers..

Register Description
UxRBR Contains the recently received Data
UxTHR Contains the data to be transmitted
UxFCR FIFO Control Register
UxLCR Controls the UART frame formatting(Number of Data Bits, Stop bits)
UxDLL Least Significant Byte of the UART baud rate generator value.
UxDLM Most Significant Byte of the UART baud rate generator value.
UxLSR Line status register, used to check transmitter is free / Receiver has data
RV College
of Go, change the
Engineerin
g world

Example: U0LCR = (0x03<<0) | (1<<7); 8bit data, 1Stop bit, No parity


RV College
of Go, change the
Engineerin
g world
RV College
of Go, change the
Engineerin
g world

BaudRate Calculation..
RV College
of Go, change the
Engineerin
g world

Configure UART for 115200 baud rate, PCLK = 15MHz


Calculation:
DLM:DLL = 15000000 / 16 * (115200) = result
Hence, DLL = result % 256 = 8 (lower 8 bits of result)
DLM = result / 256 (upper 8 bits of result)
(or , use calculator, convert answer in decimal to HEX, take lower two digits put into DLL, next two digits to DLM)

void uart_init(void)
{
//configurations to use serial port, UART0
PINSEL0 |= 0x00000005; // P0.0 & P0.1 ARE CONFIGURED AS TXD0 & RXD0
//programming the baud rate
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit & DLAB = 1 */
U0DLM = 0; U0DLL = 8; // 115200 baud rate, PCLK = 15MHz
U0LCR = 0x03; /* 8 bits, no Parity, 1 Stop bit & DLAB = 0 */
}
RV College
of Go, change the
Engineerin
g world

Write a Program to transmit a string from LPC 2148 to PC using


Serial port / UART0
int main()
{
unsigned char i=0,ch,msg[]={"RVCE-CSE"};
SystemInit(); // set PCLK = 15MHz
uart_init(); // refer previous explanation

while((ch=msg[i++])!= '\0')
{
// Wait for Previous transmission to complete
while((U0LSR & (1u<<5))== 0x00){};
// Load the data to be transmitted
U0THR= ch;
}
}
RV College
of Go, change the
Engineerin
g world

Write a Program to transmit a string from LPC 2148 to PC using


Serial port / UART0
RV College
of Go, change the
Engineerin
g world

Write a Program to receive a character from PC and output the


8 bit data on P0.16 to P0.23.
int main()
{
unsigned char i=0;
SystemInit();
uart_init();

IO0DIR = 0XFF << 16; // configure P0.16 to P0.23 as output pins


do
{
while((U0LSR & (0x01<<0))== 0x00){}; // wait till, a character (8bit) is received from PC
i = UORBR; // read from the UART0
IO0CLR = 0XFF << 16;IO0SET = U0RBR << i; // output the i(8bit code) to P0.16 – P0.23
}
while(1);
}
RV College
of Go, change the
Engineerin
g world

Write a Program to receive a character from PC and output the


8 bit data on P0.16 to P0.23.

You might also like