Shop OBEX P1 Docs P2 Docs Learn Events
SD Max Card - examples wanted to show how the code is actually used — Parallax Forums

SD Max Card - examples wanted to show how the code is actually used

ElectricAyeElectricAye Posts: 4,561
edited 2008-09-04 01:58 in Propeller 1
Hi all,
I'm struggling with how to use SD cards and I've looked through the documentation that came with the Hydra SD Max and could not find the kind of code examples that cause me to have a much-needed ah-ha! experience. What I think I need to get that ah-ha experience is a few real world examples that are not too complicated but are also not so simple as to be entirely trivial. What would be even more enlightening is to have code examples that happen to include human language explanations of what the various lines of code are doing. I know it's asking a lot, especially the part about having comments with the code, but I thought I'd toss this request out here into the forum and see if anyone has something like this they wouldn't mind sharing with all of us SD card newbies.

My own application requires me to write about 20 values about every 5 seconds for several weeks. Those 20 values have to be written to the SD card using comma separated values (CSV). I suppose I would like to close up a file every day or so in order to protect it in case of a power failure, etc. and then open up a new file and immediately start recording data on the same card. Also what would be ideal is to have the SD card set up so I can pull it out and stick in a new one every so often, though I'm not sure that's possible.

But, in general I just need to learn how to work with SD cards, so anything you would like to share would be cool to see and a big help.

many thanks,
Mark

Comments

  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-09-01 21:37
    @Mark,

    I'm working on a tutorial specifically for learning how to work
    with the SD card. See if this attached .spin helps you understand it.

    You'll need to grab a copy of PST (Parallax Serial Terminal) as it
    sends all it's results back to your computer.

    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-02 02:11
    Hey, thanks OBC! I'll download this tonight and give it a shot tomorrow. If you're trying to make your training code suitable for dummies, I'm your test case!

    wish me luck!
    Mark

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    It might be the Information Age but the Eon of Ignorance has yet to end.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-02 05:43
    Hi OBC,
    just a quick question about your SD card section on your Propeller Cookbook. I noticed you have an illustration that says "Do not pins 8 or 9 in SPI mode". Did you mean to say "Do not connect" or "Do not forget to pull up" or... ?

    I noticed that the sdspi object from the Obex has pin 9 (I presume of the SD card) hooked up to 3.3volts through a 20k resistor. And it looks like he has pin 8 hooked up the same way. The other propeller pins, pins 0 through 3, appear to be hooked up identically to yours.

    So what do you suggest to do with pins 8 and 9?

    many thanks for your help,

    Mark



    smile.gif
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-02 05:53
    Hi OBC,
    a question about the pins you are using for your SD Interface Trainer:
    in your trainer program, you have your SD configuration listed as spiDO = 16, spiClk = 17, etc. But at the very top of the program, you make the comment that this module is intended for use with the SD cookbook entry. From what I found on your website, the SD cookbook entry seems to suggest using pins P0 through P3 as a kind of standard. So am I misunderstanding something, or are you using a different set of pins in the trainer program vs. your Cookbook entry?

    thanks,
    Mark
  • Oldbitcollector (Jeff)Oldbitcollector (Jeff) Posts: 8,091
    edited 2008-09-02 14:31
    I saw that error in the publication. I'll fix that.
    Should read "Do not connect pins 8 or 9".

    You have a sharp eye in regard to the pin assignments!
    My original documentation used p0-P3 to connect the SD,
    however with so many of us using composite TV connections,
    (and the release of the Hydra SD Card) I've adjusted this
    recommendation to pins P16-P19.

    There is an update to the Cookbook in the works, which
    will be released in a printed version. It will include
    documented spin code for each item. (much like the copy I posted)


    Let's move the rest of this conversation to your SD thread under "Propeller"
    It will help me stay focused.. [noparse]:)[/noparse]


    OBC

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    New to the Propeller?

    Getting started with a Propeller Protoboard?
    Check out: Introduction to the Proboard & Propeller Cookbook 1.4
    Updates to the Cookbook are now posted to: Propeller.warrantyvoid.us
    Got an SD card connected? - PropDOS

    Post Edited (Oldbitcollector) : 9/2/2008 2:56:31 PM GMT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-02 15:01
    Hi OBC,
    thanks for taking a look at this. I saw your answers in the Prop forum, too. The feeling I get from the comments I've heard is that it's optional to hook pins 8 and 9 of the SD card to 3.3 volts via a 10K or 20K resistor. I guess since I don't understand why some people prefer one configuration over another, I'd like to take the safest route which, I'm just guessing, would be to tie pins 8 and 9 to the 3.3 volts. Upon hearing that on the Sparkfun board, the WP stands for "write protect" and the CD stands for "card detect" might be useful for indicator LEDs - it's always nice to know that the card is actually making contact and that it's not in write protection mode, considering how little things like "bad insertions" can drive one crazy when trying to debug a problem. I haven't seen any examples of using WP or CD. I don't even know if it requires software to light up LED indicator circuits or if this would be a purely hardware thing. For me, anytime I'm trying to hook up two things, it always give me a warm fuzzy to see something light up - unless, of course, that source of light happens to be flames shooting out of the connector plug.

    thanks for sharing,
    Mark
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-02 15:27
    CD and WP are just switch closures. You can wire them to Propeller I/O pins, but the I/O drivers have no provisions for them. You could add provisions in your own programs and check for WP before you call any of the write routines or check for CD before you call any SD card routines.

    The issue of pullups or no pullups has to do with noise and power consumption. Any CMOS logic input will "float" if it's not connected to anything or connected to another high impedance input. A floating input is very susceptable to static, to capacitive effects, etc. Wave your hand nearby and the logic state seen by the input may change. Floating inputs tend to hover near the "linear mode" portion of the switching curve of the input gate and the power consumption of the input gate is much higher than if it were held to normal logic levels (Vss or Vdd). A pullup (or pulldown) resistor will fix these problems.

    Post Edited (Mike Green) : 9/2/2008 3:35:07 PM GMT
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-02 16:38
    Thanks, Mike. It sounds like if I'm using batteries, then I want to make sure I do NOT float those pins. That's good to know!

    cheers,
    Mark
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-04 01:14
    Nope, CD and WP are outputs (switch closures), not inputs.
    If you don't use them, they don't need any pullup or pulldown.
    If you do use a pullup, it won't draw any current unless an SD
    card is installed. WP, if it has a pullup, won't draw any current
    unless WP is enabled.
  • ElectricAyeElectricAye Posts: 4,561
    edited 2008-09-04 01:58
    Okay, Mike, now I understand.· Luckily the support staff that sold me the Hydra SD Max card provided me with wiring diagrams that show how to wire up the WP and CDs so I can actually use them for lighting up LEDs.· Isn't that sweet of them?

    thanks for your patience,
    Mark
Sign In or Register to comment.