micromuc
02-27-2005, 09:17 AM
Thanks Jim,
Jim or anyone tha can help, errors are still getting through. I have posted the program info for the TX and RX side of this project. The problem I am having is calculating a checksum that works. Please read through and you will see my problem. I am new to programming so I may be doing something stupid. Please let me know how to correctly calculate a checksum for my application.
Here is the transmit side information. I acquire data from the GPS at 4800bps then sending it out at 1200bps. I have no problems with this working. I acquire the data and save it as string. I also calculate a checksum by just adding the strings together and with three numbers I made up. I send out the “$A,” in front of the data because I am using the WAIT (“$A,”) on the receive side as a marker to start saving data. I also am sending the 13,10 to make reading the info on HyperTerminal easier at the RX side. They will be dropped once I get things working. Because there is a 2 second period between GPS updates I am sending the data three times before waiting to acquire GPS data again.
TX CODE ----------------------------------------------------------------
vld var byte
spd var byte[8]
deg var byte[8]
alt var byte[8]
cs var byte
loop var byte
start:
SerIn GPSin,baudIN,3000,start,[WAIT("$GPRMC,"),WAIT(","),str vld\2\",",WAIT(","),WAIT(","),WAIT(","),WAIT(","),str spd\8\".",WAIT(","),str deg\8\"."]
SerIn GPSin,baudIN,3000,start,[WAIT("$GPGGA,"),WAIT(","),WAIT(","),WAIT(","),WAIT(","),WAIT(","),WAIT(","),WAIT(","),WAIT(","),str alt\8\"."]
if vld = 86 then start 'if gps signal not valid then wait for valid signal before sending data
cs = (spd + 15) + (deg + 17) + (alt + 19) ‘numbers 15,17,19 are made up by me
for loop = 1 to 3
serout GPSout,baudOUT,["$A,",str spd,",",str deg,",",str alt,"*",cs,"#",13,10]
pause 50
next loop
goto start
END
-------------------------------------------------------------
Now on the RX side I serial in the data that was sent out above. I WAIT for the “$A,” then save the spd, deg and alt as strings. Next I run the same checksum calculation on the strings and save the result. Then I compare the checksum (cs) that was calculated and sent from the TX to the checksum (csRX) calculated at the RX. For now I am just outputting the data out to HyperTerminal. The problem is that the checksum calculated at the TX and RX will match sometimes but the data has errors. I have posted an example of this under the RX code.
RX CODE -------------------------------------------------------------
spd var byte[8]
deg var byte[8]
alt var byte[8]
cs var byte[16]
csRX var byte
start:
SerIn GPSin,baudIN,2500,start,[WAIT("$A,"),str spd\8\",",str deg\8\",",str alt\8\"*",str cs\16\"#"]
csRX = (spd + 15) + (deg + 17) + (alt + 19)
serout GPSout,baudOUT,[str spd,",", str deg,",",str alt,"*",#cs,",",#csRX,13,10]
goto start
END
-------------------------------------------------------------
Here is a copy of what I captured in HyperTerminal. I have BOLD faced the lines that data was bad but the checksums are equal. Any help is greatly appreciated.
Here is the format it should be in;
Spd,Deg,Alt*cs,csRX
0,147,#51*135,183
0,147,351*199,199
0,147,351*199,199
0,147,351*199,199
0,147,351*135,199
0,147,351*135,199
0,147,351*199,199
0,147,35!*199,199·
0,147,351*199,199
0,147,#51*135,183
0,147,351*135,199
0,147,35!*199,199
0,147,351*199,199
0,147,35!*199,199
0,147,351*199,199
0,147,351*199,199
0,147,351*135,199
0,147,35!*199,199
0,147,351*199,199
0,147,351*199,199
0,147,351*135,199
0,147,351*135,199
0,147,351*135,199
0,147,351*199,199
0,147,351*199,199
0,147,351*199,199
0,147,351*135,199
0,147,35!*199,199
0,147,351*199,199
0,147,#51*199,183
0,147,35!*199,199
0,147,351*135,199
0,147,35!*199,199
0,147,351*199,199
0,147,35!*199,199
0,147,351*199,199
0,!47,351*199,183
0,147,35!*199,199
0,147,351*199,199
0,147,351*135,199
2,303,351*203,203
2,303,351*139,203
2,303,35!*203,203
d±š_šb4ª ,ŠRZ7©Høÿd±š_šb4ª ,ÿÿÿÝÿ$A,ŠRZ7©Høÿd±š_šb4ª *50,32
",303,351*203,187
r,354,351*203,11
2,354Tͪ
R2,Z7©Hø$A,354Tͪ
R2*50,242
2,356,351*203,203
2,35H±šªŠR2,Z7©Hø$Al35H±šªŠR2*2,242
2,355,35!*203,203
2,355,351*203,203
2,355,351*203,203
2,348,351*203,203
2,348,351*139,203
2,348,351*203,203
2,348,351*203,203
2,348,351*203,203
2,349,351*203,203
2,349,#51*139,187
2,349,351*203,203
2,309,ci`©[7©H309*248,251
2,349,351*203,203
2,349,351*203,203
",34=XͪŠR",Z7©@øÿÿÿ34=XͪŠR"*248,226
2,349,351*139,203
2,s49,35!*203,11
2,349,351*203,203
28Í¢ÊBšªì,ŠÒZ7©Høô28Í¢ÊBšªì,ýÿþ$A,2,ŠÒZ7©Høô28Í¢ÊB šªì*51,236
2,349,35!*203,203
2,349,351*203,203
2,349,351*203,203
2,349,351*139,203
",349,351(Ë#
349*36,187
2,349,351*203,203
2,3¤6-351*2,Ë#
$A,23¤6-351*2*12,99
0,3ÇÝb_ªŠR0,Z7©Hø$A,3ÇÝb_ªŠR0*34,240
2,335,351*203,203
",3#5,351*203,187
1,336,351*202,202
1,336,35!*202,202
!,336,351*202,186
2,0,351*200,200
2, ,351*200,184
2,0,351*200,200
",357,351*139,187
2,357,351*203,203
2,357,351*203,203
2ì356,351*‹#
2ì356,$A,2,356351*‹#
2ì356*44,188
2,356,350*139,203
2,3kÙb_U_’2,Z1©Hø$A,3kÙb_U_’2*50,242
2,fÕªb_"úV2,Z7©Hø$A,fÕªb_"úV2*50,37
2,0,348*200,200
1,7,346*206,206
1,7,346*206,206
!,245,345*201,185
1,250,#45*217,185
3,178,344*202,202
3,178,344*202,202
0,74LfÑšRj0,7©Èø$A,074LfÑšRj0*44,209
0,74,343*205,205
0,74,343*205,205
0,74,343*205,205
0,74,343*205,205
0,74,343*205,205
0,74,34#+Í#
74*36,205
0,74,34c*205,205
0,7h±š¢šRj0,7©Hø$A,07h±š¢šRj0*44,209
0,74,343*205,205
0,74,343*205,205
0,74,343*205,205
1,357,343*138,202
1,357,343*202,202
1,357,343*202,202
1,357,343*202,202
1,359,343*202,202
1,359,s4g«R7©H359*248,10
2,!79,342*201,185
2,1?9,342*201,201
2,179,342*201,201
2,171,342*201,201
2,171,;42*201,209
2,17!,34"*201,201
2,165,34-:É#
165*36,201
2,165,341*201,201
2,106,740*201,205
2<q06$34„, J’#
þü2<q06$34„,ÿÿ$A,2,8 J’#
þü2<q06$34„*51,132
2,83,340*208,208
1,72,340*206,206
1,72,340*206,206
1,72,340*206,206
2,179,342*201,201
2,171,342*201,201
2,171,;42*201,209
2,17!,34"*201,201
2,165,34-:É#
165*36,201
2,165,341*201,201
2,106,740*201,205
2<q06$34„, J’#
þü2<q06$34„,ÿÿ$A,2,8 J’#
þü2<q06$34„*51,132
2,83,340*208,208
1,72,340*206,206
1,72,340*206,206
1,72,340*206,206
Post Edited (micromuc) : 2/27/2005 2:23:38 AM GMT