SparkFun Forums 

Where electronics enthusiasts find answers.

Tips and questions relating to the GPS modules from SFE
By danrulz01
#15535
hay everyone. first post (in this forum). i was looking at purchasing a 20 Channel EM-406 SiRF III Receiver with Antenna, for use with an atmega 128 or what ever i got lying around i guess. but my question was, how difficult is it to operate one. i can use the usart and timeres and tons of other things but havent used I2c yet so if it uses that im up the creek. i dont have a real plan for doing anything with it so i guess just testing basic funcs to start with is ok.
it will prob go into my robot platform later on.

also is there any "SIMPLE" source code available that i can just use to build on?

:arrow: Dan :!:
By Calebcohoon
#15565
Hey Dan!

Well, I own a couple of the EM-406 receivers and they are very easy to use. Just apply power to the Vcc pin and ground to Vdd pins and voila the module will start outputing NMEA 0183 data. You said you already know how to use the uarts on your microcontroller, so just connect the Tx pin of the GPS module to the Rx of the micro and thats it. Just make sure your micro's serial ports are running at 4800 baud. The GPS module doesn't have a I2C interface so you should be fine. The only tricky part now is writing code to parse the NMEA string and get the data you want. Here's some easy code that I use in my projects that I got from the Ghetto GPS Project websitehttp://www.mhd.miun.se/~stok/ghetto-gps/ with
some modification:
Code: Select all
#include <8051.h> // put your micro's header file here
#include <string.h>
#include <stdlib.h>

static char receivebuffer[44]; // buffer to hold the NMEA string
uchar idx = 0;
uchar temprec;

int i;

//structure to hold the latitude and longitude
struct nmea_gps_data{
    char latitude[9];
    char longitude[10];
};

void nmea_gprmc_parse(char *line)
{

  //here im finding the $GPRMC string but you can change it to look for other sentences 

  if(line[0] == '$' && line[1] == 'G' && line[2] == 'P')
    {
      if(line[3] == 'R' && line[4] == 'M' && line[5] == 'C') // GPRMC
        {
             // copy the longitude and latitude values in the structure variables
  	   		memcpy(gps_data.latitude, line+20, sizeof(gps_data.latitude));
  	   		memcpy(gps_data.longitude, line+32, sizeof(gps_data.longitude));

  	   

        }
    }
}

// this interrupt just keeps reading data from the GPS module continuously
// since your using a atmega chip youll have to change what interrupts or just put a receive function in a while loop in your main function

void ser_rec(void) interrupt 4 using 1{

  if(RI)// this bit flag is set when a byte has been received
  {
	// change the SBUF varible to whatever variable your micro stores the incoming bytes from
  	temprec = SBUF;

                // once we find the end of a string send it to the parser function above to see if its 

the sentence we want
   	if(temprec != '\n')
   	{
		receivebuffer[idx++] = temprec;
	} else {
		idx = 0;

                     // found a sentence now parse it
		nmea_gprmc_parse(receivebuffer); 
		
	}

   	RI = 0;
   }
}
Well I hope that code helps you a little. I'm sure you'll have to do some modification on it to fit your project but it shouldn't be much. Let us know how your project goes. Later, Caleb
By danrulz01
#15569
thanks heaps for the code. it sounds like no probs to use.. i ordered one, and am looking forward to its arival. i guess i wouldnt be hard to connect it to the hyper terminal either. ill let u know how it goes

:arrow: Dan :!: