Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

PIC18 + GPS Help

Status
Not open for further replies.

Toonzaka

New Member
Hello, I recently purchased a Garmin 18x LVC GPS unit to use with my micro controller. I am using a PIC18 with to communicate to the GPS unit and hyperterminal to see the data. Now I am running into some problems. For one, I am very new to GPS, this is actually the first time I am working with one and I have no idea if this unit is on or off because I am not receiving any data from the unit even after 5 minutes.

Now for the controller, as I said I am using a C-Stamp micro controller that uses a PIC18. I am not sure if anyone on this forum is familiar with that controller but it has its own syntax for sending/receiving info. I am using two simple lines that SHOULD receive any data from the GPS unit but it is not. I a, also using MATLAB and the C18 compiler.

I have a few questions now as well...

For the GPS Unit does anyone know if you have to initialize the system? I have been trying to send it a string of $PGRMC,0D0A which should echo back to me. I also read that I need to end each line with return and line feed and those are the corresponding hex values for that at the end.

Any help is welcome. I just need to get this working!
 
Yes, quadruple checked that. Right now I have an RS232 -> USB connection from the controller to my laptop. I also have the pins that use that connection hooked up to the GPS unit. I am thinking that maybe I cannot share the connection? Otherwise yes everything is connected correctly.
 
You should be able to hook the GPS to your PC and see the data in hyperterminal. Most (I think all) GPS units default to outputting a position string every second and so you shouldn't have to send it any commands. To connect to a Pic you will need a MAX232 chip to invert and level shift the signal.

Mike.
 
Alright I tried connecting the GPS Directly to the RS232 cable to see if I can get anything on the hyper terminal, and there was nothing showing. I am uncertain as to what I am doing wrong...
 
Does the db9f shell contain the BJT's or does one have to go out and make the circuit? Like can I go to radio shack tomorrow (oh god did I really say that when tomorrow is black friday!?!?) and buy one so then I can hook it up and have it working successfully? Also will a simple amp be good enough to boost the signal? I believe that the GPS outputs 5V.

Sorry for the stupid questions but like I said I am a programmer kinda guy, worked a little bit with circuitry so I know how to wire something up but when it comes to specifics... Well they just don't teach that that much in school :D
 
You will need to get the BJT's (i think they are mosfets from the schematic) and i doubt radio shack will have that part number, worth a try though.

Or you could just use a max232 if you came across it and all the right parts.
 
Unless you can get it working with hyperterminal there is no point trying to get it working with a Pic. Just connect the output from the GPS to pin 2 of a DB9 connector and Gnd to pin 5 and it should work in hyperterminal. For more info see **broken link removed**.

Mike.
 
Now with the max232 i will need some capacitors and resistors correct? Also is there any other way of knowing that the GPS is working. The micro controller that I am working with has USART pins. I am using the receive pin to get the data and then since these pins are also connected to the RS232 connection which I have plugged into my PC I am just resending the data on the send pin which I would think sends the data to my computer. But it is not... Can I do this or is this type of shared connection wrong?
 
Some GPS do indeed require a sentence to start sending data. It's uncommon. Looking at the Garmin 18x LVC GPS spec, it is not one of those. Sec 4.1.5 describes which sentences are ON by default.

If you have an oscilloscope, you should check the data out pin from the GPS. It should drop from 5v in bursts of data. You can probably check for it with a multimeter too.

You do have a level problem.
The module's IO is 5v/0v logic. The RS232-to-USB dongle, or your PC's serial port (who's even got those anymore?) uses voltages of like +10v/-10v on the RS232 side. The MAX232 will fix that. Actually, quick and dirty fix- that dongle will probably accept 5v/0v logic in as well as +10v/-10v, but it's logically inverted from RS232 hi/lo levels. If you disconnect the dongle's data out TO the module (because electrically the GPS module can't take it) and reconfigure the COM port with inverted levels (if you can), then it'll read the default GPS sentences coming out.

Make sure your COM port is set to the correct baud rate, and 8N1. If the baud's wrong, you may get gibberish or nothing at all.

Personally, I do not recommend the "Stamp" in any way shape or form. You can't write code for the PIC18 on those. The PIC18 has a Stamp instruction engine which executes Stamp instructions which is really pointless (very very slow too) and you don't learn much of anything about microcontrollers doing this. Nor will any of the work you've done be of use when you DO decide to switch to PIC18's for real. There's the MCC18 compiler, free from Microchip, which DOES turn C code into PIC18 instructions for real. The only difference is you need to buy a programmer like an ICD2 (not expensive) and buy the PICs themselves instead of the expensive Stamp units.
 
Last edited:
Thank you Oznog, I wish I could just use the PIC18 but I am forced to use the Stamp. I will try all of your suggestions. And thank you everyone for the help and I will keep up to date with my progress.
 
Last edited:
All the GPS receivers that I have used just output data once a second, without being asked. It doesn't usually make any difference if the GPS has not got a lock. It will still output data, even if it is zeros.

Some GPS receivers output the data on 0 - 3V (inverted compared to RS232) so you don't need level conversion. The signal can be connected directly to the PIC. The voltage will normally be 3V when idle.

As the data burst lasts about half a second you can actually see if that is happening with an LED or a voltmeter.

I would program the PIC18 directly, and not use a C-Stamp.

I suggest the following stages:-

1) Get the PIC to flash an LED
2) Get the PIC to light an LED when it sees a low voltage on the GPS output. That should make the LED flicker for about half a second each second and off the rest of the time.
3) Get the PIC to light an LED briefly when it receives the $ symbol. There are about 10 in each data burst from a GPS so you'll see about 10 brief flashes in half a second, then half a second of nothing.
4) Get the PIC to light the LED briefly when it receives "$GPRMC". That should give a flash once a second.

Then you can start looking at the data in more detail.
 
Alright I purchased a db9f and was able to read the GPS data on Hyperterminal. I thank all of you for the help again! The next step I believe is parsing the data and getting the Stamp to read each of the lines which I should be able to do. Again I will keep everyone updated and I really appreciate all of the help. Thank you all so much!
 
Thank you Oznog, I wish I could just use the PIC18 but I am forced to use the Stamp. I will try all of your suggestions. And thank you everyone for the help and I will keep up to date with my progress.

What situation is forcing the use of Stamp?

You may need to send commands to the GPS soon. You'll have to format the command exactly, including a checksum. This is kind of a pain because when you screw something up, it's hard to know what was screwed up because nothing happens (the GPS typically rejects any sentence with a bad checksum or invalid formatting). Takes a little while. Best to check your checksum generator on sentences coming FROM the GPS, it's the same method.
 
There are lots of GPS strings. However all the GPS receivers that I have seen have a default set that includes:
$GPRMC (lat, long, date, speed and track)
$GPGGA (lat, long, height and horizontal position error)
$GPGSA (satellites in view, signal levels, horizontal and vertical position error)

($GPGSA is often only transmitted every 5 seconds, and it may need several strings to list all the satellites)

The point is that those include all the information that you want in just about all circumstances.

The GPS protocol allows for a whole load of things that you never need nowadays. For instance, you can tell a GPS receiver a destination, and it will tell you a course and distance to that destination. I can't see why you would want that as you might as well get the PIC or C-Stamp or whatever to do that calculation itself, as the PIC or C-Stamp must have the position of the destination in order to send it to the GPS, and it's easier to get that to do the calculation.

Therefore you can almost certainly read the default strings and get all the data you want without ever sending data to the GPS.

If your GPS receiver doesn't have an internal battery to record the ephemeris data, it gets more complicated if you want a fast fix. However, the only GPS receivers like that are basic GPS engines that are circuit level modules, not consumer products in a pretty case.
 
I was wondering really quickly if anyone knew what the GPS units data is received as by the microcontroller? Is it a string or just plain ASCII?
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top