![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
lerastas
Joined: 27 Jun 2006 Posts: 3
|
pic stop when read RS232 ??? |
Posted: Tue Jun 27, 2006 12:36 pm |
|
|
Hello everybody, I would like if you know why my pic 16F876A stop the read of RS232.
In fact, the pic read the data but stop when it want!!! I don't know why. Is it because the GPS data doesn't send the data every time. But my code wait a $ before continue.
It's the GPGGA data.
If anyone can reply, it will be cool!!
Thanks, sorry for the English!!
Lerastas
#include <16F876A.h>
#use delay(clock=20000000)
#use rs232(baud=38400,xmit=PIN_C6,rcv=PIN_C7, stream=GPS)
#include <string.h>
#include <stdlib.h>
char k;
char i;
char string[6];
char buffer[45];
char compar[]="GPGGA,";
char heure[3], minutes[3], sec[3], ms[3], sat[3], trame[6];
void read_GPS ()
{
while ( fgetc(GPS) != 36 ); // wait a $
for (k=0;k<45;k++) buffer[k]=fgetc(GPS);
while (strncmp(buffer,compar,6)!=0);
for (i=0; i<2; i++)
{
heure[i]=buffer[i+6];
heure[2] = '\0';
}
for (i=0; i<2; i++)
{
minutes[i]=buffer[i+8];
minutes[2] = '\0';
}
for (i=0; i<2; i++)
{
sec[i]=buffer[i+10];
sec[2] = '\0';
}
for (i=0; i<2; i++)
{
ms[i]=buffer[i+13];
ms[2] = '\0';
}
for (i=0; i<2; i++)
{
sat[i]=buffer[i+43];
sat[2] = '\0';
}
heure_bis=atoi(heure);
minutes_bis=atoi(minutes);
sec_bis=atoi(sec);
ms_bis=atol(ms)*10;
sat_bis=atol(sat);
}
void main(void)
{
init();
while(1)
{
read_GPS(); //lecture de la trame GPS
fprintf(GPS,"donnees GPS %u heure %u minutes %u sec %u nb sat %ld ms\n\r", heure_bis,minutes_bis ,sec_bis, sat_bis,ms_bis);
}
} |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 27, 2006 12:47 pm |
|
|
The UART receiver may be locking up. When you do the large fprintf()
statement, you are not checking the UART for incoming characters.
If the hardware fifo fills up (it can only hold 2 characters) and you
receive one more character, then the UART receiver will lock up.
You can make the compiler add code to automatically clear the lock-up
by adding the ERRORS parameter as shown in bold below.
Quote: | #use rs232(baud=38400,xmit=PIN_C6,rcv=PIN_C7, ERRORS, stream=GPS) |
It would be better if you prevent the lockup completely by adding
an interrupt-driven software receive fifo, as shown in the CCS example
file, EX_SISR.C. Look in this folder for it:
c:\Program Files\PICC\Examples |
|
![](templates/subSilver/images/spacer.gif) |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|