UART receiving problem with LPC1227

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART receiving problem with LPC1227

535 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arunkollam on Tue Jul 09 05:25:15 MST 2013
Hi
i am writing a program which receives 0x03 and 0x04 strings continusly via UART0 and sends to a device through UART1.The device responds with a 3 bit data for each command(0x03 and 0x04).


DEVICE-1 sends 0x03 =>uart0----- LPC1227-----UART1=>0x03 to the device2
DEVICE-2 sends 0x01 0x0c 0xff =>uart1----- LPC1227-----UART0=>0x01 0x0c 0xffto the device1

DEVICE-1 sends 0x04 =>uart0----- LPC1227-----UART1=>0x04 to the device2
DEVICE-2 sends 0x01 0x0c 0xff =>uart1----- LPC1227-----UART0=>0x01 0x0c 0xffto the device1



The first bit of the receving bit is a command and it should be always 0x01.
my problem is in receiving the 3 bit data , some times the device 2 will not send 3 bits of data insted it will send 1 or 2 bits and my getchar waits for receiving it and the program enter into a endless loop.so any one can help me in writing a timer which waits for receiving the data for 5 ms and after 5ms , if there is no data received restart or clear the uart buffer.
0 Kudos
Reply
7 Replies

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arunkollam on Wed Jul 10 02:44:18 MST 2013
thanks...
0 Kudos
Reply

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arunkollam on Wed Jul 10 02:36:59 MST 2013
Thank you very much
0 Kudos
Reply

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by CodeRedSupport on Tue Jul 09 23:50:52 MST 2013
There are examples in the LPC12xx examples supplied with LPCXpresso that show the use of both Systick and Timer peripherals. Suggest you start off by looking at those.

Regards,
CodeRedSupport
0 Kudos
Reply

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Tue Jul 09 17:23:17 MST 2013
I haven't got any experience with the HW timers so all I can suggest at this point is a dodgy software "timer"

int UART1_getchar (void) {

    for (long i = 0; i < some_really_big_number; i++) {
        if (!(LPC_UART1->LSR & 0x01)){
                  return (LPC_UART1->RBR);
        }
    return (ERROR_TIMEOUT);
}
0 Kudos
Reply

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arunkollam on Tue Jul 09 07:35:27 MST 2013

Quote: graynomad
I assume you means [B]bytes[/B].

The quick and dirty way is to wrap your getchar() in a loop with a counter and maybe a short delay. If you get a character you return from inside the loop, if the loop terminates you timed out.

You could also read the systick value ( SysTick->VAL; ) and return after 5mS has passed.



You are exactly right.but i had found a different way of implimentation .plan to make a delay in uart1 receive.the uart 1 rx will jump from the infinite loop without receiving any charactor after 5 ms.


int UART1_getchar (void)

    {

if (!(LPC_UART1->LSR & 0x01))
{

}

return (LPC_UART1->RBR);
    }
any idea to execute a timer?
0 Kudos
Reply

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by arunkollam on Tue Jul 09 07:29:13 MST 2013
Hi,

Any have an idea about receiving strings without waiting more than 3 ms.

int UART1_getchar (void)

    {

if (!(LPC_UART1->LSR & 0x01))
{

}

return (LPC_UART1->RBR);
    }

i tried to remove the loop, but it making errors in receiving the second and third data.so i need a proper counder or timer to me executed after sending the data.

Thanks
Arun
0 Kudos
Reply

515 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by graynomad on Tue Jul 09 06:09:07 MST 2013

Quote:
3 bits of data

I assume you means [B]bytes[/B].

The quick and dirty way is to wrap your getchar() in a loop with a counter and maybe a short delay. If you get a character you return from inside the loop, if the loop terminates you timed out.

You could also read the systick value ( SysTick->VAL; ) and return after 5mS has passed.
0 Kudos
Reply