Reply by Michael Anton March 1, 20092009-03-01
See my comments inline.

> -----Original Message-----
> From: l...
> [mailto:l...]On Behalf
> Of big_poo69
> Sent: Sunday, March 01, 2009 7:22 AM
> To: l...
> Subject: [lpc2000] LPC2468 UART0 Exmples???
> Hello all,
>
> i have been working on trying to get my UART0 working on my ollimex
> LPC2468 dev board, however when i run the program it only shows me
> rubbish on the pc termeinal (using realterm)
>
> here is my code:
>
> any suggestions very much appreciated!
> also if you have ANY code to do with UART0 receiving (from pc to
> LPC2468) i would love to have a look!
> i have been stuck on this for 3 weeks now!!!!!!
>
> many thanks !
>
> COde:
>
> //CLOCK = 72mhz
> //Baud = 921600

Do you actually have a PC UART that can support this baud rate?

> //*************************************************
>
> void UART0_Init(void)
> {
> PINSEL0 = PINSEL0 |= 1<<4; // Select UART0 RXD/TXD
> PINSEL0 = PINSEL0 |= 1<<6; // Select UART0 RXD/TXD

Perhaps you meant:
PINSEL0 = PINSEL0 | 1<<4; // Select UART0 RXD/TXD
PINSEL0 = PINSEL0 | 1<<6; // Select UART0 RXD/TXD

But, this would work equally well:
PINSEL0 |= 1<<4; // Select UART0 RXD/TXD
PINSEL0 |= 1<<6; // Select UART0 RXD/TXD

Though, even what you used should work correctly.

> U0FDR |= 0x92; // divaddval & mulval
>
> U0FCR = 7; // Enable and clear FIFO's
> U0LCR = 0x83; // 8N1, enable Divisor latch bit
> //U0FDR = U0FDR|= 1<<4 ;//Mulval is 1
>
> U0DLL = 4;// baud rate fixed to 19200 @ PCLK = 9 Mhz
> U0DLM = 0;
> U0LCR = 3; // Disable Divisor latch bit
> // 8 bits chars, 1 stop bit, no parity, odd parity, no break,
> }
>
> static void SendString(char *text)
> {
> if (txptr == 0) // previous message send ?
> {
> typtr = 0;
> while(*text)
> {
> txbuf[txptr++] = *text++;
> if(txptr >= TX_BUFSIZE)
> txptr = 0;
> }
> }
> }

You may want to use a circular buffer here instead, as it makes better
use of available buffer space, and allows messages to be sent that are
larger than the buffer (though in this case, the routine may block).

> static void UART0_Tx_Int(void) // Called from the main loop
> {
> char i = 16;
> if (U0LCR && 0x20) // transmit FIFO empty ?

Probably you want this instead:
if (U0LCR & 0x20) // transmit FIFO empty ?

> {
> while (i && (txptr > 0))
> {
> U0THR = txbuf[typtr++];
> txptr --;
> i --;
> }
> }
> }
>
> //THEN IN MAIN:
>
> UART0_Init();
> SendString("TESING UART");
> UART0_Tx_Int();

You would need to call UART0_Tx_Int() inside a loop until the entire
message has been sent.
Mike

An Engineer's Guide to the LPC2100 Series

Reply by big_poo69 March 1, 20092009-03-01
Hello all,

i have been working on trying to get my UART0 working on my ollimex
LPC2468 dev board, however when i run the program it only shows me
rubbish on the pc termeinal (using realterm)

here is my code:

any suggestions very much appreciated!
also if you have ANY code to do with UART0 receiving (from pc to
LPC2468) i would love to have a look!
i have been stuck on this for 3 weeks now!!!!!!

many thanks !

COde:

//CLOCK = 72mhz
//Baud = 921600
//*************************************************

void UART0_Init(void)
{
PINSEL0 = PINSEL0 |= 1<<4; // Select UART0 RXD/TXD
PINSEL0 = PINSEL0 |= 1<<6; // Select UART0 RXD/TXD
U0FDR |= 0x92; // divaddval & mulval

U0FCR = 7; // Enable and clear FIFO's
U0LCR = 0x83; // 8N1, enable Divisor latch bit
//U0FDR = U0FDR|= 1<<4 ;//Mulval is 1

U0DLL = 4;// baud rate fixed to 19200 @ PCLK = 9 Mhz
U0DLM = 0;
U0LCR = 3; // Disable Divisor latch bit
// 8 bits chars, 1 stop bit, no parity, odd parity, no break,
}

static void SendString(char *text)
{
if (txptr == 0) // previous message send ?
{
typtr = 0;
while(*text)
{
txbuf[txptr++] = *text++;
if(txptr >= TX_BUFSIZE)
txptr = 0;
}
}
}
static void UART0_Tx_Int(void) // Called from the main loop
{
char i = 16;
if (U0LCR && 0x20) // transmit FIFO empty ?
{
while (i && (txptr > 0))
{
U0THR = txbuf[typtr++];
txptr --;
i --;
}
}
}

//THEN IN MAIN:

UART0_Init();
SendString("TESING UART");
UART0_Tx_Int();