EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LPC 2148 - UART1 Error Characters obtain in Hyperterminal.

Started by mahaboob April 9, 2010
Hi Guys,

I am very new to LPC2148, I try to implement the UART1 for the serial communication. I am using the following code, which provide error characters in the Hyberterminal not the desired one. I need your Help.

regards,

Mahaboob.
#include "LPC214x.H"
#include

void UART1_Init(void);
void UART1_Write(char);
void delay(unsigned long int);

void main()
{
int i;
char s[]="UART1 Communication..";

UART1_Init();
//printf("HE IS THE ETERNAL\n");

while(1)
{
i=0;
while (s[i]!= '\0')
{
UART1_Write(s[i]);
delay(10000);
i++;
delay(10000);
}
}
}

void UART1_Init(void)
{
PINSEL0=0x00050000; /* Enable RxD0 and TxD0 */
U1FCR=0x07; /* Tx FIFO, Rx FIFO and FIFO eanable */
U1LCR=0x83; /* DLAB=1, Even Parity=1, WLS=7 bits */
U1DLL=0x82; /* Baud Rate */
U1DLM=0x00;
U1LCR=0x03;
}

void UART1_Write(char c)
{
delay(10000); // Delay
while(!(U1LSR & 0x20)); // Check U0LSR_bit.THRE for 1
U1THR=c;
}

void delay(unsigned long int count1)
{
while(count1 > 0) {count1--;}
}

An Engineer's Guide to the LPC2100 Series

--- In l..., "mahaboob" wrote:
>
> Hi Guys,
>
> I am very new to LPC2148, I try to implement the UART1 for the serial communication. I am using the following code, which provide error characters in the Hyberterminal not the desired one. I need your Help.
>
> regards,
>
> Mahaboob.

What crystal frequency?
What CCLK?
What PCLK?
What Baudrate?

You didn't set the Fractional Baudrate Divider so you would need a specific crystal of 14.7456 MHz. More likely, you have a 12 MHz crystal (to support USB) so, for most baudrates, there is no integer divisor that is sufficiently accurate. That's why NXP included the fractional divider hardware.

Assuming a crystal of 12 MHz, a CCLK of 60 MHz and a PCLK of 15 MHz, this code sets UART1 for 38400,n,8,1

void UART1_init(void)
{
PINSEL0 |= 0x05 << 16; // enable UART1 pins
U1LCR = 0x83; // 8,n,1 and turn on DLAB
U1DLM = 0x00;
U1DLL = 0x0D; // divide PCLK by 13
U1FDR = (8 << 4) + 7; // multiply by 8, divide by 8 + 7
U1LCR &= ~(0x80); // turn off DLAB
U1FCR = 0x07; // reset and enable FIFO, RX Trigger level 0 - 1 char
}

The calculation is detailed in the User Manual.

Now, as to Hyperterminal - it will always embarrass you. Your code can be perfect, the baudrate clock has zero error, every character is timed perfectly and STILL Hyperterminal displays junk. The number one reason why I like developing under Linux is that I hate Hyperterminal under Windows. You might try TeraTerm or almost anything else.

Richard


The 2024 Embedded Online Conference