Nothing Special   »   [go: up one dir, main page]

ARM Uart Theory

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

UART:

 ARM7 has 2 UARTS UART0 and UART1


 UART 0 is used as serial communication as well as
for on board Programming of ARM7
 UART 1 is used as serial communication only.
 16 byte buffer for UART0 and UART1
 Built in baud rate generator

U0RBR: Receive buffer register:(Serial buffer 8 bit)

The data received from uart0 pin is stored in this buffer.


The U0RBR is the top byte of the RX FIFO register
contains the oldest character received and can be read
(Receive) via bus interface,
U0THR: Transmit holding register:( 8 bit)
The top byte is the newest character in TX FIFO and can
be written (Transmit) via bus interface.
U0IER: Interrupt Enable register: 8 bit
Bit0:Rx data Enable
U0TER: Transmit Enable register: 8 bit
Bit7: Transmit Enable
Baud Rate generation formula:

So in order to get to get a baud rate of 9600 the values are


as follows:
Pclk 12 Mhz, Required Baud rate = 9600
9600 = 12000000/16(16*U0DLM+U0DLL)
16(16*U0DLM+U0DLL) = 12000000/9600
U0DLM+U0DLL = 78 / 256 = 4.9 =5
Assume U0DLM =0
So U0 DLL =5
U0LCR: Line Control Register

In the program , U0LCR = 03Hex


0:1 word length selection
So here we are selecting
8 bit data length , 1 stop bit ,Parity disabled
U0LSR:
U0LSR: LineLine Status
Status register
Register
U0LSR0 is set to 1 when U0RBR holds an unread
character and is cleared RX FIFO is empty.
UART program:
uint UART0Init( uint baudrate )
{
uint Fdiv;
PINSEL0 |= 0x00000005;// Enable RxD1 and TxD1, RxD0 and TxD0
00000000000000000000000000000101
Fdiv =( Fpclk / 16*16 ) / baudrate ;//(12000000/9600)/256= 5
U0DLM = Fdiv / 256; // 5
U0DLL = Fdiv % 256; // 0
U0LCR = 0x03; //8 bit character length
U0FCR = 0x07; // Clear and Enable TX and RX FIFO

U0IER = IER_RBR | IER_THRE | IER_RLS; // Enable UART0 interrupt


// RBR= Receive data available interrupt
//THRE= Transmit hold Register
//RLS= Receive line status
}
void UART0Handler (void) __irq //Serial Interrupt handler

if ( IIRValue == IIR_RLS ) /* Receive Line status */


//There are errors or break in interrupt
return

else if ( IIRValue == IIR_RDA ) /* Receive Data Available */


{
//New data available in U0RBR

DataBuffer[Uart0Count] = U0RBR; //Read the Character from


U0RBR into µC RAM (DataBuffer[Uart0Count])

Uart0Count++; //Increment µC RAM location


Rxcnt = RXCNT ; //Reload timer 200
RxFlag = 1 ; // Valid data has started
// RxFlag=1 && Rxcnt==0
}
Timer is running at 1 msec and if our baud rate is 9600 bits per
second then it comes to 1 msec per byte.
So, when we receive a byte from serial port we reload the timer for
200 msec time out.
If next data is received before time out (200 msec) then the timer is
again reset to time out.
If there is no data interrupt until time out (200 msec) then it is
assumed that the serial data is over and we can come out of Serial
interrupt service routine. (Rxcnt==0)
Serial Device
PC/RF/IR/FP etc.

RS232 Logic (+9v –9v) Baud rate =9600 ,8 bit

RS 232 driver IC

TTL Logic (0v - +5v ) Baud rate =9600 ,8 bit


µC
UART0 /1

Here the µC receives the data at the specified Baud rate 9600.
µC receives the data from URBR register (serial buffer) and
store the serial data in µC RAM.

You might also like