Take the 2-minute tour ×
Electrical Engineering Stack Exchange is a question and answer site for electronics and electrical engineering professionals, students, and enthusiasts. It's 100% free, no registration required.

I'm doing a project on PIC, which needs a large amount of memory to store data. I want to use an SD card as the memory storage element. I don't want any type of file system.

I googled the interfacing of SD cards with microcontrollers. I found that all of them are using some kind of file system. Is it possible to interface an SD card without any file system, like a serial EEPROM?

share|improve this question
I did this years ago on a project using MMC mode and it's certainly possible although a lot easier if you have 512 bytes of RAM free to hold a sector. Did you have that much available? –  PeterJ Jun 7 at 7:36
No, Ijust want to read and write 8 bit at a time. –  Linu Das Jun 7 at 7:38
Yeah you can, but take into account that SD cards are flash devices, so any data you write will trigger a block write. Repeated small write will wear out a block incredibly fast. Also, you will probably have very long pauses between writes as a block read-modify-write can take up to 100ms in a crappy SD card, and still something like a couple ms in a good card. And this amount of time is variable; depends on garbage collection and such. –  user36129 Jun 7 at 7:41
It's too long ago for me to remember reliably but I think you might get stuck with having to program an entire page at once, unlike some other FLASH devices where you can erase a page and then keep adding bytes. –  PeterJ Jun 7 at 7:45

2 Answers 2

You didn't mention which PIC you are using, but assuming it is one of the smaller ones such as the PIC16 then with it's limited RAM (99% of PIC16's have no more than 1K of RAM) it would be impossible to implement even a FAT16 file system since multiple 512 byte buffers are needed. (Microchip has a useful library to implement a FAT16/FAT32 file system but it is only applicable to the PIC18, PIC24, dsPIC33 and PIC32.)

You did mention that due to limited RAM, you would like to just write or read a byte at a time. Although, as others have stated, an SD card is typically broken up into 512 byte blocks, you don't need to use all of the bytes. Worse case, you could store just one byte per block and waste the other 511. This seems preposterous, but due to the enormous size of the SD cards available today it would actually work. If you have an 8GB card, than means there are 16M blocks, which means you can store 16 MB of data in this way.

However, it is going to be very slow, something like 10 ms or more per byte, because you are going to have to issue a command to erase each block before it is written. You didn't mention the amount of data that is contained in one of your log entries, but it would be much much better if you could buffer up one entry (say 25 bytes or whatever that is) and write that to a block. So each block becomes a log entry. Because the time to write the bytes is once again dominated by the time it takes to erase the block, writing out an entry log entry will be as fast as writing a single byte.

Since you are essentially using this as extended memory, you don't have remove the card and read it in a PC (which would require using special software to dump out the raw blocks). Instead, since you already have the read block routine in your code anyway, and assuming you have a UART, I would dump the log data out in a serial fashion to a PC; you could use a FTDI UART-to-USB bridge and the data would appear on your PC as a COM port.

share|improve this answer

Yes, any file system will be calling lower level functions that could be named something like writeBlock and readBlock, which are the ones that you'd be calling directly. Since you are using a microcontroller, you'll most like interface to the card in SPI mode, which is perfectly fine for logging applications - not so much for faster applications like video recording.

Your block size will be typically 512 bytes, so that's the minimum chunk of data that you'll be writing/reading in one go. Single byte transactions are not supported (there is no command you can send to make such a thing happen).

Having said that, you might want to think about how you're going to get the data out of the card, since there is no file system. This means that when you plug it into your computer (if that's how you're getting the data out) running a mainstream OS, there won't be any files that you can just drag and drop onto your desktop. You'll have to write a special application that accesses the SD card's raw data.

For that simple reason I would suggest to use a file system, such as FAT32, which is very common in logging applications and you'll find several ready-to-use libraries on the net.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.