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

SD Card Help

John BoardJohn Board Posts: 371
edited 2012-06-12 23:42 in Propeller 1
G'day,

I've been playing around with an SD card recently and I've gotten a bit stuck - Could anyone help me?
COn


  _clkmode = xtal1 + pll8x
  _xinfreq = 10_000_000


OBJ


  sd : "fsrw"
  ser: "FullDuplexSerial"


PUB Main  | mount, r




  Ser.start(31,30,0,9600)
  waitcnt(clkfreq*4+cnt)
  ser.str(string(16, "Mounting...", 13))


  mount := \sd.mount_explicit(0, 1, 2, 3)
  if mount < 0
    ser.str(String("Mounting failed."))
    abort


  ser.str(String("SD was found and mounted.", 13))


  sd.popen(string("test.txt"), "w")
  sd.pputs(string("Testing..."))


  sd.pclose
  sd.unmount


  ser.str(String("Wrote 'Testing...' to test.txt", 13))




  mount := \sd.mount_explicit(0, 1, 2, 3)
  if mount < 0
    ser.str(String("Mounting failed."))
    abort


  ser.str(String("SD was found and mounted.", 13))


  sd.popen(string("test.txt"), "r")


  repeat
    r := sd.pgetc
    if r < 0
      ser.str(string("EOF", 13))
      reboot
     if r > 10
      ser.tx(r)
      ser.tx(13)


  ser.str(string("Closing file and unmounting sd card.", 13))


  sd.pclose


  sd.unmount

And the output is:

[code]
Mounting...
SD was found and mounted.
Wrote 'Testing...' to test.txt
SD was found an

Comments

  • John BoardJohn Board Posts: 371
    edited 2012-06-12 23:08
    Hold this thought - But don't reply yet! (except about the "\" thing) - I think I've found the problem (101 typos namely).

    -John
  • John BoardJohn Board Posts: 371
    edited 2012-06-12 23:22
    Found the answer!
    COn
    
      _clkmode = xtal1 + pll8x
      _xinfreq = 10_000_000
    
    
    OBJ
    
    
      sd : "fsrw"
      pst: "Parallax Serial Terminal"
      num : "Simple_numbers"
    
    
    PUB Main  | mount, r
    
    
      pst.start(115_200)
      pst.str(string(16, "Mounting...", 13))
      mount := \sd.mount_explicit(0, 1, 2, 3)
      if mount < 0
        pst.str(String("Mounting failed."))
      pst.str(String("SD was found and mounted.", 13))
      sd.popen(string("test.txt"), "w")
      sd.pputs(1024)
      sd.pclose
      pst.str(String("Wrote 'Testing...' to test.txt", 13))
      waitcnt(clkfreq/5+cnt)
      pst.str(String("Opening test.txt", 13))
      sd.popen(string("test.txt"), "r")
      pst.str(String("File Opened", 13))
      pst.str(String("Reading...", 13)) 
      repeat
        r := sd.pgetc
        if r < 0             
          reboot
        if r > 10
          pst.char(num.dec(r)) 
      pst.str(string("Closing file and unmounting sd card.", 13))
      sd.pclose
      sd.unmount
    

    Although I'm still puzzled with the "\" problem

    -John
  • msrobotsmsrobots Posts: 3,709
    edited 2012-06-12 23:29
    that '\' thing catches aborts.

    like

    try

    catch

    any abort will jump up the stack-chain until it hits a '\'. there you need to handle the error

    Enjoy!

    Mike
  • JLockeJLocke Posts: 354
    edited 2012-06-12 23:31
    I can tell you how the "\" is defined, but I haven't used it in coding myself. From the Propeller Manual (v1.2), page 208:
    \ Abort trap: appears immediately before a method call that could potentially abort. See ABORT on page 47.

    Probably it would be best to refer you to page 47 of the Propeller Manual (v1.2). There is some nice example code on pages 49-50 demonstrating use of the "\".
  • Tracy AllenTracy Allen Posts: 6,664
    edited 2012-06-12 23:32
    Look up "abort" in the manual for info about the "\" prefix. Deep in fsrw are rare conditions that generate an abort. If you open the fsrw object and look at the mount method, you will see several conditions that can occur and an error number that they return. By including the "\" prefix you are telling the program execution to back all the way out to this top level if the error should happen to occur, even if the call to fsrw had been routed via nested methods that are there to handle normal operation.

    I see you have an abort in the program listing you posted. I'm not quite sure what that will do, because at this level there is nowhere to abort to, already the top. You could just as well use a REPEAT there to hold the program.
  • John BoardJohn Board Posts: 371
    edited 2012-06-12 23:42
    Wow - Thanks for all these replies! It all makes sense now,

    Comming from a computer coding background (Java, Python, etc) the "Try, Catch" analogy was something I could relate to quite easily!

    -John
Sign In or Register to comment.