Shop OBEX P1 Docs P2 Docs Learn Events
SD Card problem — Parallax Forums

SD Card problem

PhilldapillPhilldapill Posts: 1,283
edited 2008-06-23 03:08 in Propeller 1
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

Comments

  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-23 03:02
    I get the "WARNING! openFile Failed!" message. BTW, this is ripped from the BB_* files.

    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.
  • PhilldapillPhilldapill Posts: 1,283
    edited 2008-06-23 03:08
    Arg, scratch all that... I found the problem in the other BB files... I was trying to use the pin numbers(DO,DI,Clk,CS) as variables in my function, and pass them mountSDVol... They pass to it, but inside the BB file, the functions revert back to their constant definitions... This will need some recoding as well [noparse]:([/noparse]
Sign In or Register to comment.