chipKIT® Development Platform

Inspired by Arduino™

Basic SD-card writing

Created Mon, 29 Oct 2012 03:01:25 +0000 by ckdude


Mon, 29 Oct 2012 03:01:25 +0000

Being able to read/write to files on an SD card now, I'm now wondering what's the best way to do this. I intend to dump lots of CSV data to it (datalogging), so I want to optimize speed and data integrity. I mention that last part because at one point I was not closing the file and none of the data got written to the file. So I suspect I should close the file periodically, or at least flush the data. But what does that do to performance? And what is a good interval (number of bytes) that I should flush at?

Anything else I should be aware of for data integrity or speed? For example, SD-cards allow hot-swapping, but I'm guessing I should do a file close before removing the card, right?


Thu, 01 Nov 2012 11:41:13 +0000

..maybe you can indicate how much data and how fast you want to write to the Sdcard. Afaik currently the write speed is 100kB/sec (see the other topics). Mind the Sdcard's write latency - this could be up to 250msecs. So you must consider that when you want to write a continual data stream down to the SDcard. Typical write speed with supermarket-like SHDC card achievable on the pic32 is ~400kB/sec at 20MHz SPI. All cards today do wear leveling, so when you overwite the same flash memory cells many times the cpu inside the SDcard will find other place for placing your data, thus minimise the wear. Data integrity - hot swap must be supported by the system (?), normally is not, so you have to flush/close and power off properly before you start tackling the card.