EmbeddedRelated.com
Forums

UART initialisation?

Started by Leon Heller April 26, 2007
I'm trying to get output from UART0 using this very simple
initialisation code, and am not getting anything transmitted. Can
anyone see what I'm doing wrong.
void Initialise(void)
{
// initialise PLL
PLL0CFG=0x24; // Cclk = 60Mhz
PLL0CON=0x01;
PLL0FEED=0xAA;
PLL0FEED=0x55;
while(!(PLL0STAT & 0x0400)) ;
PLL0CON=0x3;
PLL0FEED=0xAA;
PLL0FEED=0x55;
// initialise MAM and VPB
MAMTIM=0x3; // 3 cycles to read from FLASH
MAMCR=0x2;
APBDIV=0x02; // Pclk = 30MHz
U0LCR = 0x83; // set DLAB. 8N1
U0DLL = 0xC3; // set for 9600 Baud
U0DLM = 0x00; // set for 9600 Baud
U0LCR &= ~0x80; // Disable DLAB
PINSEL0 = PINSEL0 & (~0xF)| 0x5; // enable UART0 pins
}

Leon

An Engineer's Guide to the LPC2100 Series

--- In l..., "Leon Heller" wrote:
>
> I'm trying to get output from UART0 using this very simple
> initialisation code, and am not getting anything transmitted. Can
> anyone see what I'm doing wrong.
> void Initialise(void)
> {
> // initialise PLL
> PLL0CFG=0x24; // Cclk = 60Mhz
> PLL0CON=0x01;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
> while(!(PLL0STAT & 0x0400)) ;
> PLL0CON=0x3;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
> // initialise MAM and VPB
> MAMTIM=0x3; // 3 cycles to read from FLASH
> MAMCR=0x2;
> APBDIV=0x02; // Pclk = 30MHz
> U0LCR = 0x83; // set DLAB. 8N1
> U0DLL = 0xC3; // set for 9600 Baud
> U0DLM = 0x00; // set for 9600 Baud
> U0LCR &= ~0x80; // Disable DLAB
> PINSEL0 = PINSEL0 & (~0xF)| 0x5; // enable UART0 pins
> }
>
> Leon
>

Please disregard this! I was calling the initialisation function after
the output statements. UART0 output is working, but the baud rate
seems to be worng for some reason.

Leon
Hi Leon

I assume from the PLL config you're using a 12Meg clock and latching it up
to 60Meg? If so, all the settings look fine although i'm unsure why you've
called the VPBDIV register APBDIV. Typo? Or could you in fact be running
your pclk at the default settings for VPBDIV and thereby seeing the wrong
uart baud rates?

Andy

-----Original Message-----
From: l... [mailto:l...]On Behalf Of
Leon Heller
Sent: 26 April 2007 15:26
To: l...
Subject: [lpc2000] Re: UART initialisation?
--- In l..., "Leon Heller" wrote:
>
> I'm trying to get output from UART0 using this very simple
> initialisation code, and am not getting anything transmitted. Can
> anyone see what I'm doing wrong.
>
>
> void Initialise(void)
> {
> // initialise PLL
> PLL0CFG=0x24; // Cclk = 60Mhz
> PLL0CON=0x01;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
> while(!(PLL0STAT & 0x0400)) ;
> PLL0CON=0x3;
> PLL0FEED=0xAA;
> PLL0FEED=0x55;
> // initialise MAM and VPB
> MAMTIM=0x3; // 3 cycles to read from FLASH
> MAMCR=0x2;
> APBDIV=0x02; // Pclk = 30MHz
>
>
> U0LCR = 0x83; // set DLAB. 8N1
> U0DLL = 0xC3; // set for 9600 Baud
> U0DLM = 0x00; // set for 9600 Baud
> U0LCR &= ~0x80; // Disable DLAB
> PINSEL0 = PINSEL0 & (~0xF)| 0x5; // enable UART0 pins
> }
>
> Leon
>

Please disregard this! I was calling the initialisation function after
the output statements. UART0 output is working, but the baud rate
seems to be worng for some reason.

Leon
----- Original Message -----
From: "Andy Berney"
To:
Sent: Thursday, April 26, 2007 4:02 PM
Subject: RE: [lpc2000] Re: UART initialisation?
> Hi Leon
>
> I assume from the PLL config you're using a 12Meg clock and latching it up
> to 60Meg? If so, all the settings look fine although i'm unsure why you've
> called the VPBDIV register APBDIV. Typo? Or could you in fact be running
> your pclk at the default settings for VPBDIV and thereby seeing the wrong
> uart baud rates?

Thanks. There was actually nothing wrong with the code, I was calling it
*after* the serial I/O stuff, so the initialisation wasn't actually
happening! What I thought was a baud rate problem was Bray terminal not
working properly, it was OK with RealTerm. For some reason CrossWorks uses
APBDIV instead of VPBDIV in the header file.

Leon