Problem with LPC2378 UART

Started by jkasinathan February 13, 2011
Problem regarding UART1 in LPC2378.

I am using LPC2378 microcontroller. Programming uart1 for communication.
Using P2.0 for TXD1 and P2.1 for RXD1. The initialization section of the code is given below.

Using Crystal clock 12MHz, Baud rate is 9600 bps.

PINSEL10 = 0X000000000; //To disable the ETM interface.
PINSEL4 = 0X0000000a; //select TXD1 and RXD1 lines
IO0DIR = 0x00000400; //making txd1 as o/p
U1LCR = 0X00000083; //enable baud rate divisor loading and
//select the data format
U1DLM = 0X00;
U1DLL = 0x0C; //select baud rate 9600 bps

U1LCR = 0X00000003; //Disabling DLAB

U1FDR = 0X85; //DIVADDVAL = 8, MULVAL=5.

U1FCR = 0x07; //FIFO enable

U1IER = 0X03; //Enable RX Line Status Interrupt, Enable THRE Interrupt, Enable RX Data Available Interrupt.

VICVectAddr7 = (unsigned long)uart1_interrupt;
VICVectPriority7 = 0x00; // Highest priority
VICIntEnable = 0x00000080; // Enable the uart1 interrupt

Calculated the baud rate as follows.

UARTnbaudrate = pclk / 16 X (256 X UnDLM + UnDLL)

9600 = (12MHz/4) / 16 X (256 X UnDLM + UnDLL)
Taking UnDLM = 0.
UnDLL = 3MHz / 16X 9600
UnDLL = 19.531
And calculated the Fraction correction using the table given in the datasheet.
Got the values as UnDLM = 0x00, UnDLL = 0x0C, DIVADDVAL = 5, MULVAL=8.

Testing using Hyperterminal One Program written to transmit a character and the second written to receive a character from the PC and loop it back to the PC . In both cases I am getting both transmit and receive interrupts , but the data displayed is junk
Hyperterminal is OK as the the connector loopback is working fine

Would be much obliged if someone could tell me where the problem is
Jayaraman .K

An Engineer's Guide to the LPC2100 Series

--- In l..., "jkasinathan" wrote:
>
> Problem regarding UART1 in LPC2378.
>
> I am using LPC2378 microcontroller. Programming uart1 for communication.
> Using P2.0 for TXD1 and P2.1 for RXD1. The initialization section of the code is given below.
>
> Using Crystal clock 12MHz, Baud rate is 9600 bps.
>
> PINSEL10 = 0X000000000; //To disable the ETM interface.
> PINSEL4 = 0X0000000a; //select TXD1 and RXD1 lines
> IO0DIR = 0x00000400; //making txd1 as o/p
> U1LCR = 0X00000083; //enable baud rate divisor loading and
> //select the data format
> U1DLM = 0X00;
> U1DLL = 0x0C; //select baud rate 9600 bps
>
> U1LCR = 0X00000003; //Disabling DLAB
>
> U1FDR = 0X85; //DIVADDVAL = 8, MULVAL=5.
>
> U1FCR = 0x07; //FIFO enable
>
> U1IER = 0X03; //Enable RX Line Status Interrupt, Enable THRE Interrupt, Enable RX Data Available Interrupt.
>
> VICVectAddr7 = (unsigned long)uart1_interrupt;
> VICVectPriority7 = 0x00; // Highest priority
> VICIntEnable = 0x00000080; // Enable the uart1 interrupt
>
> Calculated the baud rate as follows.
>
> UARTnbaudrate = pclk / 16 X (256 X UnDLM + UnDLL)
>
> 9600 = (12MHz/4) / 16 X (256 X UnDLM + UnDLL)
> Taking UnDLM = 0.
> UnDLL = 3MHz / 16X 9600
> UnDLL = 19.531
> And calculated the Fraction correction using the table given in the datasheet.
> Got the values as UnDLM = 0x00, UnDLL = 0x0C, DIVADDVAL = 5, MULVAL=8.
>
> Testing using Hyperterminal One Program written to transmit a character and the second written to receive a character from the PC and loop it back to the PC . In both cases I am getting both transmit and receive interrupts , but the data displayed is junk
> Hyperterminal is OK as the the connector loopback is working fine
>
> Would be much obliged if someone could tell me where the problem is
> Jayaraman .K
>
I didn't get the same values for DIVADDVAL and MULVAL. I'm probably wrong...

Just for fun, try 115200 baud as the example is given in the user manual. Two things will happen: First, you can use the values given and test the UART at 115200 and, second, you can use the calculation process and see if you get the same values.

Richard

Your calculation is just fine, but there are somethings wrong.
I only have the LPC2478 manual but I believe it to be similar to lpc2378.

You set U1FDR to 0x85 and that is the opposite of what you've written.
To have DIVADDVAL = 8 and MULADDVAL = 5 U1FDR should be set to 0x58.
You have DIVADDVAL = 8 and MULVAL = 5 and from page 438 of the LPC2478 User
Manual there are three conditions that must be met, condition number three
is:
DIVADDVAL < MULADDVAL

You're violating this condition. You need to find new values for the
fractional divider register.

Regards,
Bernardo Marques.