sirri 28 Posted October 7, 2013 Share Posted October 7, 2013 that's right. i still could not get it working as well T_T Quote Link to post Share on other sites
russcky 9 Posted October 8, 2013 Share Posted October 8, 2013 Hi @@rotbeer and @@sirri, I was trying to use P2.2 for chip select CS but noticed the change in the library and now use P1.4. #define cs_pin 6 // P1.4 myerr = FatFs.begin(cs_pin,3); // initialize FatFS library calls I think this was my problem. sirri 1 Quote Link to post Share on other sites
sirri 28 Posted October 8, 2013 Share Posted October 8, 2013 Hi @@rotbeer and @@sirri, I was trying to use P2.2 for chip select CS but noticed the change in the library and now use P1.4. #define cs_pin 6 // P1.4 myerr = FatFs.begin(cs_pin,3); // initialize FatFS library calls I think this was my problem. Hi, Can you please confirm that it works with a SDHC card as well?? I just have 4 GB SDHC... T_T Thanks. Quote Link to post Share on other sites
russcky 9 Posted October 9, 2013 Share Posted October 9, 2013 @@sirri, I only have 2 SD cards I have handy to test are 2GB or smaller. I'll see if I can locate any larger and test but a quick check tonight hasn't turned up any. sirri 1 Quote Link to post Share on other sites
russcky 9 Posted October 18, 2013 Share Posted October 18, 2013 Hi @@calinp, The Petit FatFS library is working great, I'm able to read sounds, images and text files perfectly, but is there a way to have more than one file open at the same time? The library doesn't seem to support it, but I need to be reading sounds and images at the same time and my MSP430G2553 doesn't have the RAM to support buffering enough of either to do what I need. Looking at the library I was looking at using the lseek function to open each file and jump to the prev location, but I'm not sure of the consequences of doing so many open/seek/read calls back and forth or even if the speed will be fast enough to keep up with the audio. Any ideas? Quote Link to post Share on other sites
calinp 24 Posted October 18, 2013 Author Share Posted October 18, 2013 Hi russcky, The Petit FatFS library does not support multiple files open. You can find more information on http://elm-chan.org/fsw/ff/00index_p.html . Searching with lseek works, but is very slow to do this multiple times. This library supports a forwarding function that I did not implement (check the examples from the link for an implementation). Calin russcky 1 Quote Link to post Share on other sites
Jon86 0 Posted November 1, 2013 Share Posted November 1, 2013 I'm getting pretty desperate now guys... I've finally got the SD Library working which I'm very happy about! A huge thanks to the people that worked on it! But now I've come across a little problem, I want to write a float value to a text file, I've got it writing "Hello world" just fine, but I can't seem to convert the float to a string :? I've tried to get some help from the good folk on the EEVBlog forums, but I'm still stuck on the conversion... char buf[20]; buf[0] = 0; snprintf(buf, sizeof(buf), "%f", value); rc = FatFs.write(buf, strlen(buf), &bw); Snprintf doesn't seem to work at all... Quote Link to post Share on other sites
PTB 27 Posted November 12, 2013 Share Posted November 12, 2013 @@Jon86 Try this. I have been struggling with the same problem to write a CSV file from variables. Got it working tonight. This has been snipped out of my program and edited to be a more generic structure example. Hope it still works after the edit and I haven't stuffed it. FILE.001 will have to exist on the sd card. Smarter folks will have a better way I am sure, but this is doing what I want on my stellaris. Cheers PTB byte data_length; data_length = 32; char buffer_SDStringWrite[data_length]; for(uint16_t i=0; i<data_length;i++){ buffer_SDStringWrite[i]=' '; } uint16_t A = 23; uint16_t B = 17; float C = 98.543; Serial.println(); Serial.println("Opening a storage file (FILE.001)."); delay(100); rc = FatFs.open("FILE.001"); if (rc) die(rc); Serial.println(); Serial.println("Writing Data to FILE.001"); delay(100); bw=0; for (uint16_t i=0;i<=50;i++) { SDStringWrite = String(i) + "," + String(A) + "," + String( + "," + String(C); SDStringWrite.toCharArray(buffer_SDStringWrite, data_length); rc = FatFs.write(buffer_SDStringWrite, data_length, &bw); rc = FatFs.write("\r\n", 2, &bw); if (rc) die(rc); if (rc || !bw) break; } if (rc) die(rc); rc = FatFs.write(0, 0, &bw); //Finalize write if (rc) die(rc); Quote Link to post Share on other sites
Serginho 4 Posted November 26, 2013 Share Posted November 26, 2013 Hi, Can you please confirm that it works with a SDHC card as well?? I just have 4 GB SDHC... T_T Thanks. Hi Sirri, A bit late maybe, but I have just successfully tested a 8 GB SD HC card with a SD card reader same as the one in your picture and similar wiring (just changed PWR pins). I am using enegia .E0010. One strange behavior in my case (maybe my setup??) is that after changing a 1 GB SD by the SD HC one, my Serial monitor stopped showing anything. After trying LP reset I tried USB cable removal/reinsert. Just after that, serial monitor started showing data again. Strange because just removing and replacing the same SD Card just requires LP reset. I repeated the full process and I got the same situation consistently Regarding the "rc = 6" message I could see that it appears in many situations such as, no card present, CS unplugged, MOSI or MISO unplugged. Good luck with your debugging and feel free to contact me in case I we can use my setup to debug yours. BR, Sergio- Quote Link to post Share on other sites
rotbeer 1 Posted December 2, 2013 Share Posted December 2, 2013 Thanks to previous posts here I've been able to get basic datalogging functionality, but now I want to make things a little more complicated. I've got a question regarding the lseek function. I am building a datalogger and I want to be able to write data to my SD card, stop writing, start again, stop again, start again etc. without data being overwritten. So for example: If I have an accelerometer I want it to write values to the SD card while the sensor is being moved around, but when the sensor stops moving I don't need those values so the logging stops. But once the movement starts again I want to again start writing values without overwriting the data that's already been written (which is what currently happens every time I start, stop, and the start writing data again.) By the way, I am basically using the file writing example that comes with this library, except it's writing my sensor valuse to the SD card instead of "Hello World!" I've looked closely at these reference pages: http://elm-chan.org/fsw/ff/pf/write.html and http://elm-chan.org/fsw/ff/pf/lseek.html I realize that the lseek "offset can be specified in only origin from top of the file." And that "write operation can start/stop on the sector boundary." So my thinking is that I can write code that will tell my file writing process to consider what's already been written, and then start writing data after that when it's time to begin datalogging again. So, 0+X= begin writing here! Where: 0= the beginning of the file X= the last sector boundary (or last byte written?) My question: How do I make this work? Thanks everyone! Quote Link to post Share on other sites
bluehash 1,581 Posted December 2, 2013 Share Posted December 2, 2013 @@rotbeer welcome to the forum. Not sure how to do this in energia. But look up the seek command. Quote Link to post Share on other sites
bluehash 1,581 Posted December 19, 2013 Share Posted December 19, 2013 I can confirm that the lseek command does not seem to work. Adding, say 10, bytes to lseek, still overwrites the previous entry. FatFs.lseek( 10 ); Is it possible for someone to do a quick test. Also, do you have to prep a file on the PC with a fixed size? I know PetiteFS calls for file pre-creation, but fixed size too? Quote Link to post Share on other sites
calinp 24 Posted December 21, 2013 Author Share Posted December 21, 2013 For writing function to work, the file must be created in advance with a size >0. This library can not resize, delete files or change their attributes. For lseek to work you shoud keep in mind that writing with petit fatfs can start only at the begining of a sector, so the pointer shoud go to the next sector in case data needs to be written again. Let's say you write 150 bytes in a file and close it. when the file is opened again for write, lseek shoud have 512 as argument. If one wants to write a single byte and uses lseek(151), then writing will start at the beginning of the same sector and will overwrite the already existing 150 bytes because when a file is closed, the remaining bytes in the sector are filled with nulls. Writing with this library is very restricted but I think it is the only one that can work in less than 512 Bytes of ram. bluehash 1 Quote Link to post Share on other sites
bluehash 1,581 Posted December 21, 2013 Share Posted December 21, 2013 For writing function to work, the file must be created in advance with a size >0. This library can not resize, delete files or change their attributes. For lseek to work you shoud keep in mind that writing with petit fatfs can start only at the begining of a sector, so the pointer shoud go to the next sector in case data needs to be written again. Let's say you write 150 bytes in a file and close it. when the file is opened again for write, lseek shoud have 512 as argument. If one wants to write a single byte and uses lseek(151), then writing will start at the beginning of the same sector and will overwrite the already existing 150 bytes because when a file is closed, the remaining bytes in the sector are filled with nulls. Writing with this library is very restricted but I think it is the only one that can work in less than 512 Bytes of ram. @@calinp Thanks for the detailed reply calinp.. That SD is going to fill up fast. I'm creating a tutorial for the Blog using your code for logging temperature. Will update once I have it working. Quote Link to post Share on other sites
bluehash 1,581 Posted December 21, 2013 Share Posted December 21, 2013 @@calinp Ok.. I tried what you said... and it works! Tutorial coming up shortly! calinp 1 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.