+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2003
    Posts
    41

    Default GPS parser for GPRMB and GPRMC

    Here is a routine for a PIC16F877 that will extract all the GPRMB data fields and selected GPRMC fields. It works with a Garmin Foretrex as the NMEA source and I use both an on-board LCD and a HP-200LX as a portable RS232 terminal to display results.

    Cheers
    Brian
    Attached Files Attached Files

  2. #2
    Join Date
    Apr 2010
    Posts
    6

    Default

    thank you for sharing your code, i really appreciate that.
    but could you please provide me with the hardware connection between the GPS and the PIC.


    thnx again

  3. #3
    Join Date
    Aug 2003
    Location
    Australia
    Posts
    550

    Default

    Quote Originally Posted by sradayda View Post
    thank you for sharing your code, i really appreciate that.
    but could you please provide me with the hardware connection between the GPS and the PIC.


    thnx again
    The source makes it pretty obvious.

    A 16F877 running at 20MHz, and LED connected to RA0,
    GPS connected RX to RD7, Tx to RD6, etc.

    188 is the serin2 mode for 4800 baud rate so the GPS device will have to
    be set to 4800 baud, or the basic program changed.

  4. #4
    Join Date
    May 2011
    Posts
    2

    Default Re: GPS parser for GPRMB and GPRMC

    Dear all,
    I have problems with the parser of GPS string using PIC32.


    Could you help me please?

    Do you have an example please?

  5. #5
    Join Date
    May 2011
    Posts
    2

    Default Re: GPS parser for GPRMB and GPRMC

    include
    #include
    #include
    #include


    #pragma config FPLLODIV = DIV_1, FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FWDTEN = OFF, FCKSM = CSECME, FPBDIV = DIV_1
    #pragma config OSCIOFNC = ON, POSCMOD = XT, FSOSCEN = ON, FNOSC = PRIPLL
    #pragma config CP = OFF, BWP = OFF, PWP = OFF

    #define GetSystemClock() (80000000ul)
    #define GetPeripheralClock() (GetSystemClock()/(1 << OSCCONbits.PBDIV))
    #define GetInstructionClock() (GetSystemClock())
    #define buf_new 1024


    void SendDataBuffer(const char *buffer, UINT32 size);
    UINT32 GetMenuChoice(void);
    UINT32 GetDataBuffer(char *buffer, UINT32 max_size);

    char gps_string[buf_new];
    float lat, lon, lat1, lon1;
    int fix, qual, dd, led=0;
    char *start_ptr, *end_ptr, *latitude, *longitude, *quality;

    void parse(volatile unsigned char *string)
    {
    printf("%s\n", gps_string);


    // LATITUDE
    start_ptr=strchr(gps_string,','); //find start of time field
    start_ptr=strchr(start_ptr+1,','); //find start of latitude field
    latitude = start_ptr+1; //find first character in latitude field
    printf ("Latitude starts at gps_string[%d]\n",latitude-gps_string);
    end_ptr=strchr(latitude,','); //find end of latitude field
    printf ("Latitude ends at gps_string[%d]\n",end_ptr-gps_string-1);
    if (latitude-gps_string>=end_ptr-gps_string) //determine if latitude exists
    {printf("Latitude not received\n");}
    else
    {
    lat=atof(latitude); //convert to float
    printf("Latitude = %f\n",lat);
    }
    // LATITUDE

    // LONGITUDE
    start_ptr=strchr(start_ptr+1,',');
    start_ptr=strchr(start_ptr+1,',');
    longitude = start_ptr+1;
    printf ("Longitude starts at gps_string[%d]\n",longitude-gps_string);
    end_ptr=strchr(longitude,',');
    printf ("Longitude ends at gps_string[%d]\n",end_ptr-gps_string-1);
    if (longitude-gps_string>=end_ptr-gps_string)
    {printf("Longitude not received\n");}
    else
    {
    lon=atof(longitude);
    printf("Longitude = %f\n",lon);
    }
    // LONGITUDE

    // QUALITY
    start_ptr=strchr(start_ptr+1,',');
    start_ptr=strchr(start_ptr+1,',');
    quality = start_ptr+1;
    printf ("Quality starts at gps_string[%d]\n",quality-gps_string);
    end_ptr=strchr(quality,',');
    printf ("Quality ends at gps_string[%d]\n",end_ptr-gps_string-1);
    if (quality-gps_string>=end_ptr-gps_string)
    {
    printf("Quality not received\n");

    }
    else
    {
    qual=atoi(quality);
    printf("Quality = %d\n",qual);
    if (qual==1|qual==2){
    printf("Fix acquired\n");

    }
    else{
    printf("Fix not aquired\n");

    }
    }

    }



    int main(void)
    {
    UINT32 menu_choice;
    UARTConfigure(UART2, UART_ENABLE_PINS_TX_RX_ONLY);
    //UARTSetFifoMode(UART2, UART_INTERRUPT_ON_TX_NOT_FULL | UART_INTERRUPT_ON_RX_NOT_EMPTY);
    UARTSetLineControl(UART2, UART_DATA_SIZE_8_BITS | UART_PARITY_NONE | UART_STOP_BITS_1);
    UARTSetDataRate(UART2, GetPeripheralClock(), 4800);
    UARTEnable(UART2, UART_ENABLE_FLAGS(UART_PERIPHERAL | UART_RX | UART_TX));



    while(1)
    {
    if(gps_string[0]=='$' && gps_string[1]=='G' && gps_string[2]=='P' && gps_string[3]=='G' && gps_string[4]=='G')
    parse(gps_string);

    }
    while(1)
    {

    UINT32 rx_size;
    rx_size = GetDataBuffer(gps_string, 1);
    SendDataBuffer(gps_string, rx_size);

    }

    return -1;
    }



    // ************************************************** ***************************
    // void UARTTxBuffer(char *buffer, UINT32 size)
    // ************************************************** ***************************
    void SendDataBuffer(char *buffer, UINT32 size)
    {
    while(size)
    {
    while(!UARTTransmitterIsReady(UART2))
    ;

    UARTSendDataByte(UART2, *buffer);

    buffer++;
    size--;
    }

    while(!UARTTransmissionHasCompleted(UART2))
    ;
    }



    // ************************************************** ***************************
    // UINT32 GetDataBuffer(char *buffer, UINT32 max_size)
    // ************************************************** ***************************
    UINT32 GetDataBuffer(char *buffer, UINT32 max_size)
    {
    UINT32 num_char;

    num_char = 0;

    while(num_char < max_size)
    {
    UINT8 character;

    while(!UARTReceivedDataIsAvailable(UART2))
    ;

    character = UARTGetDataByte(UART2);

    // if(character == '\r')
    // break;

    *buffer = character;

    buffer++;
    num_char++;
    }

    return num_char;
    }




    Ragazzi questo e' tutto il codice scritto per PIC32

    Mi dà questi errori


    ource\main.c: In function `parse':
    source\main.c:32: warning: implicit declaration of function `strchr'
    source\main.c: At top level:
    source\main.c:128: error: conflicting types for 'SendDataBuffer'
    source\main.c:17: error: previous declaration of 'SendDataBuffer' was here
    source\main.c:128: error: conflicting types for 'SendDataBuffer'
    source\main.c:17: error: previous declaration of 'SendDataBuffer' was here


    non capisco.... sto impazzendo.....aiuttoooooooooooooooooooo

    grazie a tutti....

  6. #6
    Join Date
    Sep 2003
    Location
    INDIA
    Posts
    161

    Default Re: GPS parser for GPRMB and GPRMC

    Could you please show me how to extract the speed component from $GPRMC, its variable lenght......


    Hi, we are pleased to see that you are using our forum.

    We'd like you to become a member of our community. Membership is FREE, please REGISTER and view our forums without these annoying reminders!

    Once registered you may post on the forums, download from the file areas and use the WIKI without interruption.






    Thank you.

Similar Threads

  1. GPS decoding problems
    By vladimir059@hot in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 25th February 2012, 10:57
  2. GPS Logging
    By eoasap in forum GPS
    Replies: 0
    Last Post: - 14th February 2006, 17:22
  3. GPS logger?
    By Gonzzo in forum Off Topic
    Replies: 11
    Last Post: - 13th February 2006, 13:25

Members who have read this thread : 14

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts