## uart0 is not working

Started by 3 years ago9 replieslatest reply 3 years ago89 views
Dear all,
I am new to LPC2378 (#LPC2300). Currently i am developing code for sending a character in serial port....Below i mentioned the code what i have written..but this is not working...i am using keil uvision3...Can anybody help me in this code????In my hardware DB 9 connectors rxd and txd are connected together(loopback test)

This is my code...
#include <LPC23xx.H>
#include <stdio.h>
void delay(int);
int main (void)
{

PCONP |= (1<<3) /* power for uart 0 */
PINSEL0 |= 0x00000050; /* Enable TxD0 *//* Enable RxD0 */
U0LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */
U0DLM = 0x00;
U0DLL = 0x78; /* 9600 Baud Rate @ 12MHz Clock */
U0FDR = 0xA3;
U0LCR = 0x03; /* DLAB = 0 */
U0FCR = 0x81;

while(1)
{
U0THR = 'A';
while (!(U0LSR & 0x40));
}
[ - ]

Hi Appujohn,

You need to find answers to following questions to know if your program is right or wrong.

What is the crystal frequency in your system?

What is the CCLK value in your system? You need to look at you PLL Config values to check this.

What is the PCLK_UART0 value?

In LPC 2378, the crystal frequency, is fed into a PLL. Based on your PLL configuration, a processor clock is generated. This clock is then divided to get UART0 clock. Using UART0 clock, U0DLL and U0DLM value are calculated.

Note: You will be doing your calculations for U0DLL and U0DLM in decimal numbers. You can write them directly to registers without "0x" like I am showing below. If you want to write them in hexadecimal format (with 0x), you need to convert your computed values to hexa decimal.

U0DLL = <your decimal value>;
[ - ]

Hello maruthi,

XTAL=12MHZ

PLL=288MHZ;

PROCESSOR CLOCK=48MZ;

PHERPHERAL CLOCK=12MHZ.

U0DLL=78;

[ - ]

Are you having difficulties with the editor?  Why so many spaces?  Why not something like:

Hello maruthi,

XTAL=12MHZ

PLL=288MHZ;

PROCESSOR CLOCK=48MZ;

PHERPHERAL CLOCK=12MHZ.

U0DLL=78;

[ - ]

Hello,

I just had a quick look at your code, so take what I'm saying with a grain of salt.  One thing I don't see is how you set the PCLKSEL0 register.  It sets (among other things) the input clock of UART0 (PCLK_UART0).

At reset, PCLKSEL0 is set to have PCLK_UART0 = CCLK/4, where CCLK is the CPU clock.  Therefore, if you say your UART0 clock is 12MHz, your CPU clock should be 48MHz.  Is this right?

Regards,
Ivan

[ - ]

Hi,

A guess, looks like U0DLM shall be decimal 78 not hex 0x78.

you can download the code for LPC2378 Sample Code Bundle for LPC23xx/LPC24xx Peripherals using Keil's μVision

Regards,

Sudheer

[ - ]

Hi,

Thank you

U0DLL=78;

[ - ]

As a followup to the reply by maruthi.hr, let me describe the LPC2378 clock tree in some more detail (for what concerns the UART0 clock).  Have a look at Fig. 16 of the LPC23xx User Manual for the full story.

*1*: The LPC2378 can have up to three possible clock sources:
- Internal RC (IRC) oscillator, @4MHz nominally
- Crystal-controlled Real-Time Clock (RTC), @32768Hz nominally
- Crystal-controlled Main Oscillator (OSC), often running @12MHz

These sources are individually enabled and controlled by their own registers.  For instance, OSC is controlled by part of the SCS register.

*2*: One of these sources is fed to the on-chip PLL input by means of the CLKSRCSEL register.  The output frequency of the PLL is then determined by the PLLCON, PLLCFG, PLLSTAT, and PLLFEED registers.

*3*: The PLL output is divided by the value specified in the CCLKCFG register to obtain the CPU clock CCLK.

*4*: To generate peripheral clocks (for instance, PCLK_UART0) CCLK is divided by an integer number specified in the PCLKSEL0 and PCLKSEL1 registers.

The starting frequency for baud rate calculation is PCLK_UART0 and it depends on how all these things have been set up.  This is the reason why it's hard to tell whether the values in your code are right or not.

Regards,
Ivan

[ - ]

Thanks Ivan,

it really helped me to understand the concept.Thanks a lot.

XTAL=12MHZ

PLL=288MHZ;

PROCESSOR CLOCK=48MZ;

PHERPHERAL CLOCK=12MHZ.

U0DLL=78;

[ - ]