Saturday, September 21, 2013

GPS interfacing with AT89s52

   Today, I am going to provide a brief description on interfacing GPS receiver with AT89s52( a microcontroller from 8051 family). The GPS receiver used is GT3221R. The specification of this GPS receiver (GT3221R) can be found in the manufacturers website.Before we go to this post first it is recommended to read a post on serial communication using AT89s52. First, I will be telling how this GPS receiver works and then we will go in the process of interfacing it with AT89s52.
   
   Looking at the history, we see that GPS was first used by US navy in millitary process but now any individual can use this device for their desired application if they have a GPS receiver. Currently, 24 to 32 satellite revolving in medium earth orbit(MEO) are used for global positioning system. The GPS receiver works when four or more among this satellites in MEO are in line of sight with the receiver. Nowadays, GPS receiver has gained a wide use in navigation and tracking purpose and are used in many application  like vehicle navigation, tracking particular person, researh of animals(by attaching GPS receiver and then tracking them) etc.

   GPS receiver receives the co-ordinates i,e longitude and latitude of particular location in NMEA message format. There are different form of NMEA message format received by GPS receiver like GGA,GSA,GSV,RMC etc. Among them we will extract location co-ordinates using GGA message packets. The format of this packet is shown below

fig:- GGA message format

The algorithm used to extract Co-ordinates from GGA format is given below.

1. First check if first six received data is "$GPGGA". If not, repeat the process.
2. Find the position of commas in the message packet and store them in suitable variable.
3. Then from comma position 4 to 6 read data and store it in the array representing longitude.
4. From comma position 2 to 4 read data and store it in the array representing latitude.
5. Repeat the process if you want to receive co-ordinates again.

Using this message format (GGA) you can also obtain the current UTC time. For this you need to read data from comma position 1 to comma position 2.

You can easily write code to receive co-ordinates from GT3221R using this algorithm. And when I was experimenting with this receiver I faced some problems like not receiving co-ordinates when I was in the ground floor of multiple floor building and the device failed to give location(it used to give zero longitude and zero latitude) when it was used after a long period of interval. I had to wait powering device for more than an hour to get co-ordinates while using it again after a long duration. So if you get same problem just wait powering up the device for some period and then you will start getting co-ordinates. 


To download complete source code click here.

No comments: