I'm trying to log some data, so if I don't clear it, it is sometimes
hard to tell where the new data ends.
If you are logging ASCII data, this is not a problem. Simply reserve special characters for 'data begins here' and 'data ends here'. Even if you are logging binary data, it may be worth changing the encoding to something like base64 ( http://en.wikipedia.org/wiki/Base64 ) to net you special characters for controlling your data sequence (GB memory cards are cheap, and base64 only introduces 33% data overhead).
Alternatively, you could have an extra file that contains the data boundaries for your log files as a number of bytes. This is going to be a hassle with an interface as limited as petitFAT though, as you can only open a single file at a time. Depending on how much RAM and program memory you can spare on your MSP430, you may consider moving to a more feature-rich FAT implementation.
If I call the pf_write function by timer interrupt, how do I actually
write it to MMC? From what I've read, it seems like I have to
terminate write and reinitiate it again? e.g., this line pf_write(0,
0, &bw);
In a simple logger that does nothing but write sequentially to a single file you shouldn't need to call pf_write(0,0,&bw) until you shut down your device entirely. (It may or may not be necessary to do so before seeking to another position.)
If you absolutely want to stick with your 'overwrite entire file' idea, you could try whether first getting the file size and then writing larger blocks of \0s instead of single bytes gives you a significant speedup.
I have another question for you since you seem to be familiar with petitFAT. If I call the pf_write function by timer interrupt, how do I actually write it to MMC? From what I've read, it seems like I have to terminate write and reinitiate it again? e.g., this line pf_write(0, 0, &bw);
– user2218339 Jul 29 '13 at 18:55for(;;){ strcat(value,",\n"); res = pf_write(value, strlen(value), &bw);I didn't callres = pf_write(0, 0, &bw);and it seems to work, though I think this might be a bad way to do it. Any tips? – user2218339 Jul 29 '13 at 19:06