Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Thread

Can't Receive Data on UART0

Can't Receive Data on UART0

2006-03-11 by Nice Guy

I have tried everything I can think of, but I can not receive data on
the UART.  I know the UART and all other hardware is good, because I
can program the part over the exact same setup.  All I want to do is
send anything I receive back out, Just emulate a loopback as a first
step.  I can send data out the uart all day long. Below is my code, I
must be doing something stupid.  VPB Clock is set the same as the PLL
clock. Thanks for any help.

int main(void)
{
	sysInit();                              // Init system stuff
	uart0Init(9600, UART_8N1);
	uart0Puts("UP!\n\r");
	while(1)
	{
		uart0Putch(uart0Getch());
	}
	return(0);
}

int uart0Init(int baud, int mode)
{
	// clear needed pinsel bits and set to correct values
	PINSEL0 &= ~(PINSEL_FUNC(3,1)|PINSEL_FUNC(3,0));
	PINSEL0 |= PINSEL_FUNC(1,1) | PINSEL_FUNC(1,0);

	U0LCR = BIT7|mode;
	U0DLL = ((XTAL * M_OSC) / (baud * 16)) & 0xFF;
	U0DLM = (((XTAL * M_OSC) /(baud * 16)) >> 8) & 0xFF;
	U0LCR &= ~BIT7;

	U0IER = 0x00;             // disable all interrupts
	U0IIR = 0x00;             // clear interrupt ID register
	U0LSR = 0x00;             // clear line status register
	U0FCR = BIT2|BIT1|BIT0;
	return(0);
}

int uart0Putch(int ch)
{
  while (!(U0LSR & BIT5))          // wait for TX buffer to empty
    continue;                           // also either WDOG()

  U0THR = (unsigned char)ch;  // put char to Transmit Holding Register
  return (unsigned char)ch;      // return char ("stdio-compatible"?)
}

const char *uart0Puts(const char *string)
{
	char ch;

	while ((ch = *string)) {
		if (uart0Putch(ch)<0) break;
		string++;
	}

	return string;
}

int uart0Getch(void)
{
	if(U0LSR & BIT0)
	return U0RBR;
	return -1;
}

Re: [lpc2000] Can't Receive Data on UART0

2006-03-11 by Leon Heller

----- Original Message ----- 
Show quoted textHide quoted text
From: "Nice Guy" <mcmurtr@...>
To: <lpc2000@yahoogroups.com>
Sent: Saturday, March 11, 2006 7:11 PM
Subject: [lpc2000] Can't Receive Data on UART0


>I have tried everything I can think of, but I can not receive data on
> the UART.  I know the UART and all other hardware is good, because I
> can program the part over the exact same setup.  All I want to do is
> send anything I receive back out, Just emulate a loopback as a first
> step.  I can send data out the uart all day long. Below is my code, I
> must be doing something stupid.  VPB Clock is set the same as the PLL
> clock. Thanks for any help.

Rowley CrossStudio for ARM  has an example. I think it worked OK when I 
tried it.

Leon

Re: [lpc2000] Can't Receive Data on UART0

2006-03-11 by Karl Olsen

---- Original Message ----
Show quoted textHide quoted text
From: "Nice Guy" <mcmurtr@...>
To: <lpc2000@yahoogroups.com>
Sent: Saturday, March 11, 2006 8:11 PM
Subject: [lpc2000] Can't Receive Data on UART0

> I have tried everything I can think of, but I can not receive data on
> the UART.  I know the UART and all other hardware is good, because I
> can program the part over the exact same setup.  All I want to do is
> send anything I receive back out, Just emulate a loopback as a first
> step.  I can send data out the uart all day long. Below is my code, I
> must be doing something stupid.  VPB Clock is set the same as the PLL
> clock. Thanks for any help.
>
> int main(void)
> {
> sysInit();                              // Init system stuff
> uart0Init(9600, UART_8N1);
> uart0Puts("UP!\n\r");
> while(1)
> {
> uart0Putch(uart0Getch());
> }
> return(0);
> }
>
> int uart0Init(int baud, int mode)
> {
> // clear needed pinsel bits and set to correct values
> PINSEL0 &= ~(PINSEL_FUNC(3,1)|PINSEL_FUNC(3,0));
> PINSEL0 |= PINSEL_FUNC(1,1) | PINSEL_FUNC(1,0);
>
> U0LCR = BIT7|mode;
> U0DLL = ((XTAL * M_OSC) / (baud * 16)) & 0xFF;
> U0DLM = (((XTAL * M_OSC) /(baud * 16)) >> 8) & 0xFF;
> U0LCR &= ~BIT7;
>
> U0IER = 0x00;             // disable all interrupts
> U0IIR = 0x00;             // clear interrupt ID register
> U0LSR = 0x00;             // clear line status register
> U0FCR = BIT2|BIT1|BIT0;
> return(0);
> }
>
> int uart0Putch(int ch)
> {
>  while (!(U0LSR & BIT5))          // wait for TX buffer to empty
>    continue;                           // also either WDOG()
>
>  U0THR = (unsigned char)ch;  // put char to Transmit Holding Register
>  return (unsigned char)ch;      // return char ("stdio-compatible"?)
> }
>
> const char *uart0Puts(const char *string)
> {
> char ch;
>
> while ((ch = *string)) {
> if (uart0Putch(ch)<0) break;
> string++;
> }
>
> return string;
> }
>
> int uart0Getch(void)
> {
> if(U0LSR & BIT0)
> return U0RBR;
> return -1;
> }

Most of the times you call uart0Getch(), no character is received, and it 
seems you then send 0xFF.  Is this intended?

Karl Olsen

Re: Can't Receive Data on UART0

2006-03-12 by Nice Guy

--- In lpc2000@yahoogroups.com, "Karl Olsen" <kro@...> wrote:
>
> ---- Original Message ----
> From: "Nice Guy" <mcmurtr@...>
> To: <lpc2000@yahoogroups.com>
> Sent: Saturday, March 11, 2006 8:11 PM
> Subject: [lpc2000] Can't Receive Data on UART0
> 
> > I have tried everything I can think of, but I can not receive data on
> > the UART.  I know the UART and all other hardware is good, because I
> > can program the part over the exact same setup.  All I want to do is
> > send anything I receive back out, Just emulate a loopback as a first
> > step.  I can send data out the uart all day long. Below is my code, I
> > must be doing something stupid.  VPB Clock is set the same as the PLL
> > clock. Thanks for any help.
> >
> > int main(void)
> > {
> > sysInit();                              // Init system stuff
> > uart0Init(9600, UART_8N1);
> > uart0Puts("UP!\n\r");
> > while(1)
> > {
> > uart0Putch(uart0Getch());
> > }
> > return(0);
> > }
> >
> > int uart0Init(int baud, int mode)
> > {
> > // clear needed pinsel bits and set to correct values
> > PINSEL0 &= ~(PINSEL_FUNC(3,1)|PINSEL_FUNC(3,0));
> > PINSEL0 |= PINSEL_FUNC(1,1) | PINSEL_FUNC(1,0);
> >
> > U0LCR = BIT7|mode;
> > U0DLL = ((XTAL * M_OSC) / (baud * 16)) & 0xFF;
> > U0DLM = (((XTAL * M_OSC) /(baud * 16)) >> 8) & 0xFF;
> > U0LCR &= ~BIT7;
> >
> > U0IER = 0x00;             // disable all interrupts
> > U0IIR = 0x00;             // clear interrupt ID register
> > U0LSR = 0x00;             // clear line status register
> > U0FCR = BIT2|BIT1|BIT0;
> > return(0);
> > }
> >
> > int uart0Putch(int ch)
> > {
> >  while (!(U0LSR & BIT5))          // wait for TX buffer to empty
> >    continue;                           // also either WDOG()
> >
> >  U0THR = (unsigned char)ch;  // put char to Transmit Holding Register
> >  return (unsigned char)ch;      // return char ("stdio-compatible"?)
> > }
> >
> > const char *uart0Puts(const char *string)
> > {
> > char ch;
> >
> > while ((ch = *string)) {
> > if (uart0Putch(ch)<0) break;
> > string++;
> > }
> >
> > return string;
> > }
> >
> > int uart0Getch(void)
> > {
> > if(U0LSR & BIT0)
> > return U0RBR;
> > return -1;
> > }
> 
> Most of the times you call uart0Getch(), no character is received,
and it 
> seems you then send 0xFF.  Is this intended?
> 
> Karl Olsen
>

Yeah, it's fine for now, I want to be able to hold a key down and see
it appear in the output stream. The 0xFF shows up as spaces in
hyperterminal.

Re: [lpc2000] Re: Can't Receive Data on UART0

2006-03-12 by Bill Knight

On Sun, 12 Mar 2006 20:11:36 +0000, Nice Guy wrote:

<snip>

>Yeah, it's fine for now, I want to be able to hold a key down and see
>it appear in the output stream. The 0xFF shows up as spaces in
>hyperterminal.



Hyperterminal drops characters.  I suggest you change the code to only
send a character if one is received.

int ch;
if ((ch = uart0Getch()) >= 0)
  uart0Putch(ch);

Regards
-Bill Knight
R O SoftWare &
http://www.theARMPatch.com

Re: [lpc2000] Re: Can't Receive Data on UART0

2006-03-12 by Robert Adsett

At 02:19 PM 3/12/06 -0600, Bill Knight wrote:
>On Sun, 12 Mar 2006 20:11:36 +0000, Nice Guy wrote:
><snip>
>
> >Yeah, it's fine for now, I want to be able to hold a key down and see
> >it appear in the output stream. The 0xFF shows up as spaces in
> >hyperterminal.
>
>Hyperterminal drops characters.  I suggest you change the code to only
>send a character if one is received.

Also given Hyperterminal's oddities consider getting something that's more 
of a 'real' terminal emulator.  I use realterm but there are others and 
several of them are free (including realterm)

Robert

" 'Freedom' has no meaning of itself.  There are always restrictions,   be 
they legal, genetic, or physical.  If you don't believe me, try to chew a 
radio signal. "  -- Kelvin Throop, III
http://www.aeolusdevelopment.com/

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.