#define MAX_SENTENCE_LENGTH 20
void main(void)
{
init();
while(1)
{
if((strncmp("GPGSV",GPSmsg,5)==0)
{ // if found GPGSV
extract lat and lon etc.
}
if((strncmp("GGA",GPSmsg,3)==0)
{ // if found GGA
// extract data.
}
}
}
void interrupt(void)
{
if(RI==1)
{ // if character is received..
temp = SBUF; // read and save it
RI=0; // and clear interrupt flag
if(temp == '$')
{ // look for '$' to start the sentence,
GPSmsg[ix++]= temp; // save character in buf
}
}
}
Hi,
it´s not clear what you want to do within the ISR.
Klaus
The shown code doesn't. It only copies '$' to GPSmsg. Please reconsider.I want to store message in interrupt service routine and I want to compare and parse in main routine
That's what I am asking for help understandingThe shown code doesn't. It only copies '$' to GPSmsg. Please reconsider.
Hint:
when you receive '$' set 'ix' to zero and increment it as each new character is received. That will add each new character to the GPSmsg string. Remember that in the C language a string is terminated with a zero so think about how your string comparison will find the end of the message if the terminator is missing.
Brian.
GPSmsg[ix]= '\0';
#define MAX_SENTENCE_LENGTH 20
volatile char GPSmsg[ix];
void main(void)
{
init();
while(1)
{
if((strncmp("GPGSV",GPSmsg,5)==0)
{ // if found GPGSV
extract lat and lon etc.
}
if((strncmp("GGA",GPSmsg,3)==0)
{ // if found GGA
// extract data.
}
}
}
void interrupt(void)
{
if(RI==1)
{ // if character is received..
temp = SBUF; // read and save it
RI=0; // and clear interrupt flag
if(temp == '$')
{ // look for '$' to start the sentence,
ix = 0;
}
else
{
GPSmsg[ix++]= temp; // save character in buf
}
}
}
You could do yourself a favour by:That's what I am asking for help understanding
You are close in your new code at post #8 but the zero terminator might still cause problems. I'm not going to write the code for you but the principle is:
1. Allocate at least one extra space in the storage for GPSmag so it can hold the terminator
2. initialize your index into the message to zero.
3. Use the ISR to read the character.
4. if the character is '$' make ix = 0
otherwise
5. Store the character at GPSmsg[ix]
6. Increment ix
7. Store zero (as in 0x00) in GPSMsg[ix]
Brian.
#define MAX_SENTENCE_LENGTH 20
volatile char GPSmsg[ix];
void main(void)
{
init();
while(1)
{
if((strncmp("GPGSV",GPSmsg,5)==0)
{ // if found GPGSV
extract lat and lon etc.
}
if((strncmp("GGA",GPSmsg,3)==0)
{ // if found GGA
// extract data.
}
}
}
void interrupt(void)
{
if(RI==1)
{ // if character is received..
temp = SBUF; // read and save it
RI=0; // and clear interrupt flag
if(temp == '$')
{ // look for '$' to start the sentence,
ix = 0;
}
else
{
GPSmsg[ix++]= temp; // save character in buf
if(ix == MAX_SENTENCE_LENGTH))
{
GPSmsg[ix]= '\0';
}
}
}
}
if(ix == MAX_SENTENCE_LENGTH))
{
char temp = SBUF;
if(temp == '$')
{
ix = 0;
*GPSmsg = 0;
return;
}
if(temp == CR)
{
GPSDataReceived = 1;
return;
}
if(ix < MAX_SENTENCE_LENGTH - 1)
{
GPSmsg[ix++] = temp;
GPSmsg[ix] = 0;
}
}
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?