EmbeddedRelated.com
Forums

UART Loop Back

Started by majid_mokhtari December 28, 2005
Hi Everybody ,

First of all , Merry Christams and I hope a happy new year for everybody.

May be already answered but I couldn't find it . I tried to read data
from UART0 by initializing exactly based around Insider Guide book
from Hitex . I could not receive data by Hyperterminal . After
checking all parameters , I used Oscilloscope and I had serial data
with correct baud rate . Another software was used but the same
problem exist.

I tried to read data by loop baking UART0 and 1 . ( only connecting
2< - - > 3) with the same initializing and I saw serial data on line.
By overriding putchar ( ) for writing data and getchar ( ) to read
data but it didn't read anything . Any advice is welcomed , it's my code ;

void UART0 (void)
{
PINSEL0 = 0x05; // Select TxD and RxD on pin connect block
U0LCR = 0x80; //Enable programming of divisor latches

U0DLL = 0xC2; //Program the divisor latch for 19200 baud
U0DLM = 0x00;

U0LCR = 0x33; //Program the line control 8\N\1
U0FCR = 0x4F; //enable the FIFO's

}
void UART1 (void)
{
PINSEL0 |=0x050000;
U1LCR = 0x80; //Enable programming of divisor latches

U1DLL = 0xC2; //Program the divisor latch for 19200 baud
U1DLM = 0x00;

U1LCR = 0x33; //Program the line control 8\N\1
U1FCR = 0x4F;
}

int putchar (int ch)
{ /* Write character to Serial Port */

if (ch == '\n')
{
while (!(U0LSR & 0x20));
U0THR = CR; /* output CR */
}
while (!(U0LSR & 0x20));

return (U0THR=ch);
}

int getchar (void)
{
while(!(U1LSR & 0x01 ));
return (U1RBR);
}



An Engineer's Guide to the LPC2100 Series

Hello Majid,
I followed this approach for UART0
communication: One thing which is worth mentioning
here is that:

DLAB=0 while receiving or transmitting the data.

#include<LPC213x.h>
#include<stdio.h>

void UART0_Init(void);
void UART0_Write(char);

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

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

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

}

void UART0_Init(void)
{

PINSEL0=0x00000005; /* Enable RxD0 and TxD0 */
U0FCR=0x07; /* Tx FIFO, Rx FIFO and FIFO eanable
*/
U0LCR=0x92; /* DLAB=1, Even Parity=1, WLS=7 bits */
U0DLL=0x97; /* Baud Rate */
U0DLM=0x00;
U0LCR=0x12;
}

void UART0_Write(char c)
{
while(!(U0LSR & 0x20)); // Check U0LSR_bit.THRE for 1
U0THR=c;
} Hope this will work for you....

Regards

--- majid_mokhtari <majid_mokhtari@maji...> wrote: ---------------------------------
Hi Everybody ,

First of all , Merry Christams and I hope a happy new
year for everybody.

May be already answered but I couldn't find it . I
tried to read data
from UART0 by initializing exactly based around
Insider Guide book
from Hitex . I could not receive data by Hyperterminal
. After
checking all parameters , I used Oscilloscope and I
had serial data
with correct baud rate . Another software was used
but the same
problem exist.

I tried to read data by loop baking UART0 and 1 . (
only connecting
2< - - > 3) with the same initializing and I saw
serial data on line.
By overriding putchar ( ) for writing data and getchar
( ) to read
data but it didn't read anything . Any advice is
welcomed , it's my code ;

void UART0 (void)
{
PINSEL0 = 0x05; // Select TxD and RxD on
pin connect block
U0LCR = 0x80; //Enable programming of
divisor latches

U0DLL = 0xC2; //Program the divisor
latch for 19200 baud
U0DLM = 0x00;

U0LCR = 0x33; //Program the line
control 8\N\1
U0FCR = 0x4F; //enable the FIFO's

}
void UART1 (void)
{
PINSEL0 |=0x050000;
U1LCR = 0x80; //Enable programming of
divisor latches

U1DLL = 0xC2; //Program the divisor
latch for 19200 baud
U1DLM = 0x00;

U1LCR = 0x33; //Program the line
control 8\N\1
U1FCR = 0x4F;
}

int putchar (int ch)
{ /* Write character to Serial Port
*/

if (ch == '\n')
{
while (!(U0LSR & 0x20));
U0THR = CR; /* output CR
*/
}
while (!(U0LSR & 0x20));

return (U0THR=ch);
}

int getchar (void)
{
while(!(U1LSR & 0x01 ));
return (U1RBR);
} ---------------------------------
YAHOO! GROUPS LINKS ---------------------------------

Send instant messages to your online friends http://in.messenger.yahoo.com



> May be already answered but I couldn't find it . I tried to read data
> from UART0 by initializing exactly based around Insider Guide book
> from Hitex . I could not receive data by Hyperterminal . After
> checking all parameters , I used Oscilloscope and I had serial data
> with correct baud rate . Another software was used but the same
> problem exist.

If you confirmed correct baud rate and you see data being sent from target
there are still two possibilities:

1. Improper pin-out of RS-232 cable
2. Baud rate mismatch between target and host

If these are ok, try dropping to a baud with 0% error. Alternative to Hyperterminal (free):
http://hp.vector.co.jp/authors/VA002416/teraterm.html Joel