---- 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 OlsenMessage
Re: [lpc2000] Can't Receive Data on UART0
2006-03-11 by Karl Olsen
Attachments
- No local attachments were found for this message.