PDA

View Full Version : GPS parser for GPRMB and GPRMC



btaylor
- 1st January 2007, 01:44
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

sradayda
- 17th April 2010, 18:05
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

Art
- 18th April 2010, 13:14
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.

minoenea
- 16th May 2011, 17:01
Dear all,
I have problems with the parser of GPS string using PIC32.


Could you help me please?

Do you have an example please?

minoenea
- 17th May 2011, 16:07
include <plib.h>
#include <stdio.h>
#include <stdlib.h>
#include <GenericTypeDefs.h>


#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....

charudatt
- 17th November 2011, 12:42
Could you please show me how to extract the speed component from $GPRMC, its variable lenght......

Thank you.