Questions and discussions about the SDK tools used to program the TD RF modules.
arnaudw
 
Posts: 17
Joined: Fri Jun 12, 2015 8:18 pm

best way to read with leuart

by arnaudw Fri Jun 26, 2015 10:01 am

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.
User avatar
lcheminade
 
Posts: 146
Joined: Mon May 11, 2015 7:47 am

Re: best way to read with leuart

by lcheminade Fri Jun 26, 2015 10:20 am

Hi,

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

Loïc
arnaudw
 
Posts: 17
Joined: Fri Jun 12, 2015 8:18 pm

Re: best way to read with leuart

by arnaudw Fri Jun 26, 2015 11:21 am

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: )
User avatar
lcheminade
 
Posts: 146
Joined: Mon May 11, 2015 7:47 am

Re: best way to read with leuart

by lcheminade Fri Jun 26, 2015 12:23 pm

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.
arnaudw
 
Posts: 17
Joined: Fri Jun 12, 2015 8:18 pm

Re: best way to read with leuart

by arnaudw Fri Jun 26, 2015 1:42 pm

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 :)
Return to Tools

Who is online

Users browsing this forum: No registered users and 11 guests