SD Card problem
I'm making a battery logger, and need to log the voltage to an SD Card. I've gotten the same adapter/sd card combo to work before, but I'm writing up an entirely new function for it. All I need to do for now, is to open the file on the card. The card volume mounts successfully, but won't open any files. Here's my code.
PUB SDCard_Start(DO,Clk,DI,CS) | err, val, progsize
'' Initialize the I/O routines including console I/O, I2C/SPI
'' Clear the program space and variables, then read a line and interpret it.
·· long[noparse][[/noparse]def#memPtr] := def#endFree······················· ' Start at end of HUB memory
·· long[noparse][[/noparse]def#randomSeed] := def#initMarker················ ' Initialize random seed
·· long[noparse][[/noparse]def#userPtr] := def#noSuchAddr······················
·· if not ldrInit.start·································· ' Now start up the I2C driver
···· abort false
·· long[noparse][[/noparse]def#initMarker] := def#uniqueMark················ ' Basic initialization complete
·· progsize := long[noparse][[/noparse]def#memPtr] - @err - (512 << 2) ' Allocate memory
·· if progsize < 512
····· TV.str(string("Available memory < 512 bytes",def#Cr,def#Lf))
····· abort
·· def.allocate(progsize)
·· TV.dec(progsize)
·· TV.str(string(" bytes available",def#Cr))
·· TV.str(string("Opening...."))
·· TV.out(13)
·· val := \SD.mountSDVol(DO,Clk,DI,CS)··
·· ifnot val < 0
···· ifnot \SD.closeFile < 0
······ ifnot val := \SD.openFile(string("TestFile.txt"),"w")
········ TV.str(string("File Opened Successfully..."))
········ waitcnt(cnt+clkfreq)··
········ return true
······ else
········ TV.str(string("WARNING! openFile Failed!"))···········
·· else
····· TV.str(string("WARNING! MountSDVol Failed!"))
·· waitcnt(cnt+clkfreq)····················
·· return 0
PUB SDCard_Start(DO,Clk,DI,CS) | err, val, progsize
'' Initialize the I/O routines including console I/O, I2C/SPI
'' Clear the program space and variables, then read a line and interpret it.
·· long[noparse][[/noparse]def#memPtr] := def#endFree······················· ' Start at end of HUB memory
·· long[noparse][[/noparse]def#randomSeed] := def#initMarker················ ' Initialize random seed
·· long[noparse][[/noparse]def#userPtr] := def#noSuchAddr······················
·· if not ldrInit.start·································· ' Now start up the I2C driver
···· abort false
·· long[noparse][[/noparse]def#initMarker] := def#uniqueMark················ ' Basic initialization complete
·· progsize := long[noparse][[/noparse]def#memPtr] - @err - (512 << 2) ' Allocate memory
·· if progsize < 512
····· TV.str(string("Available memory < 512 bytes",def#Cr,def#Lf))
····· abort
·· def.allocate(progsize)
·· TV.dec(progsize)
·· TV.str(string(" bytes available",def#Cr))
·· TV.str(string("Opening...."))
·· TV.out(13)
·· val := \SD.mountSDVol(DO,Clk,DI,CS)··
·· ifnot val < 0
···· ifnot \SD.closeFile < 0
······ ifnot val := \SD.openFile(string("TestFile.txt"),"w")
········ TV.str(string("File Opened Successfully..."))
········ waitcnt(cnt+clkfreq)··
········ return true
······ else
········ TV.str(string("WARNING! openFile Failed!"))···········
·· else
····· TV.str(string("WARNING! MountSDVol Failed!"))
·· waitcnt(cnt+clkfreq)····················
·· return 0
Comments
I have all the pins hooked up right, I assume, as the volume mounts when the SD is in, and doesn't when it is out.