Issues writing to SD card to be read by a computer
xander18
Posts: 5
Hello all,
I'm really excited to be messing around with a Propellor. I have some experience with 8052 years ago and Arduino recently but I decided to step into something a bit more interesting. I'm working with Propellor C and SimpleIDE right now, trying to get my C up to speed. There's not as much info out there on Propellor C as SPIN and Arduino so I'm hoping this forum is at least somewhat receptive to stupid questions cause I'll definitely have one or two of them
I'm trying to just read and write a file to an SD card on my Activity Board. My code is somewhat based on John Kauffman's from this thread and is below.
I'm having two issues. The first is that the data is reading back in incorrectly, returning as 0. The second is that when I jump the SD card over to a computer it's writing in hex instead of numeric. I'm hoping to eventually use this for a DAQ system so I'll be trying to write a CSV. Any tips?
I'm really excited to be messing around with a Propellor. I have some experience with 8052 years ago and Arduino recently but I decided to step into something a bit more interesting. I'm working with Propellor C and SimpleIDE right now, trying to get my C up to speed. There's not as much info out there on Propellor C as SPIN and Arduino so I'm hoping this forum is at least somewhat receptive to stupid questions cause I'll definitely have one or two of them
I'm trying to just read and write a file to an SD card on my Activity Board. My code is somewhat based on John Kauffman's from this thread and is below.
I'm having two issues. The first is that the data is reading back in incorrectly, returning as 0. The second is that when I jump the SD card over to a computer it's writing in hex instead of numeric. I'm hoping to eventually use this for a DAQ system so I'll be trying to write a CSV. Any tips?
#include "simpletools.h" // Include simpletools header . int DO = 22, CLK = 23, DI = 24, CS = 25; // SD card pins on Propeller BOE // values for writes & values to receive reads int myWriteInt = 11; int myReadInt; int main(void){ sd_mount(DO, CLK, DI, CS); // Mount SD card FILE* fp = fopen("OneInt.txt", "w"); // Open a file for appending print("\nmyWriteInt = %d",myWriteInt); // Tell user value to write fwrite(&myWriteInt, 4, 1, fp); // Write number to SD card fclose(fp); fp = fopen("OneInt.txt", "r"); myReadInt = fread(&myReadInt, 4, 1, fp); // Read from SD & get status print(", myReadInt = %d\n",myReadInt); // Tell user value read fclose(fp); // Close the file } // main
Comments
I'll look into those commands, sounds promising.
Yeah this Propellor stuff looks really cool! I think that the multicore aspect will make me think a lot more critically about how I structure programs and tasks. I read through the 'SimpleIDE is dead' thread and I see a lot of the points and concerns in there about it. But as a relative beginner it was awesome to be able to jump right into Propellor with very familiar software and coding. So good job to everyone who worked on that project and I'm looking forward to seeing the Propellor C community grow.
It builds on the 'XMMC External Flash Code Main RAM Data' model fine but damn, did I really max out the main memory that fast? Seems like a real small program. Am I totally missing some kind of optimization or memory management?
If there aren't file equivalents, you have a few options.
1) Do it in a two step process: Convert to a string with sprinti and then write with fwrite (and reverse for reading, fread and sscani). Or, similar, write your own int-to-string and string-to-int methods.
2) Use the SD card class in PropWare
3) Use the SD card class in libpropeller
Unfortunately, options #2 and #3 don't have "tutorials" in the same way as Parallax's Learn website, so they're not necessarily quite as easy. But both have examples you can use to learn from if you choose to go that route.
Thanks a ton for all the help. Monday morning, back at my desk playing around with this thing. I'll start playing around with option 1, at least for education's sake.
I suspect I'll keep running up against performance issues like this as long as I'm trying to keep it simple. I need to step up my game here and move in the direction of options 2 and 3.
Again, thanks for all the pointers.
Definitely a good idea. It's always good to learn how the standard library works
Dave's approach can yield smaller code because it focuses on the problem at hand.
The code below shows the general solution built-in using sprint(buffer, format, ...) which is comparable to print(format, ...) (about 17KB of code with CMM).
Also jazzed, thanks for SimpleIDE
Edit:
Dave, taking a close look at your code now. This is interesting, I'm just gonna start googling until I'm caught up with it line by line.
jazzed, clearly I need to learn my standard library considerably better.
Thanks again!