free 8051 Microcontroller Projects AVR PIC Microcontroller Projects Tutorials Ebooks Libraries, interfacing tutorials, lcd tutorial, stepper motor, dc motor 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems
PCLK is the clock frequency generated from the PLL DLM & DLL each are 8 bit registers required to divide the clock to desired frequency.... for further fine tuning of the baud rate we have DivAddVal and mulVal registers
The UART0 Divisor Latch is part of the UART0 Fractional Baud Rate Generator and holds the value used to divide the clock supplied by the fractional prescaler in order to produce the baud rate clock, which must be 16x the desired baud rate (Equation 9–1). The U0DLL and U0DLM registers together form a 16 bit divisor where U0DLL contains the lower 8 bits of the divisor and U0DLM contains the higher 8 bits of the divisor. A 0x0000 value is treated like a 0x0001 value as division by zero is not allowed
assuming PCLK = 60Mhz assuming no fine tuning required... for a baud rate of 115200 lets find out the values of DLL and DLM remember it will be easier if ou consider DLL and DLM a single 16 bit register instead of 2 8 bit register .. with the higher byte going to DLM
=> (256*U0DLM+U0DLL) = 60,000,000/(16*115200) = 32.552 =>0x0020 hex => DLM = 0x00 DLL = 0x20 so we can calculate the values required for any baud rate!!!! try out to find the maximum baud rate you can generate in LPC214X (remember division by zero not possible in LPC214x ... the zero in final expression(denominator) will automatically be taken as +1).
consider the following funtion void init_uart0(void)
u will find a new register U0LCR refer manual u will find =>
bit7 DLAB bit6 Set Break bit5 StickParity bit4 EvenPar.Selct. bit3 ParityEnable bit2 No. ofStop Bits bit1 bit0 Word Length Select
for 8 bit no parity 1 stop bit... from manual bit0 =1 bit1 =1 bit 2 =0 bit 3=0 bit 7 (dlab) =1 => U0LCR =0x83 or U0LCR =0x80 ; U0LCR=0x03;
The Divisor Latch Access Bit (DLAB) in U0LCR must be zero in order to access the U0THR(transmit hold register)/U0RBR (receive buffer register) and must be one when updating values of DLL DLM....
so we have...
CODE:
void init_uart0(void) {
U0LCR =0;// DLAB = 0
U0LCR =0x80;// DLAB = 1
U0DLM =0x00;// DLM = 0x00
U0DLL =0x20;// DLL = 0x20, Divisor = 32, set baudrate=115200
U0LCR =0x03;// DLAB = 0, No parity, 8 data, 1 stop } int putchar (int ch)/* Write character to Serial Port */ { if(ch =='\n') { while(!(U0LSR &0x20));
U0THR = CR;/* output CR */ } while(!(U0LSR &0x20)); return(U0THR = ch); } int getchar (void)/* Read character from Serial Port */ { while(!(U0LSR &0x01)); return(U0RBR); }
we will next discuss the above code!! till then bye :bye
for users referring to user manual for lpc214x series please note: PLL in all above discussion shall be veiwed as PLL0 similarly all registers will change ex PLLCFG =>PLL0CFG PLLCON =>PLL0CON the second PLL will be discussed under the topic USB!! till then no mention of PLL1 registers also the name of registers may change according to the header files used ex. most lpc210x.h headers will have SCB_PLLCFG instead of PLLCFG.
[ Edited Sat Dec 29 2007, 10:09AM ] lProgress is not made by early risers or hard workers, but by LAZY people, trying to find easier ways to do the same........
8051 Microcontroller Projects 8051 AVR tutorials PIC microcontroller, 8051 assembly language programming electronics and communication ECE CSE pdf ebooks library BE final year project ideas Embedded systems