Forums

Help wanted for UART1 configuration LPC2388

Started by neliz_x May 6, 2009
Hello everybody,

Currently I'm doing some tests with a LPC2388 on the MCB2300 board from KEIL.
All of the code is written in Eclipse and compiled with the YAGARTO toolchain.

I want to display the results of the test in a hyperterminal session using UART1.
I've gone through several example programs, but I havent any luck in getting it to work,
no characters on appear on the terminal window.
It has cost a lot of time so far (2 weeks), and time is running out.

The only changes that are made to the sample code from the TN of NXP
is recalculating of reg. values found in UART1_Init()

I Appreciate the help!

Here is my PLL config and changed UART1_Init().
Please see http://www.standardics.nxp.com/support/documents/microcontrollers/pdf/tn05007.pdf
for the rest of the example code.

I've uploaded a zip with all of the source to my webpage:
http://members.lycos.nl/nelizx/HelloWorld.zip

void UART1_Init(void)
{
/* Fpclk = 18.000.000 MHz
(CPU clock(CCLK) = 72 MHz FpclkK/4 = 18 Mhz) */
// Select UART1 RXD/TXD --> From Technical Note, should be
PINSEL0 |= 0x00050000;

U1FCR = 7; // Enable and clear FIFO's
U1LCR = 0x83; // 8N1, enable Divisor latch bit
U1DLL = 0x4E; // baud rate fixed to 9600 @ PCLK = 18 Mhz
U1DLM = 0;
U1LCR = 3; // Disable Divisor latch bit
}

Function that is called from Startarm.S to initialize the clocks:
void Init_Clocks(void)
{
/* Start main oscillator */
SCS |= (1<<5);

while ((SCS & (1<<6)) == 0)
;

/* Select PLL as source */
CLKSRCSEL = 0x01;

/* Start PLL */
PLLCFG = 0x0000000B;
PLLFEED = 0xAA;
PLLFEED = 0x55;

PLLCON = 0x01;
PLLFEED = 0xAA;
PLLFEED = 0x55;

/* Wait until locked */
while ((PLLSTAT & (1<<26)) == 0)
;

/* Wait until M and N are correct */
while ((PLLSTAT & 0xFF7FFF) != 0x0000000B)
;

/* Setup CPU clock divider */
CCLKCFG = 3;

/* Setup USB clock divider */
USBCLKCFG = 5;

/* Setup Peripheral clock */
PCLKSEL0 = 0;
PCLKSEL1 = 0;

/* Switch to PLL clock */
PLLCON = 0x03;
PLLFEED = 0xAA;
PLLFEED = 0x55;

/* Make sure we are connected to PLL */
while ((PLLSTAT & (1<<25))==0)
;
}

An Engineer's Guide to the LPC2100 Series

--- In l..., "neliz_x" wrote:

> // Select UART1 RXD/TXD --> From Technical Note, should be
> PINSEL0 |= 0x00050000;

To complete the "should be" sentence from above:
PINSEL0 = 0x40000050 ; /* Enable TxD1 */
PINSEL1 |= 0x00000001; /* Enable RxD1 */

Fixed as below:

void UART1_Init(void)
{
/* Fpclk = 18.000.000 MHz
(CPU clock(CCLK) = 72 MHz FpclkK/4 = 18 Mhz) */

// Select UART1 RXD/TXD --> From Technical Note, should be
//PINSEL0 |= 0x00050000;

PINSEL0 |= 0x40000000; /* Enable TxD1 P0.15 */
PINSEL1 |= 0x00000001; /* Enable RxD1 P0.16 */

U1FCR = 7; // Enable and clear FIFO's
U1LCR = 0x83; // 8N1, enable Divisor latch bit
//U1DLL = 0x4E; // baud rate fixed to 9600 @ PCLK = 18 Mhz
//U1DLM = 0;
U1DLM = (( 18000000 / 16 ) / 9600) / 256; // baud rate fixed to 9600 @ PCLK = 18 Mhz
U1DLL = (( 18000000 / 16 ) / 9600) % 256;
U1LCR = 3; // Disable Divisor latch bit
}
----- Original Message -----
From: neliz_x
To: l...
Sent: Wednesday, May 06, 2009 4:57 PM
Subject: [lpc2000] Help wanted for UART1 configuration LPC2388

Hello everybody,

Currently I'm doing some tests with a LPC2388 on the MCB2300 board from KEIL.
All of the code is written in Eclipse and compiled with the YAGARTO toolchain.

I want to display the results of the test in a hyperterminal session using UART1.
I've gone through several example programs, but I havent any luck in getting it to work,
no characters on appear on the terminal window.
It has cost a lot of time so far (2 weeks), and time is running out.

The only changes that are made to the sample code from the TN of NXP
is recalculating of reg. values found in UART1_Init()

I Appreciate the help!

Here is my PLL config and changed UART1_Init().
Please see http://www.standardics.nxp.com/support/documents/microcontrollers/pdf/tn05007.pdf
for the rest of the example code.

I've uploaded a zip with all of the source to my webpage:
http://members.lycos.nl/nelizx/HelloWorld.zip

void UART1_Init(void)
{
/* Fpclk = 18.000.000 MHz
(CPU clock(CCLK) = 72 MHz FpclkK/4 = 18 Mhz) */

// Select UART1 RXD/TXD --> From Technical Note, should be
PINSEL0 |= 0x00050000;

U1FCR = 7; // Enable and clear FIFO's
U1LCR = 0x83; // 8N1, enable Divisor latch bit
U1DLL = 0x4E; // baud rate fixed to 9600 @ PCLK = 18 Mhz
U1DLM = 0;
U1LCR = 3; // Disable Divisor latch bit
}

Function that is called from Startarm.S to initialize the clocks:
void Init_Clocks(void)
{
/* Start main oscillator */
SCS |= (1<<5);

while ((SCS & (1<<6)) == 0)
;

/* Select PLL as source */
CLKSRCSEL = 0x01;

/* Start PLL */
PLLCFG = 0x0000000B;
PLLFEED = 0xAA;
PLLFEED = 0x55;

PLLCON = 0x01;
PLLFEED = 0xAA;
PLLFEED = 0x55;

/* Wait until locked */
while ((PLLSTAT & (1<<26)) == 0)
;

/* Wait until M and N are correct */
while ((PLLSTAT & 0xFF7FFF) != 0x0000000B)
;

/* Setup CPU clock divider */
CCLKCFG = 3;

/* Setup USB clock divider */
USBCLKCFG = 5;

/* Setup Peripheral clock */
PCLKSEL0 = 0;
PCLKSEL1 = 0;
/* Switch to PLL clock */
PLLCON = 0x03;
PLLFEED = 0xAA;
PLLFEED = 0x55;

/* Make sure we are connected to PLL */
while ((PLLSTAT & (1<<25))==0)
;
}



Thank you so much Frank! This indeed solved the problem :-D :-D
Could you explain to me why the Pclk has to be devided by 16 first and them by the baudrate?

Did I misinterpreted the usermanual on how to calculate those values?
Thanks again for the help.

--- In l..., "frank" wrote:
>
> Fixed as below:
>
> void UART1_Init(void)
> {
> /* Fpclk = 18.000.000 MHz
> (CPU clock(CCLK) = 72 MHz FpclkK/4 = 18 Mhz) */
>
> // Select UART1 RXD/TXD --> From Technical Note, should be
> //PINSEL0 |= 0x00050000;
>
> PINSEL0 |= 0x40000000; /* Enable TxD1 P0.15 */
> PINSEL1 |= 0x00000001; /* Enable RxD1 P0.16 */
>
> U1FCR = 7; // Enable and clear FIFO's
> U1LCR = 0x83; // 8N1, enable Divisor latch bit
> //U1DLL = 0x4E; // baud rate fixed to 9600 @ PCLK = 18 Mhz
> //U1DLM = 0;
> U1DLM = (( 18000000 / 16 ) / 9600) / 256; // baud rate fixed to 9600 @ PCLK = 18 Mhz
> U1DLL = (( 18000000 / 16 ) / 9600) % 256;
> U1LCR = 3; // Disable Divisor latch bit
> }