Shop OBEX P1 Docs P2 Docs Learn Events
FSRW fast start for dummies (like me) — Parallax Forums

FSRW fast start for dummies (like me)

StevenRStevenR Posts: 13
edited 2010-01-10 18:06 in Propeller 1
I'll be wiring up my uSD board next week and have read the readme's but would like a jump start into reading and writing to an SD card.

Would someone post some code that shows basic functions like how to initialize FSRW, mount the card, read/writes to the card, file naming, file retrieving, etc.

Tnx.

Comments

  • SamMishalSamMishal Posts: 468
    edited 2009-12-31 07:34
    Steven,

    From another dummy (me) here is some code I wrote to test my uSD unit too.

    It creates a file and writes some·numbers (longs, bytes and words)·to it in Binary
    and in Text format and writes some text strings too.

    Then it also reads the file back and prints the read stuff to the PST.
    All the time it is also reporting to the PST what it is doing.

    The code is largely self commenting and should be easy to understand.
    I am using the FSRW_23 object....there is now a 26 version but it should
    not be any different.

    I hope this helps.

    Read the code before you run it.... when you run it you need to press Enter on the PST to start the action.
    This is made clear when you study the code.


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.RobotBASIC.com
  • StevenRStevenR Posts: 13
    edited 2010-01-02 04:35
    Samuel,

    Thank you very much for posting your code. I went through it along with the FSRW object and it is making sense to me.

    I've begun to write my code in anticipation of getting the uSD board next week.

    I do have one question, what is the difference between "mount_explicit" and "mount"?

    My board already uses P0 so I will be using P1 as the first pin for the SD board. I think that I read somewhere in the forum that if I deviate from using P0 as the first pin then I have to do something different with the mount command.

    Steven.
  • SamMishalSamMishal Posts: 468
    edited 2010-01-02 06:16
    Steven,

    I am glad you found my code useful. If you change the BASE pin to P1 or whatever then just
    change the Orange line in the code below to say so.

    Remember this is the BASE pin and so you will then need to connect D0 to that base pin and
    SCLK to BasePin+1, DI to BasePin+2, CS to BasePin+3

    The code I wrote does not make use of the Card_Detect pin (CD) this you can connect to any
    pin you like it does not have to be sequential. But the FSWR object does not make use of it, nor
    does my code.

    It provides·a·means for detecting if there is a card inserted in the holder or not. This can be useful
    to avoid doing the mounting which will fail if there is no card.

    CON
      _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000
      [color=orange][b]sd_FirstPin = 0  'use pins P0 to P3[/b][/color]
    
    


    As far as Mount_Explicit() and Mount() have a look at the descriptions in the code below

      Pub mount_explicit(DO, CLK, DI, CS)                                           
         Mount a volume.  The address passed in is passed along to the block        
         layer; see the currently used block layer for documentation.  If the       
         volume mounts, a 0 is returned, else abort is called.                      
      
    Pub mount(basepin)                                                            
         For compatibility, a single pin.                                           
    
    


    With Mount_Explicit() you specify what pin number you want for each of the D0,SCLK,DI and CS
    so they do not have to be CONSECUTIVE....they can be ANY pins.

    With Mount() you specify the BASE PIN ie the D0 pin but then it is assumed that the SCLK, DI and CS are
    then the CONSECUTIVE pins as described above.

    So it is up to you which you want to use but in fact Mount() calls Mount_Explicit() any way notice
    how it does it below. You can change my code to use the Mount_Explicit() instead of Mount() and then
    pass it the appropriate pin numbers, but the rest of the code would be no different.


    Pub mount(basepin) : r | start, sectorspercluster, reserved, rootentries, sectors
    {{
       For compatibility, a single pin.
    }}
       return [b][color=blue]mount_explicit(basepin, basepin+1, basepin+2, basepin+3)
    [/color][/b]   'This may do more complicated stuff later.
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.RobotBASIC.com


    Post Edited (SamMishal) : 1/2/2010 6:21:51 AM GMT
  • StevenRStevenR Posts: 13
    edited 2010-01-09 22:27
    Sam,

    Got the board wired this morning (Sat).

    Your code works great and am implementing parts of it in my application.

    Thanks again.

    Steven.
  • SamMishalSamMishal Posts: 468
    edited 2010-01-10 18:06
    StevenR said...
    Got the board wired this morning (Sat).
    Your code works great and am implementing parts of it in my application.
    Thanks again.
    I am glad..... You are very welcome.....

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Samuel

    www.RobotBASIC.com
    ·
Sign In or Register to comment.