Very insightful, I think the offending piece of code lies in this that I used from OBEX
Code:
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.
Code:
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.
Code:
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.
Bookmarks