R Pankau
03-23-2012, 01:52 PM
Very insightful, I think the offending piece of code lies in this that I used from OBEX
PUB readNEMA
Null[0] := 0
repeat
longfill(gps_buff,20,0)
repeat while Rx <>= "$" ' wait for the $ to insure we are starting with
Rx := uart.rx ' a complete NMEA sentence
cptr := 0
repeat while Rx <>= CR ' continue to collect data until the end of the NMEA sentence
Rx := uart.rx ' get character from Rx Buffer
if Rx == ","
gps_buff[cptr++] := 0 ' If "," replace the character with 0
else
gps_buff[cptr++] := Rx ' else save the character
if gps_buff[2] == "G"
if gps_buff[3] == "G"
if gps_buff[4] == "A"
copy_buffer(@GPGGAb, @GPGGAa)
if gps_buff[2] == "R"
if gps_buff[3] == "M"
if gps_buff[4] == "C"
copy_buffer(@GPRMCb, @GPRMCa)
if gps_buff[0] == "P"
if gps_buff[1] == "G"
if gps_buff[2] == "R"
if gps_buff[3] == "M"
if gps_buff[4] == "Z"
copy_buffer(@PGRMZb, @PGRMZa)
if gps_buff[0] == "G"
if gps_buff[1] == "P"
if gps_buff[2] == "G"
if gps_buff[3] == "S"
if gps_buff[4] == "A"
copy_buffer(@GPGSAb, @GPGSAa)
The ascii 88 1 is the first four chars of Longitude.
the "Null[0] right off the bat has me thinking that it's writing to location zero.
the "interrupt" I refer to is just this, running it a separate cog.
PUB interrupt
repeat
waitcnt(80_000_000 + cnt)
cntr++
and I use cntr a global var to trigger subs then clear cntr,then wait again. I had CLKFREQ in the waitcnt instruction at first then switched it to 80Mhz and noticed that things began working better.
I also use byte addressing in this, which is where all the writing to the sd card happens. but I believe it should never affect location zero....requires a closer look though.
pub write_sd(landmark) |address, i
ret_val := \sd.popen(string("Log01.txt"),"a")
if landmark == 2
\sd.SDstr(gps.GPSaltitude)
\sd.SDstr(string(", "))
'bytefill(@lat_and_long,0,15) 'Clear Buffer
address := gps.latitude 'Get address of latitude
byte[lat_and_long][0] := byte[address][0]
byte[lat_and_long][1] := byte[address][1]
byte[lat_and_long][2] := " "
i := 3
repeat 7
byte[lat_and_long][i] := byte[address][i-1]
i++
byte[lat_and_long][i] := 0
\sd.SDstr(lat_and_long)
\sd.SDstr(string("N, "))
'bytefill(@lat_and_long,0,15) 'Clear Buffer
address := gps.longitude 'Get address of longitude
byte[lat_and_long][0] := byte[address][1]
byte[lat_and_long][1] := byte[address][2]
byte[lat_and_long][2] := " "
i := 3
repeat 7
byte[lat_and_long][i] := byte[address][i]
i++
byte[lat_and_long][i] := 0
\sd.SDstr(lat_and_long)
\sd.SDstr(string("W, "))
\sd.SDstr(gps.satellites)
\sd.SDstr(string(", "))
\sd.SDstr(gps.valid)
\sd.SDstr(string(", "))
\sd.SDstr(gps.time)
\sd.SDstr(string(", "))
\sd.SDstr(gps.heading)
\sd.SDstr(string(", "))
\sd.SDstr(gps.speed)
\sd.SDstr(string(", "))
\sd.SDstr(gps.date)
\sd.SDstr(string(" ",13,10))
'debug.str(string("test"))
'debug.dec(ret_val)
'debug.tx(13)
\sd.pflush
\sd.pclose
'debug.str(string("after file close",13,10))
if landmark == 1
\sd.SDstr(gps.GPSaltitude)
\sd.SDstr(string(", "))
\sd.SDstr(gps.latitude)
\sd.SDstr(string(", -"))
\sd.SDstr(gps.longitude)
\sd.SDstr(string(", "))
\sd.SDstr(gps.satellites)
\sd.SDstr(string(", "))
\sd.SDstr(gps.valid)
\sd.SDstr(string(", "))
\sd.SDstr(gps.time)
\sd.SDstr(string(", "))
\sd.SDstr(gps.heading)
\sd.SDstr(string(", "))
\sd.SDstr(gps.speed)
\sd.SDstr(string(", "))
\sd.SDstr(gps.date)
\sd.SDstr(string(", Landmark"))
\sd.SDstr(string(" ",13,10))
'debug.str(string("test"))
'debug.dec(ret_val)
'debug.tx(13)
\sd.pflush
\sd.pclose
if ret_val == 0
outa[Green_LED] := 1 'Blink LED for success.
waitcnt(clkfreq/100 + cnt)
outa[Green_LED] := 0
if ret_val <> 0
outa[Blue_LED] := 1 'Blink LED for NOT success.
waitcnt(clkfreq/2 + cnt)
outa[Blue_LED] := 0
maybe I should have used byte[@lat_and_long][0], I assumed that referencing a var array would return the address of the first byte, but.... now I see that by clearing the array to zero, or if it starts out that way, the byte[effectively zero][0] then writes to location zero.
R Pankau
03-23-2012, 02:04 PM
This should work a little better
Now if I could find the switch to turn off "unsolved" on the forum heading.
pub write_sd(landmark) |address, i
ret_val := \sd.popen(string("Log01.txt"),"a")
if landmark == 2
\sd.SDstr(gps.GPSaltitude)
\sd.SDstr(string(", "))
'bytefill(@lat_and_long,0,15) 'Clear Buffer
address := gps.latitude 'Get address of latitude
byte[@lat_and_long][0] := byte[address][0]
byte[@lat_and_long][1] := byte[address][1]
byte[@lat_and_long][2] := " "
i := 3
repeat 7
byte[@lat_and_long][i] := byte[address][i-1]
i++
byte[@lat_and_long][i] := 0
\sd.SDstr(lat_and_long)
\sd.SDstr(string("N, "))
'bytefill(@lat_and_long,0,15) 'Clear Buffer
address := gps.longitude 'Get address of longitude
byte[@lat_and_long][0] := byte[address][1]
byte[@lat_and_long][1] := byte[address][2]
byte[@lat_and_long][2] := " "
i := 3
repeat 7
byte[@lat_and_long][i] := byte[address][i]
i++
byte[@lat_and_long][i] := 0
\sd.SDstr(lat_and_long)
\sd.SDstr(string("W, "))
\sd.SDstr(gps.satellites)
\sd.SDstr(string(", "))
\sd.SDstr(gps.valid)
\sd.SDstr(string(", "))
\sd.SDstr(gps.time)
\sd.SDstr(string(", "))
\sd.SDstr(gps.heading)
\sd.SDstr(string(", "))
\sd.SDstr(gps.speed)
\sd.SDstr(string(", "))
\sd.SDstr(gps.date)
\sd.SDstr(string(" ",13,10))
'debug.str(string("test"))
'debug.dec(ret_val)
'debug.tx(13)
\sd.pflush
\sd.pclose
'debug.str(string("after file close",13,10))
if landmark == 1
\sd.SDstr(gps.GPSaltitude)
\sd.SDstr(string(", "))
\sd.SDstr(gps.latitude)
\sd.SDstr(string(", -"))
\sd.SDstr(gps.longitude)
\sd.SDstr(string(", "))
\sd.SDstr(gps.satellites)
\sd.SDstr(string(", "))
\sd.SDstr(gps.valid)
\sd.SDstr(string(", "))
\sd.SDstr(gps.time)
\sd.SDstr(string(", "))
\sd.SDstr(gps.heading)
\sd.SDstr(string(", "))
\sd.SDstr(gps.speed)
\sd.SDstr(string(", "))
\sd.SDstr(gps.date)
\sd.SDstr(string(", Landmark"))
\sd.SDstr(string(" ",13,10))
'debug.str(string("test"))
'debug.dec(ret_val)
'debug.tx(13)
\sd.pflush
\sd.pclose
if ret_val == 0
outa[Green_LED] := 1 'Blink LED for success.
waitcnt(clkfreq/100 + cnt)
outa[Green_LED] := 0
if ret_val <> 0
outa[Blue_LED] := 1 'Blink LED for NOT success.
waitcnt(clkfreq/2 + cnt)
outa[Blue_LED] := 0
Sapieha
03-23-2012, 02:14 PM
To that You need reedit first post of thread in advanced mode
This should work a little better
Now if I could find the switch to turn off "unsolved" on the forum heading.
pub write_sd(landmark) |address, i
ret_val := \sd.popen(string("Log01.txt"),"a")
if landmark == 2
\sd.SDstr(gps.GPSaltitude)
\sd.SDstr(string(", "))
'bytefill(@lat_and_long,0,15) 'Clear Buffer
address := gps.latitude 'Get address of latitude
byte[@lat_and_long][0] := byte[address][0]
byte[@lat_and_long][1] := byte[address][1]
byte[@lat_and_long][2] := " "
i := 3
repeat 7
byte[@lat_and_long][i] := byte[address][i-1]
i++
byte[@lat_and_long][i] := 0
\sd.SDstr(lat_and_long)
\sd.SDstr(string("N, "))
'bytefill(@lat_and_long,0,15) 'Clear Buffer
address := gps.longitude 'Get address of longitude
byte[@lat_and_long][0] := byte[address][1]
byte[@lat_and_long][1] := byte[address][2]
byte[@lat_and_long][2] := " "
i := 3
repeat 7
byte[@lat_and_long][i] := byte[address][i]
i++
byte[@lat_and_long][i] := 0
\sd.SDstr(lat_and_long)
\sd.SDstr(string("W, "))
\sd.SDstr(gps.satellites)
\sd.SDstr(string(", "))
\sd.SDstr(gps.valid)
\sd.SDstr(string(", "))
\sd.SDstr(gps.time)
\sd.SDstr(string(", "))
\sd.SDstr(gps.heading)
\sd.SDstr(string(", "))
\sd.SDstr(gps.speed)
\sd.SDstr(string(", "))
\sd.SDstr(gps.date)
\sd.SDstr(string(" ",13,10))
'debug.str(string("test"))
'debug.dec(ret_val)
'debug.tx(13)
\sd.pflush
\sd.pclose
'debug.str(string("after file close",13,10))
if landmark == 1
\sd.SDstr(gps.GPSaltitude)
\sd.SDstr(string(", "))
\sd.SDstr(gps.latitude)
\sd.SDstr(string(", -"))
\sd.SDstr(gps.longitude)
\sd.SDstr(string(", "))
\sd.SDstr(gps.satellites)
\sd.SDstr(string(", "))
\sd.SDstr(gps.valid)
\sd.SDstr(string(", "))
\sd.SDstr(gps.time)
\sd.SDstr(string(", "))
\sd.SDstr(gps.heading)
\sd.SDstr(string(", "))
\sd.SDstr(gps.speed)
\sd.SDstr(string(", "))
\sd.SDstr(gps.date)
\sd.SDstr(string(", Landmark"))
\sd.SDstr(string(" ",13,10))
'debug.str(string("test"))
'debug.dec(ret_val)
'debug.tx(13)
\sd.pflush
\sd.pclose
if ret_val == 0
outa[Green_LED] := 1 'Blink LED for success.
waitcnt(clkfreq/100 + cnt)
outa[Green_LED] := 0
if ret_val <> 0
outa[Blue_LED] := 1 'Blink LED for NOT success.
waitcnt(clkfreq/2 + cnt)
outa[Blue_LED] := 0
R Pankau
03-25-2012, 03:26 AM
just grabbed this...now you know the location of my living room.
$GPRMC,032531,A,3016.3376,N,08811.8669,W,000.0,000 .0,250312,,,A*61
$GPGGA,032532,3016.3377,N,08811.8667,W,1,03,02.4,0 0237.5,M,-033.9,M,,*7A
$GPGSA,A,2,08,11,19,,,,,,,,,,02.6,02.4,01.0*00
$GPGSV,3,1,11,01,28,140,26,03,13,050,00,06,02,047, 00,07,76,142,33*73
$GPGSV,3,2,11,08,62,317,34,11,46,124,41,13,18,192, 26,17,13,220,00*77
$GPGSV,3,3,11,19,48,051,41,26,19,315,30,28,34,283, 00,,,,*40
$GPRMC,032532,A,3016.3377,N,08811.8667,W,000.0,000 .0,250312,,,A*6D
$GPGGA,032533,3016.3376,N,08811.8669,W,1,03,02.4,0 0237.5,M,-033.9,M,,*74
$GPGSA,A,2,08,11,19,,,,,,,,,,02.6,02.4,00.9*08
$GPGSV,3,1,11,01,28,140,00,03,13,050,27,06,02,047, 00,07,76,142,33*72
$GPGSV,3,2,11,08,62,317,34,11,46,124,41,13,18,192, 00,17,13,220,26*77
$GPGSV,3,3,11,19,48,051,41,26,19,315,29,28,34,283, 00,,,,*48
$GPRMC,032533,A,3016.3376,N,08811.8669,W,000.0,000 .0,250312,,,A*63
$GPGGA,032534,3016.3375,N,08811.8671,W,1,03,02.4,0 0237.5,M,-033.9,M,,*79
$GPGSA,A,2,08,11,19,,,,,,,,,,02.6,02.4,00.9*08
$GPGSV,3,1,11,01,28,140,00,03,13,050,00,06,02,047, 00,07,76,142,34*70
$GPGSV,3,2,11,08,62,317,33,11,46,124,41,13,18,192, 00,17,13,2