PDA

View Full Version : GPS module + PIC



flotulopex
- 9th April 2010, 18:35
Hello,

I'm trying to communicate with a GPS module http://www.futurlec.com/GPS.shtml.

Before I connect it to a PIC+LCD, I try to communicate with the GPS module via a PC terminal.

Unfortunately, I can't get any "understandable" message from the module; I might receive SIRF information instead of NMEA messages, I don't know.

This is what I see on my terminal:
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4175&stc=1&d=1270833454">

If my guess is right, I would need to switch from SIRF to NMEA protocol. There are to examples hereunder in the doc (full doc attached).
<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4174&stc=1&d=1270833364">

I don't understand how to calculate the checksum.

I found a cool checksum calculator, HashCalc from SlavaSoft Inc. But I can't find a similar checksum corresponding to both examples.

Can someone tell me in "simple words" how the checksum in both samples above have been calculated and the exact string I would have to send the data to the module?

Is it "$PSRF100,1,4800,8,1,0*0D0A" or "$PSRF100,1,4800,8,1,0*0D,0A" or "$PSRF100,1,4800,8,1,0*<0D><0A>" or anything else?

I've spent quite a few hours on this one and no success so far so any help or info is very welcome ;)

mackrackit
- 9th April 2010, 18:53
You need an inverter chip or circuit . (MAX232)

flotulopex
- 10th April 2010, 10:48
Thanks Dave,

The MAX232 in my drawer did the trick ;)

Any idea about the checksum calculation?

This is what I did up to now in EXCEL but trying to convert HEX to BIN will rise an error.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4178&stc=1&d=1270892845">

mackrackit
- 10th April 2010, 12:50
10001000000
is the number excel failed on but other than that I do not know. I will have to look into it.

ScaleRobotics
- 10th April 2010, 13:14
Here is one check sum solution for gps:



gpsdata var byte[82] ' Max length of a GPS sentence is 82 bytes.

DoCS:
i = 0 ' Initialize the position counter

WHILE gpsdata[i] != "*" ' Count everthing until the *
cs = cs ^gpsdata[i] ' XOR for checksum
i = i + 1 ' Increment position counter
WEND

' A quick and easy atoh function
' Make it a seperate label if we add more atoh conversions in the future
LOOKDOWN gpsdata[i+1],["0123456789ABCDEF"],tempbyte
gpscs = tempbyte * 16
LOOKDOWN gpsdata[i+2],["0123456789ABCDEF"],tempbyte
gpscs = gpscs + tempbyte

' Flag bad data "V" if checksum doesn't add up.
' Or if the sentence is less then 20 chars long
' Which means there is no active waypoint to go to.
' Should be "A" otherwise.
IF (cs != gpscs) OR (i < 20 )THEN
gpsvalid = 0
ELSE
gpsvalid = 1
ENDIF
RETURN

flotulopex
- 16th April 2010, 11:32
- Reading & parsing NMEA sentences is ok;
- Calculating checksum is ok;
- Sending data to GPS module is not ok.

I have connected the GPS module via the MAX232 chip to my serial PC port both ways so I should be able to "talk" to my module.

Unfortunately, only reading out (receiving) the GPS module is working.

I checked the MAX chip with my oscillo and the signals are okay (TX & RX) on both levels (RS232 and TTL).

I'm sending an example from the module's datasheet to enable a VTG sentence but it won't work.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4205&stc=1&d=1271413381">

I just never see this VTG data appear.

<img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4207&stc=1&d=1271413812">

Any idea?

flotulopex
- 16th April 2010, 11:49
Strange....

I just restarted the terminal and... it works now - I can sent messages to the module.

Must be a kind of magic (?)

Ioannis
- 16th April 2010, 15:29
Is it Hyperterminal?

Ioannis

flotulopex
- 18th April 2010, 20:26
No, it's MicroCode Studio's terminal.

But I checked with HT too and did the same (?).

Nevermind, it works now :)

flotulopex
- 22nd April 2010, 08:51
Hello there,

I just finished this piece of code and it works fine. It will simply display the GPS course & speed.

I finally connected the GPS module's TX directly to a TTL port of my PIC (no level-shifter such as MAX232 used) with the correspondant mode settings.

Everything is working fine appart from the NOGPS routine.

When I disconnect the GPS's TX from the PIC's port, the NOGPS routine will never appear.

Any idea what's wrong?
<html><head></head><body><!--StartFragment--><pre><code><font color="#000080"><i>' PIC 16F690 Fuses
</i></font><font color="#008000">@ DEVICE FCMEN_OFF
@ DEVICE IESO_OFF
@ DEVICE BOD_OFF
@ DEVICE CPD_OFF
@ DEVICE PROTECT_OFF
@ DEVICE MCLR_OFF
@ DEVICE PWRT_OFF
@ DEVICE WDT_OFF
@ DEVICE XT_OSC

</font><font color="#000080"><i>' Registers 76543210
</i></font>OPTION_REG = %10000000 <font color="#000080"><i>'PORT A&amp;B Pull-Ups disabled (look WPUA &amp; WPUB)
</i></font>ANSEL = %00000000 <font color="#000080"><i>'Disable analog inputs Channels 0 to 7
</i></font>ANSELH = %00000000 <font color="#000080"><i>'Disable analog inputs Channels 8 to 11
</i></font>ADCON0 = %00000000 <font color="#000080"><i>'A/D Module is OFF
</i></font>CM1CON0 = %00000000 <font color="#000080"><i>'Comparator1 Module is OFF
</i></font>CM2CON0 = %00000000 <font color="#000080"><i>'Comparator2 Module is OFF
</i></font>INTCON = %00000000 <font color="#000080"><i>'INTerrupts CONtrol
</i></font>TRISA = %00000001 <font color="#000080"><i>'Set Input/Output (0 to 5)
</i></font>PORTA = %00000000 <font color="#000080"><i>'Ports High/Low (0 to 5)
</i></font>TRISB = %00000000 <font color="#000080"><i>'Set Input/Output (4 to 7)
</i></font>PORTB = %00000000 <font color="#000080"><i>'Ports High/Low (4 to 7)
</i></font>TRISC = %00000000 <font color="#000080"><i>'Set Input/Output (0 to 7)
</i></font>PORTC = %00000000 <font color="#000080"><i>'Ports High/Low (0 to 7)

'-------------------------------------------------------------------------------
' LCD cabling
'- ( 1) Vss - GND
'- ( 2) Vdd / Vcc +5V
'- ( 3) Vee / Vo / Contrast adjust / Pot 4k7(1-2-W3) or R2k2(GND-3)
'PORTC.1 ( 4) RS
'- ( 5) R/W -&gt; to Vss
'PORTC.2 ( 6) E
'PORTB.4 (11) D4
'PORTB.5 (12) D5
'PORTB.6 (13) D6
'PORTB.7 (14) D7

</i></font><b>DEFINE </b>LCD_DREG PORTB <font color="#000080"><i>'LCD data port
</i></font><b>DEFINE </b>LCD_DBIT 4 <font color="#000080"><i>'LCD data starting PORT.bit (0 or 4)
</i></font><b>DEFINE </b>LCD_RSREG PORTC <font color="#000080"><i>'LCD register select port
</i></font><b>DEFINE </b>LCD_RSBIT 1 <font color="#000080"><i>'LCD register select bit
</i></font><b>DEFINE </b>LCD_EREG PORTC <font color="#000080"><i>'LCD enable port
</i></font><b>DEFINE </b>LCD_EBIT 2 <font color="#000080"><i>'LCD enable bit
</i></font><b>DEFINE </b>LCD_BITS 4 <font color="#000080"><i>'LCD bus size 4 or 8
</i></font><b>DEFINE </b>LCD_LINES 2 <font color="#000080"><i>'Number lines on LCD

'-------------------------------------------------------------------------------
</i></font>INIT:
Ctr_A <b>VAR BYTE </b><font color="#000080"><i>'Counter
</i></font>GPS_D <b>VAR BYTE</b>(80)<font color="#000080"><i>'Incomming data bit array
</i></font>Spd_U <b>VAR WORD </b><font color="#000080"><i>'Speed Units
</i></font>GPSfrom <b>VAR </b>PORTA.0 <font color="#000080"><i>'use a TTL I/O port on PIC!
</i></font>GPSbps <b>VAR WORD
</b>GPSbps = 32956 <font color="#000080"><i>'Open,True,N,4800bps (TTL level)
</i></font>Timeout <b>CON </b>3000
CommaCnt <b>VAR BYTE </b><font color="#000080"><i>'comma count

</i></font><b>PAUSE </b>1000
<b>LCDOUT </b>$FE, 1

<font color="#000080"><i>' Custom character definition
</i></font><b>LCDOUT </b>$FE,$40,$0C,$12,$12,$0C,$00,$00,$00,$00 <font color="#000080"><i>'character 0 = &quot;&deg;&quot;
</i></font><b>LCDOUT </b>$FE,$48,$14,$18,$14,$00,$1E,$15,$15,$00 <font color="#000080"><i>'character 1 = &quot;km&quot;

</i></font><b>LCDOUT </b>$FE,2,<font color="#FF0000">&quot;GPS v1.1&quot;
</font><b>PAUSE </b>3000

<font color="#000080"><i>'-------------------------------------------------------------------------------
</i></font>GPVTG:
<font color="#000080"><i>' Get VTG sentence and store it into GPS_D var until &quot;*&quot; is found
</i></font><b>SERIN2 </b>GPSfrom,GPSbps,Timeout,NOGPS,[WAIT(<font color="#FF0000">&quot;$GPVTG,&quot;</font>),<b>STR </b>GPS_D\<font color="#FF0000">&quot;*&quot;</font>]

<font color="#000080"><i>' extract COURSE data
</i></font>Ctr_A = 0
cou_u = 0
<b>WHILE </b>GPS_D(Ctr_A) != <font color="#FF0000">&quot;.&quot;
</font>Cou_u = 10 * cou_u + (GPS_D(Ctr_A)-48)
Ctr_A = Ctr_A + 1
<b>WEND

</b><font color="#000080"><i>' locate SPEED data after 6th comma
</i></font>Ctr_A = 0
CommaCnt = 0
<b>WHILE </b>CommaCnt &lt; 6
<b>IF </b>GPS_D(Ctr_A) = <font color="#FF0000">&quot;,&quot; </font><b>THEN </b>CommaCnt = CommaCnt + 1
Ctr_A = Ctr_A + 1
<b>WEND

</b><font color="#000080"><i>' extract SPEED data - leave tenths
</i></font>Spd_U = 0
<b>WHILE </b>GPS_D(Ctr_A) != <font color="#FF0000">&quot;.&quot;
</font>Spd_U = 10 * Spd_U + (GPS_D(Ctr_A)-48)
Ctr_A = Ctr_A + 1
<b>WEND

LCDOUT </b>$FE,1
<b>LCDOUT </b>$FE,2,<b>DEC </b>cou_u,0,<font color="#FF0000">&quot; &quot;</font>,<b>DEC </b>Spd_U,1
<b>GOTO </b>GPVTG:

<font color="#000080"><i>'-------------------------------------------------------------------------------
</i></font>NOGPS:
<b>LCDOUT </b>$FE,2,<font color="#FF0000">&quot; No GPS &quot;
</font><b>PAUSE </b>1000
<b>GOTO </b>GPVTG:

<b>END
</b></code></pre><!--EndFragment--></body>
</html>

Ioannis
- 22nd April 2010, 09:30
At what level is the Serial input of the PIC when you disconnect the GPS module? I guess the timeout is blocked by the incorrect level.

You should have a pull up resistor there.

Ioannis

flotulopex
- 22nd April 2010, 18:03
I have tried both a 10k pull-down and pull-up resistor.

I was thinking a pull-down would be correct since the PIC gets a "true" signal, but as it didn't work, I tried the pull-up way; no success :(

Meanwhile, I have seen that the GPS module will always send the string my SERIN2 command is waiting for ("$GPVTG").

If the module has no signal (no satellite coverage), it will still send the NMEA sentence with empty data, just like this "$GPVTG,,T,0,M,,N,,K*xx".

So, if I disconnect the GPS from the PIC, it works but... it is not the way I would like to have it working.

flotulopex
- 28th April 2010, 08:18
Just for the record, I found the supplier's website for the GPS module I use; it is http://www.globalsat.com.tw/ and the specific module is here: http://www.globalsat.com.tw/products-page.php?menu=2&gs_en_product_id=6&gs_en_product_cnt_id=50&img_id=237&product_cnt_folder=2.