View previous topic :: View next topic |
Author |
Message |
haxan7
Joined: 27 Jul 2013 Posts: 79
|
weird problem uart getc and fgets. |
Posted: Thu Aug 08, 2013 6:39 am |
|
|
I have got a microcontroller with two hardware uarts, i am trying to echo the gps feed to pc via the controller.
Code: |
WHILE (TRUE){
t= getc(gps);
putc(t,pc);
}
|
Works fine, and i get three lines of gps strings every few ms.
but when i change the code to this:
Code: |
WHILE (TRUE){
fgets(array,gps);
fprintf(pc,array);
}
|
all i get is garbage...
Why this weird behavior? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu Aug 08, 2013 7:58 am |
|
|
Multiple things wrong/possibly wrong.....
First how big is 'array'?.
Second, remember that there are only two characters of hardware buffering. With the second code, the chip will be sending data from array for several mSec (depends how long the string is). So what happens to anything that arrives on gps in this time?.... This is the point about using interrupt driven receive.
Then fprintf, really does require a format string (printf is documented to work without one, but fprinf isn't).
Best Wishes |
|
|
haxan7
Joined: 27 Jul 2013 Posts: 79
|
|
Posted: Thu Aug 08, 2013 8:52 am |
|
|
Ttelmah wrote: |
First how big is 'array'?.
|
Array is 500 characters and string from gps is 250 char max.
if i use interrupt driven receive, would the controller be able to receive from gps and transmit to pc (on external interrupt) at the same time?
i am using 16mhz/9600 baudrate. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Thu Aug 08, 2013 9:15 am |
|
|
Yes. |
|
|
|