Issue writing buffer to SD Card
I am trying to get some quick and dirty code put together for an event tomorrow. I have another piece of code that pumps the current buffer information out over serial with no issue. However I am having troubles writing that same data to a SD card. I verified I can write to the card using pputc, and the FSRW speed test works without an issue. I created 'TempBuffer' that was defined with the type of data I was expecting. Filling it with '4300.9421' writes '3D D6 1C 38 34 35 99 81 C1' which does not correlate. I added the relevant code below. Thanks in advance!
VAR
BYTE GPSTime[noparse][[/noparse]10], GPSValidity, GPSLaditude[noparse][[/noparse]9], GPSNorS, GPSLongitude[noparse][[/noparse]10], GPSEorW, GPSSpeed, GPSTrueHeading, GPSDate[noparse][[/noparse]6]
BYTE TempBuffer[noparse][[/noparse]9]
LONG GPSStack[noparse][[/noparse]100] 'Adjust later
PUB Main
dirA[noparse][[/noparse]RELAY0]~~
dirA[noparse][[/noparse]RELAY1]~~
dirA[noparse][[/noparse]RELAY2]~~
TempBuffer[noparse][[/noparse]0] := "4"
TempBuffer := "3"
TempBuffer := "0"
TempBuffer := "0"
TempBuffer := "."
TempBuffer := "9"
TempBuffer[noparse][[/noparse]6] := "2"
TempBuffer[noparse][[/noparse]7] := "4"
TempBuffer[noparse][[/noparse]8] := "1"
'waitcnt(clkfreq + cnt) 'Wait GPS to start up, it will freeze if initialized too early
Serial.Init
Serial.AddPort(MAIN_COM, MAIN_RX, MAIN_TX, -1, -1, 0, 0, MAIN_BAUD)'Set Up Main Communication Port
Serial.AddPort(GPS_COM, GPS_RX, GPS_TX, -1, -1, 0, 0, GPS_BAUD) 'Set Up Port For GPS
Serial.Start
Cognew(GPSDecoder(GPS_COM), @GPSStack)
waitcnt(clkfreq + cnt)
outA[noparse][[/noparse]RELAY0] := 1
SD.mount_explicit(SD_DO, SD_SCK, SD_DI, SD_CS)
SD.opendir
SD.popen(string("log.txt"), "w")
repeat 1
SD.pwrite(TempBuffer, 9)
SD.pclose
SD.unmount
outA[noparse][[/noparse]RELAY0] := 0
PUB GPSDecoder(Port) | a, temp
Serial.rxflush(Port)
repeat
if Serial.rx(Port) == "$"
a := 0
repeat until Serial.rx(Port) == "," 'Wait for GPRMC ID to clear
repeat until (temp := Serial.rx(Port)) == "," 'Collect Time Stamp
GPSTime[noparse][[/noparse]a++] := temp
repeat until (temp := Serial.rx(Port)) == "," 'Collect Track Validity
GPSValidity := temp
a := 0
repeat until (temp := Serial.rx(Port)) == "," 'Collect Laditude
GPSLaditude[noparse][[/noparse]a++] := temp
repeat until (temp := Serial.rx(Port)) == "," 'Collect North Or South
GPSNorS := temp
a := 0
repeat until (temp := Serial.rx(Port)) == "," 'Collect Longitude
GPSLongitude[noparse][[/noparse]a++] := temp
repeat until (temp := Serial.rx(Port)) == "," 'Collect East Or West
GPSEorW := temp
a := 0
repeat until (temp := Serial.rx(Port)) == "," 'Collect Speed In Knots
GPSSpeed[noparse][[/noparse]a++] := temp
a := 0
repeat until (temp := Serial.rx(Port)) == "," 'Collect True Heading
GPSTrueHeading[noparse][[/noparse]a++] := temp
a := 0
repeat until (temp := Serial.rx(Port)) == "," 'Collect Date
GPSDate[noparse][[/noparse]a++] := temp

Comments
General things:
- what version of fsrw are you using?
- I don't understand what the "opendir" call is doing
- you may wish to trap the return values of the calls to see if anything is returned (ret_val := \sdfat.etc)
Jonathan
edited to make the abort trap slash go the correct way (i.e. \ instead of /)
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.
Post Edited (lonesock) : 11/13/2009 7:54:00 PM GMT
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
lonesock
Piranha are people too.