CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

problem with ublox gps
Goto page Previous  1, 2, 3, 4, 5, 6  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

problem with ublox gps
PostPosted: Mon Jun 09, 2014 1:17 pm     Reply with quote

Any ideas how to solve the problem?
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

Re: problem with ublox gps
PostPosted: Tue Jun 10, 2014 3:39 am     Reply with quote

andys wrote:
Any ideas how to solve the problem?

You are simply not telling us what your problem is.

Post simple, complete and compilable code to illustrate.

At this stage, (page 3) we are having to read your mind.

I've got better things to do.

Mike
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

problem with ublox gps
PostPosted: Tue Jun 10, 2014 12:53 pm     Reply with quote

At the line :

Code:
 sscanf(pch,"%2d%2d%2d",&DAY,&MON,&YEAR);


int *DAY,*MON,*YEAR;
(i also try to define as int DAY[10],MON[10],YEAR[10]; )

i get the error and warning :

error: Attempt to create a pointer to a constant
warning: ......sscanf.c" Line 140(1,1): Condition always TRUE


if i use #include <input.c> i get a lot of errors


with the use of #device PASS_STRINGS=IN_RAM
i get the error: Can not change device type this far into the code.

i use a lot of things from the link without success. Any suggestions?
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

Re: problem with ublox gps
PostPosted: Tue Jun 10, 2014 3:18 pm     Reply with quote

andys wrote:
for the strtok i didn't find anything from the manual
It is in my manual...
Without you telling which version of the manual you are using I must assume you didn't search good enough.

andys wrote:
At the line :

Code:
 sscanf(pch,"%2d%2d%2d",&DAY,&MON,&YEAR);


int *DAY,*MON,*YEAR;
(i also try to define as int DAY[10],MON[10],YEAR[10]; )

i get the error and warning :

error: Attempt to create a pointer to a constant
warning: ......sscanf.c" Line 140(1,1): Condition always TRUE
The error message is a bit misleading, but for a %d format specifier you almost never use '&' on the parameter. The '&' you can read as 'address of', so here you are trying to print the addresses of the DAY, MON and YEAR variables. Not what you want.
Remove the '&'. This is basic C knowledge.
The way you are trying to fix it is like using a machine gun with all kind of variations in the hope that your code will start working, but you have no clue as to what you are doing.

It is very difficult to help you. You ask a lot but give us very little information about your problems and then before we can zoom in on the problem you have already moved on.
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jun 10, 2014 3:38 pm     Reply with quote

re:...
Quote:
with the use of #device PASS_STRINGS=IN_RAM
i get the error: Can not change device type this far into the code.

Simply cut and paste it about 3-5 lines from beginning of program.
We'd have to see at least 10 lines to confirm.....

hth
jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19537

View user's profile Send private message

PostPosted: Wed Jun 11, 2014 1:00 am     Reply with quote

The standard CCS rules about 'file ordering', ought to fix the 'cannot change device type' error.

Layout needs to basically be:
1) Processor include
2) Any extra #device lines, including things like 'pass strings'
3) FUSES
4) CLOCK
5) #PIN select lines
6) #USE lines (RS232 etc.)
7) Now #include things like string.h etc.
8) Your code.

Now you can fiddle things a little. The top six sections can all be put into a single include file for example, and loaded as one 'piece'. Some parts can swap, but basically, anything that affects processor configuration, _must_ be loaded before anything that generates code (the clock statement for example generates timing routines). Then the clock statement must exist before anything that uses timings (RS232, SPI etc.). Then the RS232 must be defined before anything that uses it (stdio.h etc.). The 'pass strings' line, changes how code is generated for every string operation involving constants, so must be relatively high up in the order.

Best Wishes
mhz1575



Joined: 20 Jun 2008
Posts: 14

View user's profile Send private message

PostPosted: Wed Jun 11, 2014 12:49 pm     Reply with quote

Hi,
Are you sure that the gps wrote only in nmea ascii format?
Because it's able to send data both nmea or ublox binary protocol.
To chose the right you have first customize the gps by ucenter with the right messages than use it on your pic.

Cheers
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

problem with ublox gps
PostPosted: Thu Jun 19, 2014 8:03 am     Reply with quote

Finally i success to parse the GPS output. I used the code below :

I put the a[]="$GPRMC,195131.00,A,56044,N,03319.28598,E,0.026,,040614,,,A*7A";

to test it and is working fine.

Code:

//parser
#include <string.h>
#include <stdlib.h>


////////////////////////////////////////
typedef struct _GPRMCInfo
{
   char Valid[3];
   char Latitude[20];
   char N_S[3];
   char Longitude[20];
   char E_W[3];
   char Speed[20];




   char Day[5];
   char Month[5];
   char Year[5];
   char Hour[5];
   char Minute[5];
   char Second[5];   

} GPRMCInfo;
////////////////////////////////////////




///////////////////////////////////////////////////////////////////////////////
//copy string (pos n to pos m) from s2 to s1
char* StrnmCpy(char *s1, char *s2, size_t n, size_t m)
{
   int8 i;
   char *s;
   
   for (s=s1, i=n, s2+=n; i<=m; i++)
      *s++ = *s2++;
   *s = '\0';
   
   return s1;
}
///////////////////////////////////////////////////////////////////////////////


void GPRMC_decode(char *GPRMCStr, GPRMCInfo *RMCInfo)
{
int i;

char hour[3],min[3],sec[3];
char DAY[3],MON[3],YEAR[3];
char test[]="GPRMC";
char test2[]="A";
char * pch;

char DELIM[]= ",$*";
pch = strtok(GPRMCStr,DELIM);

         if (strcmp(pch,test)!='0')
         {
                 while (pch != NULL)
                 {
                      
                 switch (i)
                 {
         
                case(1) :
                         ////DONE
                        StrnmCpy(hour,pch,0,1);
                     StrnmCpy(min,pch,2,3);
                     StrnmCpy(sec,pch,4,5);
                      
                     strcpy(RMCInfo->Hour,hour);    
                     strcpy(RMCInfo->Minute,min);
                     strcpy(RMCInfo->Second,sec);
                     
                  break;
                case(2):
                        ////DONE
                  if(strcmp(pch,test2)!='0')//check for A -->VALID DATA
                     strcpy(RMCInfo->Valid,pch);
                     break;
                case(3):
                        //DONE
                       strcpy(RMCInfo->Latitude,pch);
                    break;
                case(4):
                        //DONE
                     strcpy(RMCInfo->N_S,pch);
                     break;
                case(5):
                        //DONE
                        strcpy(RMCInfo->Longitude,pch);
                        break;
               case(6):
                        //DONE
                        strcpy(RMCInfo->E_W,pch);
                   
                     break;
                case(7):
                        //DONE
                           strcpy(RMCInfo->Speed,pch);
                     break;
         
                case(8):
                         StrnmCpy(DAY,pch,0,1);
                     StrnmCpy(MON,pch,2,3);   
                      StrnmCpy(YEAR,pch,4,5);                     
                     strcpy(RMCInfo->Day,DAY);
                     strcpy(RMCInfo->Month,MON);
                     strcpy(RMCInfo->Year,YEAR);
                     break;
         
                case(9):
                        //fprintf(PC,"i:%d\n",i);
                        //fprintf(PC,"\nMAGNETIC:%s\n",pch);       
                        break;
                case(10):
                       //fprintf(PC,"i:%d\n",i);
                       //fprintf(PC,"\nchecksum:%s",pch);       
                       break;
                }
                 pch = strtok(NULL,DELIM);
                i++;
                }
          }
                  
         
delay_ms(100);
}



My problem now is coming when i try to call it from the main.
I used the code below to parse the output from the GPS. The problem is that nothing is printed to the screen. (if i don't use the parser code the output from the GPS printed to PC).

Code:

//main
#include <33fj128GP802.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX 100

#FUSES NOPROTECT     
#FUSES NOIESO       
#FUSES FRC             
#FUSES NOWDT           

#use delay(clock=7.37MHz) //default frequency for RC

#include "parser.c"

#PIN_SELECT U1RX=PIN_B15
#PIN_SELECT U1TX=PIN_B14
#USE RS232(UART1,ERRORS,BAUD=9600,STREAM=PC)

#PIN_SELECT U2TX=PIN_B2
#PIN_SELECT U2RX=PIN_B3
#USE RS232(UART2,ERRORS,BAUD=9600,STREAM=GPS)



char GPSData[128];
int1 GPSDataReady = FALSE;




#INT_RDA2
void RDA_isr(void)
{
   static unsigned int8 GPSDataPtr=0;
   char c;
   //it is generally better to declare variables 'in routine' where they do not
   //want/need to be global
   c = fgetc(GPS); //must use streams
   //fprintf(PC,"Data%s\n", c);
    switch (c)
   {
      case '$':
         GPSDataPtr = 1;
         GPSData[0] = '$';
      break;
     
      case '\n':
         GPSData[GPSDataPtr] = '\0';
         GPSDataPtr = 0;
         GPSDataReady = TRUE;
         //null terminate the string. Avoids possible problems
         //with the library functions.
      break;
     
      default:
         GPSData[GPSDataPtr++ & 0x7F] = c;
      break;
   }
}
void main(void)
{
GPRMCInfo MyGPRMCInfo;
//DateTimeInfo MyDateTimeInfo;
   

   enable_interrupts(INTR_GLOBAL);
   enable_interrupts(INT_RDA2);
//////////////////////////////////
//char a[]="$GPRMC,195131.00,A,56044,N,03319.28598,E,0.026,,040614,,,A*7A";
//////////////////////////////////


while(1)
   {
GPRMC_decode(GPSData, &MyGPRMCInfo);
//fprintf(PC,"\nDATA:%s\n",GPSData);

   fprintf(PC,"\nHOUR:%s\n",MyGPRMCInfo.Hour);
   delay_ms(50);
    fprintf(PC,"\nMINUTE:%s\n",MyGPRMCInfo.Minute);   
   delay_ms(50);
    fprintf(PC,"\nSECOND:%s\n",MyGPRMCInfo.Second);
   delay_ms(50);
   fprintf(PC,"\nTYPE:%s",MyGPRMCInfo.Valid);      
   delay_ms(50);
   fprintf(PC,"\nLATITUDE: %s",MyGPRMCInfo.Latitude);
   delay_ms(50);
   fprintf(PC,"\nN_S: %s",MyGPRMCInfo.N_S);   
   delay_ms(50);
   fprintf(PC,"\nLONGITUDE: %s",MyGPRMCInfo.Longitude); 
      delay_ms(50);
   fprintf(PC,"\nE_W: %s",MyGPRMCInfo.E_W);                                                                                          
   delay_ms(50);                                           
   fprintf(PC,"\nSPEED:%s",MyGPRMCInfo.Speed);                                                               
   delay_ms(50);
    fprintf(PC,"\nDAY: %s",MyGPRMCInfo.Day);
   delay_ms(50);   
fprintf(PC,"\nMONTH: %s",MyGPRMCInfo.Month);
   delay_ms(50);   
fprintf(PC,"\nYEAR: %s",MyGPRMCInfo.Year);
   delay_ms(50);

//delay_ms(800);
}

}




What is going wrong ???
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 19, 2014 9:43 am     Reply with quote

perhaps you can explain what this line of code is actually doing ??

GPSData[GPSDataPtr++ & 0x7F] = c;

esp----------------------****

also

you've got a LOT of unnessesary delay_ms(50); in printing info to the PC...
..that you should delete.



since your parser works fine with KNOWN data,you may not be getting good data from the GPS?

What is displayed when you printout the RAW GPS data( NOT parsed).

hth
jay
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Thu Jun 19, 2014 10:23 am     Reply with quote

temtronic wrote:
perhaps you can explain what this line of code is actually doing ??

GPSData[GPSDataPtr++ & 0x7F] = c;
This is a clever way of ensuring the buffer with size 128 does not overflow. I don't like clever code, especially when there is no comment to explain what is being done and why.

There is a bug in this code because in the other two locations where GPSDataPtr is being used the mask is missing and potential writing outside buffer memory is waiting to happen.

much better would be to keep it simple. Only optimize when performance really has shown to be an issue:
Code:
GPSData[GPSDataPtr] = c;
GPSDataPtr++;
if (GPSDataPtr >= 128)
    GPSDataPtr = 0;
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 19, 2014 10:32 am     Reply with quote

You have the flag variable 'GPSDataReady' that tells you when you have
a full GPS string available. It's set = TRUE when a string is available.

In main(), you call GPRMC_decode(), but you don't know for sure if
you even have a GPS string available, because you don't check
'GPSDataReady'.

When you have an interrupt routine capture some data (such as
#int_rda2), you tell the main program that you have the data by using
a flag variable. Your code has that, but you have to actually check the
flag in main() before you attempt to use the data. Then you have to
set the flag = FALSE, so it's ready for the next string to be received.

If you look at the code that you posted in your 1st post in this thread,
it is actually doing all this stuff. Read your code.
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

problem with ublox gps
PostPosted: Sat Jun 21, 2014 8:30 am     Reply with quote

I used this code :
Code:

while(1)
   {

if (GPSDataReady)
   {
   GPRMC_decode(GPSData, &MyGPRMCInfo);
   if (MyGPRMCInfo.Valid == 'A')
   {

               fprintf(PC,"\nHOUR:%s\n",MyGPRMCInfo.Hour);
                fprintf(PC,"\nMINUTE:%s\n",MyGPRMCInfo.Minute);   
                fprintf(PC,"\nSECOND:%s\n",MyGPRMCInfo.Second);
               fprintf(PC,"\nTYPE:%s",MyGPRMCInfo.Valid);      
               fprintf(PC,"\nLATITUDE: %s",MyGPRMCInfo.Latitude);
               fprintf(PC,"\nN_S: %s",MyGPRMCInfo.N_S);   
               fprintf(PC,"\nLONGITUDE: %s",MyGPRMCInfo.Longitude); 
               fprintf(PC,"\nE_W: %s",MyGPRMCInfo.E_W);                                                                                          
               fprintf(PC,"\nSPEED: %s",MyGPRMCInfo.Speed);                                                               
                fprintf(PC,"\nDAY: %s",MyGPRMCInfo.Day);
               fprintf(PC,"\nMONTH: %s",MyGPRMCInfo.Month);
               fprintf(PC,"\nYEAR: %s",MyGPRMCInfo.Year);
               delay_ms(100);
        }
   }
    GPSDataReady = FALSE;
 }



But i still have problem. I can't see anything on the pc screen


How to fix it ?????
temtronic



Joined: 01 Jul 2010
Posts: 9241
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Sat Jun 21, 2014 8:57 am     Reply with quote

... I can't see anything on the pc screen ....

do you mean NO data from the GPS
OR
do you mean NOTHING at all ??

...fprintf(PC,"\nHOUR:%s\n",MyGPRMCInfo.Hour); ...

do you get the 'HOUR' text and NOT the 'MyGPRMCInfo.Hour' data ?

There is a BIG difference !!

In the code snippet you've posted there are TWO conditionals that BOTH must be true to display anything....

hth
jay
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

problem with ublox gps
PostPosted: Sat Jun 21, 2014 9:15 am     Reply with quote

When i said "... I can't see anything on the pc screen .... "

i mean that i can't see the data from the GPS.

If i put a fprintf(PC,"DATA:%s",GPSData);

in the while (with out call the parser) i can see data.

With statement "...fprintf(PC,"\nHOUR:%s\n",MyGPRMCInfo.Hour); ... "

i expect to receive the MyGPRMCInfo.Hour


(from the parser )

Code:

***********
if (strcmp(pch,test)!='0')
         {
                 while (pch != NULL)
                 {
                      
                 switch (i)
                 {
         
                case(1) :
            
                                    StrnmCpy(hour,pch,0,1);
                     StrnmCpy(min,pch,2,3);
                     StrnmCpy(sec,pch,4,5);
                     strcpy(RMCInfo->Hour,hour);    
                     strcpy(RMCInfo->Minute,min);
                     strcpy(RMCInfo->Second,sec);
                     
                  break;
***********




What is going wrong ???????
andys



Joined: 23 Oct 2006
Posts: 175

View user's profile Send private message

problem with ublox gps
PostPosted: Sun Jun 22, 2014 5:21 am     Reply with quote

anyone who can help me to solve this problem ?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2, 3, 4, 5, 6  Next
Page 3 of 6

 
Jump to:  
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