EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

LPC2138 UART0 Problem (UART1 is OK)

Started by nkni...@yahoo.com August 4, 2006
Note: I did scan for similar questions before posting, but then it won't accept my message indicating that I need a subject on my message...which I had...so I'm reposting here and not checking the "Scan archives..." box.

I am having a problem getting output out of UART0. UART1 works fine. I have checked both with o-scope and see output on Pin 33 (Uart1), but not on pin 19 (uart0). I'm thinking there must be something wrong with my program. I can see characters typed into hyperterm go into UART0 and get output on UART1, but I never see the output output from loop below, or my typed characters on UART0.

#include
#define OSCILLATOR_CLOCK_FREQUENCY 12000000
#define U0TER (*(volatile unsigned char *)0xE000C030)

static unsigned int
processorClockFrequency(void)
{
return OSCILLATOR_CLOCK_FREQUENCY * (PLLCON & 1 ? (PLLCFG & 0xF) + 1 : 1);
}

static unsigned int
peripheralClockFrequency(void)
{
unsigned int divider;
switch (VPBDIV & 3)
{
case 0:
divider = 4;
break;
case 1:
divider = 1;
break;
case 2:
divider = 2;
break;
}
return processorClockFrequency() / divider;
}

static void
delay(int n)
{
volatile int i;
for (i = 0; i < n; ++i);
}

static void
UARTInitialize(unsigned int baud)
{
unsigned int divisor = peripheralClockFrequency() / (16 * baud);
U0LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
U0DLL = divisor & 0xFF;
U0DLM = (divisor >> 8) & 0xFF;
U0LCR &= ~0x80; /* Disable DLAB */
U0FCR = 0x1;

U1LCR = 0x83; /* 8 bit, 1 stop bit, no parity, enable DLAB */
U1DLL = divisor & 0xFF;
U1DLM = (divisor >> 8) & 0xFF;
U1LCR &= ~0x80; /* Disable DLAB */
U1FCR = 1;

PINSEL0 = (0x5 << 16)|0x5;
unsigned long ps0 = PINSEL0;
int a = 1;

}

static void
UARTWriteChar(unsigned char ch)
{

while ((U0LSR & 0x20) == 0);
U0THR = ch;

while ((U1LSR & 0x20) == 0);
U1THR = ch;
}

static unsigned char
UARTReadChar(void)
{
if (U0LSR & 0x01) return U0RBR;
return 0x0;
}

void
__putchar(int ch)
{
if (ch == '\n')
UARTWriteChar('\r');
UARTWriteChar(ch);
}

int
main(void)
{
int i,j;
UARTInitialize(9600);
for (i = 0; ; ++i)
{
delay(100000);
printf("Line Status Register U0LSR: %4.4x (%d)\n", U0LSR, i);
printf("Line Status Register U0TER: %4.4x (%d)\n", U0TER, i);
char ch = UARTReadChar();
if (ch != 0x0)
printf("Incoming Char: %c \n", UARTReadChar());
}
return 0;
}

OUTPUT SEEN ON UART1
+++OK
atid
3332
atid500
OK
atwr
OK
atcn
OK
Line Status Register U0LSR: 0060 (0)
.Line Status Register U0TER: 0080 (0)
.Line Status Register U0LSR: 0060 (1)
.Line Status Register U0TER: 0080 (1)
.Line Status Register U0LSR: 0060 (2)
.Line Status Register U0TER: 0080 (2)
.Line Status Register U0LSR: 0060 (3)
.Line Status Register U0TER: 0080 (3)
.Line Status Register U0LSR: 0060 (4)
.Line Status Register U0TER: 0080 (4)
.Line Status Register U0LSR: 0060 (5)
.Line Status Register U0TER: 0080 (5)
.Line Status Register U0LSR: 0060 (6)
.Line Status Register U0TER: 0080 (6)
.Line Status Register U0LSR: 0060 (7)
.Line Status Register U0TER: 0080 (7)
.Line Status Register U0LSR: 0060 (8)
.Line Status Register U0TER: 0080 (8)
.Line Status Register U0LSR: 0060 (9)
.Line Status Register U0TER: 0080 (9)
.Line Status Register U0LSR: 0060 (10)
.Line Status Register U0TER: 0080 (10)
.Line Status Register U0LSR: 0060 (11)
.Line Status Register U0TER: 0080 (11)
.Line Status Register U0LSR: 0060 (12)
.Line Status Register U0TER: 0080 (12)
.Line Status Register U0LSR: 0060 (13)
.Line Status Register U0TER: 0080 (13)
.Line Status Register U0LSR: 0060 (14)
.Line Status Register U0TER: 0080 (14)
.Line Status Register U0LSR: 0060 (15)
.Line Status Register U0TER: 0080 (15)
.Line Status Register U0LSR: 0060 (16)
.Line Status Register U0TER: 0080 (16)
.Line Status Register U0LSR: 0060 (17)
.Line Status Register U0TER: 0080 (17)
.Line Status Register U0LSR: 0060 (18)
.Line Status Register U0TER: 0080 (18)
.Line Status Register U0LSR: 0060 (19)
.Line Status Register U0TER: 0080 (19)
.Line Status Register U0LSR: 0060 (20)
.Line Status Register U0TER: 0080 (20)
.Line Status Register U0LSR: 0060 (21)
.Line Status Register U0TER: 0080 (21)
.Line Status Register U0LSR: 0060 (22)
.Line Status Register U0TER: 0080 (22)
.

An Engineer's Guide to the LPC2100 Series

Can someone look at this please ? Seems like an init problem, but I can't find it. -- NK

---------------------------------
Talk is cheap. Use Yahoo! Messenger to make PC-to-Phone calls. Great rates starting at 1/min.





I am having a problem getting output out of UART0. UART1 works fine. I have checked both with o-scope and see output on Pin 33 (Uart1), but not on pin 19 (uart0). I'm thinking there must be something wrong with my program. I can see characters typed into hyperterm go into UART0 and get output on UART1, but I never see the output output from loop below, or my typed characters on UART0.

#include
#define OSCILLATOR_CLOCK_FREQUENCY 12000000
#define U0TER (*(volatile unsigned char *)0xE000C030)

static unsigned int
processorClockFrequency(void)
{
return OSCILLATOR_CLOCK_FREQUENCY * (PLLCON & 1 ? (PLLCFG & 0xF) + 1 : 1);
}

static unsigned int
peripheralClockFrequency(void)
{
unsigned int divider;
switch (VPBDIV & 3)
{
case 0:
divider = 4;
break;
case 1:
divider = 1;
break;
case 2:
divider = 2;
break;
}
return processorClockFrequency() / divider;
}

static void
delay(int n)
{
volatile int i;
for (i = 0; i < n; ++i);
}

static void
UARTInitialize(unsigned int baud)
{
unsigned int divisor = peripheralClockFrequency() / (16 * baud);
U0LCR = 0x83; _/* 8 bit, 1 stop bit, no parity, enable DLAB */
U0DLL = divisor & 0xFF;
U0DLM = (divisor >> 8) & 0xFF;
U0LCR &= ~0x80; _/* Disable DLAB */
U0FCR = 0x1;

U1LCR = 0x83; _/* 8 bit, 1 stop bit, no parity, enable DLAB */
U1DLL = divisor & 0xFF;
U1DLM = (divisor >> 8) & 0xFF;
U1LCR &= ~0x80; _/* Disable DLAB */
U1FCR = 1;

PINSEL0 = (0x5 << 16)|0x5;
unsigned long ps0 = PINSEL0;
int a = 1;

}

static void
UARTWriteChar(unsigned char ch)
{

while ((U0LSR & 0x20) == 0);
U0THR = ch;

while ((U1LSR & 0x20) == 0);
U1THR = ch;

}

static unsigned char
UARTReadChar(void)
{
if (U0LSR & 0x01) return U0RBR;
return 0x0;
}

void
__putchar(int ch)
{
if (ch == '\n')
UARTWriteChar('\r');
UARTWriteChar(ch);
}

int
main(void)
{
int i,j;
UARTInitialize(9600);
for (i = 0; ; ++i)
{
delay(100000);
printf("Line Status Register U0LSR: %4.4x (%d)\n", U0LSR, i);
printf("Line Status Register U0TER: %4.4x (%d)\n", U0TER, i);
char ch = UARTReadChar();
if (ch != 0x0)
printf("Incoming Char: %c \n", UARTReadChar());
}
return 0;
}

---------------------------------
Do you Yahoo!?
Next-gen email? Have it all with the all-new Yahoo! Mail Beta.

The 2024 Embedded Online Conference