Shop OBEX P1 Docs P2 Docs Learn Events
SD Card Reading/Writing — Parallax Forums

SD Card Reading/Writing

MoZak18MoZak18 Posts: 26
edited 2012-03-03 15:54 in Propeller 1
Hello,

I am a senior in electrical engineering working on my senior design project, and not the most adept coder, especially not in Spin. For the project, we are sending up a weather balloon to gather atmospheric data. The sensors we are using are an altimeter, temperature sensors, compass, and accelerometer. The microcontroller we are using is the Parallax Propeller, and coding is done in Spin. The goal is to gather this data at certain time intervals and save this data to an SD card. The micro-SD card adapter we are using is the Parallax #32312. I am aware of the FAT16 (fsrw.spin) object by Tomas Rokicki and have downloaded it. However, I am unsure as to how to implement it. Attached is a simplified version of the code I have. The main file gathers and prints altitude data to Parallax Serial Terminal every 2 seconds. The two other files are just required objects. I was wondering if someone could show me the basic concept of how to create a file and write this data to the micro-SD card (Parallax #32312) instead of Parallax Serial Terminal using the fsrw object with this simplified example. Any help would be greatly appreciated.

29124_altimeter.spinParallax Serial Terminal.spinsimplified_main.spin

Comments

  • groggorygroggory Posts: 205
    edited 2012-02-23 15:14
    There is an awesome SD object (version 3) I think from a guy named Kye I think here on the forum. Go check that out. Really nice object!

    Good luck!
  • Cluso99Cluso99 Posts: 18,066
    edited 2012-02-23 17:43
    MoZak18: Firstly, welcome to this fabulous forum.

    Take a look at Kyes SD object. There is an App Note by Parallax describing this. There is a demo program using the sd card. Also look at KyeDos by Drac. I think this will get you there quicker.
  • KyeKye Posts: 2,200
    edited 2012-02-23 19:57
    Its the full file system driver object in the object exchange. http://obex.parallax.com/objects/619/
  • Cluso99Cluso99 Posts: 18,066
    edited 2012-02-23 22:55
    BTW you will see version 2 & 3 mentioned. It is confusing but the object in obex is the latest.
  • MoZak18MoZak18 Posts: 26
    edited 2012-02-24 16:28
    Thank you for all the replies, as well as the link, I am taking a look at Kye's object right now. I have found another object however; SD_Card_Micro_01.spin by Greg Denson. It's for beginners and actually utilizes the fsrw object. I played around with it for only a few minutes the other day with no output whatsoever on PST. Any comments on this object relative to Kye's?
  • JonnyMacJonnyMac Posts: 8,912
    edited 2012-02-24 17:17
    I only use FSRW for my projects; it's been heavily vetted and the only SD card driver I trust. That said, it may not have as much hand-holding as you desire. You may need to dig in a little more to use it, but I think you'll be happy you did.

    In the beginning you need to decide how you're going to store information on the SD card. You could store data in a raw format, which is the most compact, but you might consider storing it in text format that can be displayed later; perhaps something that is comma-delimited. Using a comma-delimited file will let you open and view the file in a simple text editor, or open the file in a spreadsheet where you can use the values stored.
  • Cluso99Cluso99 Posts: 18,066
    edited 2012-02-24 18:17
    Almost all of my programs currently use fsrw. Originally I thought that Kye's was slower but I think it is now at least as fast (anyone care to comment?).

    I am switching to Kye's drivers. They are documented nicely and use longer more meaningful names (too long for me as I like typeing short names because I am old school). Catalina uses a derived version of Kye's drivers, and Drac uses them for KyeDos. It also supports FAT32 (dont think fsrw supports FAT32) and also subdirectories. Also it comes with quite a lot of functionality like MKDIR etc.

    Just my 2c
  • MoZak18MoZak18 Posts: 26
    edited 2012-02-28 08:37
    Ok. Well below I have attached the "beginner" object that utilizes the fsrw object. I only got the error message, and could not get the SD card to mount. Could someone else try this and tell me if they have any luck and/or any suggestions? Thanks as always.

    fsrw.spinParallax Serial Terminal.spinsafe_spi.spinSD_Card_Micro_01.spin
  • rokickirokicki Posts: 1,000
    edited 2012-02-28 09:53
    > I am switching to Kye's drivers.

    That's too bad.

    > Originally I thought that Kye's was slower but I think it is now at least as fast

    Kye's drivers aren't even in the same ballpark in speed. But they are fast
    enough for some uses.

    > It also supports FAT32 (dont think fsrw supports FAT32)

    fsrw has supported FAT32 for quite some time.

    > and also subdirectories.

    fsrw does not support subdirectories.
  • KyeKye Posts: 2,200
    edited 2012-02-28 18:05
    FSRW will always be faster. You can't even replace my block driver with FSRW's block driver and get the same speed.

    If you need speed go with FSRW.
    Kye's drivers aren't even in the same ballpark in speed. But they are fast
    enough for some uses.

    My drivers's readByte function goes at 3KBs... FSRW goes at 32KBs. O_o

    ---

    My goal for my code was not to be fast though. My goal was to support all the file system functionality FSRW does not have.
  • Cluso99Cluso99 Posts: 18,066
    edited 2012-02-28 18:32
    Thanks rokicki.

    I must do some proper speed tests as I sure don't want to slow access in ZiCog, or any of the new OS I am planning.

    In fact, I am using mb_rawb_spi26_rr006.spin for the low level pasm driver by lonesock. The upper level is fsrw26_rr006 .spin. (the _rr006 is to force release of the spi pins to tristate). I can simply recompile using fsrwFemto_rr007.spin. Apologies to anyone who had input to these drivers that have not been mentioned.

    Would it be difficult to support subdirectories?

    Perhaps I need to use a mix, using your pasm for the physical access??? I need some free time to perform some checks.
  • KyeKye Posts: 2,200
    edited 2012-02-28 21:05
    @Cluso99

    My driver does extra FAT book keeping when writing files.

    You should get a nice speed bump if you Frankenstein both drivers together for reading... see the last post here: http://forums.parallax.com/showthread.php?128553-Better-than-sliced-bread!-SD3.01-FAT16-32-Driver-Updated!/page3 #140

    For writing you probably won't have much of a speed boost. But, I did not really test the Frankenstein'ed version of my driver much.

    And... I threw away the code... So... it will have to be re-written.
  • barney831barney831 Posts: 2
    edited 2012-03-03 09:21
    I put together my very first spin program to count slow pulses from an optical tach and write the counts on an SD card that I attached to an USB prototype board. I used bits and pieces of spin code from this forum. The program loads from the eeprom, runs fine and writes the data to the SD card as long as the board is connected to my computer through the USB port. When I try to run it on battery power with no USB connection, there is no file written on the SD card and a small red led next to the USB port is flashing. It appears that the propeller may be trying to communicate through the USB port and not booting the program from the EEprom.

    I would appreciate any suggestions?

    Thanks
  • KyeKye Posts: 2,200
    edited 2012-03-03 12:06
    You are most likely suffering from the FTDI reset problem.

    You need check the state of the pin 31 when the prop chip turns on.

    If high then also turn the serial driver on.

    If low then do not turn the serial driver on.

    The issue is do to the FTDI chip being powered by the propeller chip's pin 30 when the propeller chip turns on. And then when the FTDI chip turns on it resets the propeller chip. Which causes an infinite reset loop.

    Thanks,
  • Cluso99Cluso99 Posts: 18,066
    edited 2012-03-03 13:02
    Kye: Thanks for the readbyte speed comparisons.
    Have you compared readsectors? This is where I would require the speed, and of course writesector.
  • KyeKye Posts: 2,200
    edited 2012-03-03 15:45
    I think FSRW is about 3X faster than my readData function. I think the writeData function for FSRW is 3X to 4X faster.

    My driver has about the same performance of the original FSRW library when using my readData and writeData functions.
  • barney831barney831 Posts: 2
    edited 2012-03-03 15:54
    Thanks for the tip, Kye!

    I used PST when debugging my program and I commented out all reference to it for the final version -except I missed the first two:

    PST :" Parallax Serial Terminal"
    PST.Start(115200)

    When I commented these out, it works fine.
Sign In or Register to comment.