Hello forum!
I'm facing a difficulties in configuring UART[2] receive on my LPC2368
board
from futurlec.com.
I've succeeded in writing character (transmit) to UART[2] by adapting
from
the sample code given,
but I'm kinda confused with the sample code given to get character from
UART[2]. Here's the sample code I'll be adapting from:
if(U2LSR & 0x01)
{
uart_data = getchar2();
if(uart_data==0x0D)
{
sprintf(uart2_buf,"ET-JR ARM7 LPC2368 : UART[2]\n\r");
print_uart2();
}
putchar2(uart_data);
}
Since I'm gonna use the character received by UART[2] to deliver the
feedback from LCD projector (such as lamp hour),
I need more than an 0x0D (enter button). I need to get like "65h43m21s" kind
of data. Here's what I've done by adapting from the code above
if(U2LSR & 0x01)
{
uart_data = getchar2();
sprintf(LCDlife,"%c",uart_data);
}
Did I miss something on my program? Thanks in advance for your help!
Regards,
Daniel
UART Receive in LPC2368
Started by ●March 11, 2010
Reply by ●March 25, 20102010-03-25
Hey Daniel,
If you really want to learn what you missed in your proposition, try to
understand the following dirty&simple adaptation from your code.
...
if(U2LSR & 0x01)
{
uart_data = getchar2();
if(uart_data==0x0D) //or whatever end of line your system sends
{
LCDLife[charpos] = 0; //NULL termination for the string
charpos = 0; //charpos should be static to your function
//LCDLife array is now complete
//Do what you need to do with the information collected
...
}
else
{
LCDLife[charpos] = uart_data;
charpos = charpos + 1; //update the position on the array for the next
character
}
}
...
Marcus
On Thu, Mar 11, 2010 at 9:18 PM, Daniel Giovanni wrote:
> Hello forum!
>
> I'm facing a difficulties in configuring UART[2] receive on my LPC2368
> board from futurlec.com.
> I've succeeded in writing character (transmit) to UART[2] by adapting from
> the sample code given,
> but I'm kinda confused with the sample code given to get character from
> UART[2]. Here's the sample code I'll be adapting from:
>
> if(U2LSR & 0x01)
> {
> uart_data = getchar2();
> if(uart_data==0x0D)
> {
> sprintf(uart2_buf,"ET-JR ARM7 LPC2368 : UART[2]\n\r");
> print_uart2();
> }
> putchar2(uart_data);
> }
>
> Since I'm gonna use the character received by UART[2] to deliver the
> feedback from LCD projector (such as lamp hour),
> I need more than an 0x0D (enter button). I need to get like "65h43m21s"
> kind of data. Here's what I've done by adapting from the code above
>
> if(U2LSR & 0x01)
> {
> uart_data = getchar2();
> sprintf(LCDlife,"%c",uart_data);
> }
>
> Did I miss something on my program? Thanks in advance for your help!
>
> Regards,
> Daniel
>
>
If you really want to learn what you missed in your proposition, try to
understand the following dirty&simple adaptation from your code.
...
if(U2LSR & 0x01)
{
uart_data = getchar2();
if(uart_data==0x0D) //or whatever end of line your system sends
{
LCDLife[charpos] = 0; //NULL termination for the string
charpos = 0; //charpos should be static to your function
//LCDLife array is now complete
//Do what you need to do with the information collected
...
}
else
{
LCDLife[charpos] = uart_data;
charpos = charpos + 1; //update the position on the array for the next
character
}
}
...
Marcus
On Thu, Mar 11, 2010 at 9:18 PM, Daniel Giovanni wrote:
> Hello forum!
>
> I'm facing a difficulties in configuring UART[2] receive on my LPC2368
> board from futurlec.com.
> I've succeeded in writing character (transmit) to UART[2] by adapting from
> the sample code given,
> but I'm kinda confused with the sample code given to get character from
> UART[2]. Here's the sample code I'll be adapting from:
>
> if(U2LSR & 0x01)
> {
> uart_data = getchar2();
> if(uart_data==0x0D)
> {
> sprintf(uart2_buf,"ET-JR ARM7 LPC2368 : UART[2]\n\r");
> print_uart2();
> }
> putchar2(uart_data);
> }
>
> Since I'm gonna use the character received by UART[2] to deliver the
> feedback from LCD projector (such as lamp hour),
> I need more than an 0x0D (enter button). I need to get like "65h43m21s"
> kind of data. Here's what I've done by adapting from the code above
>
> if(U2LSR & 0x01)
> {
> uart_data = getchar2();
> sprintf(LCDlife,"%c",uart_data);
> }
>
> Did I miss something on my program? Thanks in advance for your help!
>
> Regards,
> Daniel
>
>