Page 1 of 1

best way to read with leuart

Posted: Fri Jun 26, 2015 10:01 am
by arnaudw
Hello,

I have a GPS which continuously send info on the RX pin.
What is the best way/practice to read from leuart ?
I think i should implement a buffer, then read it when it is full.

Found the declaration in the examples :

Code: Select all
init_printf(TD_UART_Init(9600, true, false), TD_UART_Putc, TD_UART_Start,
         TD_UART_Stop);


Then, I found this on the web :
Code: Select all
 while ((c = TD_UART_GetChar()) >= 0) {
//...
}

But in my case, it will never stop if i use it like this.

Thanks in advance,


Arnaud.

Re: best way to read with leuart

Posted: Fri Jun 26, 2015 10:20 am
by lcheminade
Hi,

This should be fine. Did you declare c as an int?

Loïc

Re: best way to read with leuart

Posted: Fri Jun 26, 2015 11:21 am
by arnaudw
Yes, c is an int.

Ok if it is the good way, i will find how to proceed with buffer. I am a a beginner but i should find :)

Thanks Loïc.
(I think you are french as me but as we are on an internationnal forum... :mrgreen: )

Re: best way to read with leuart

Posted: Fri Jun 26, 2015 12:23 pm
by lcheminade
The buffer already exist at the driver level. If you don't get out of the loop then this is probably because you never stop to have data. I guess your GPS keeps sending you some data. You'd better use 11500 speed when your gps is on and go back to 9600 when it is off.

Re: best way to read with leuart

Posted: Fri Jun 26, 2015 1:42 pm
by arnaudw
Indeed it sends always data, either if there is no fix.
Good news that a buffer is already in the chip, so, if i understand, i only need to do this to get (always) the content by char.

int c;
char didi;
while (((c = TD_UART_GetChar()) >= 0)) {
didi = (char)c;
};


Thanks :)