SD Card Reading/Writing
MoZak18
Posts: 26
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
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
Good luck!
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.
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.
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
fsrw.spinParallax Serial Terminal.spinsafe_spi.spinSD_Card_Micro_01.spin
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.
If you need speed go with FSRW.
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.
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.
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.
I would appreciate any suggestions?
Thanks
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,
Have you compared readsectors? This is where I would require the speed, and of course writesector.
My driver has about the same performance of the original FSRW library when using my readData and writeData functions.
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.