SD Card C driver – Poor man’s FAT

To get my SD card driver going, I’m simply dumping files on it with a regular computer.  The SD card is formatted with FAT16.  This is very useful if you need to edit the files first on a PC; as you use the SD card with an ordinary card reader, your PC will see the card as a regular disk drive. To get the data at the micro controller’s side, the operation is a bit … Continue reading

SD Card C driver – Read multiple sectors

In a previous post I showed you how to read a single sector from a SD card.  Now we’ll progress a little further by reading multiple sectors at once.  Since on a micro controller this very memory consuming, such an operation can only take place when the data is transferred immediately to its destination without using large buffers.  In my example I’m reading data across multiple sectors from an image file on the SD card and … Continue reading


Before This week I’ve been fighting with my PIC18F4550 for my TFT LCD abd SD card reader controllers.  I’ve been using the HiTech C before and since a couple of months XC8 from Microchip, but now I encountered some very strange behavior.  The timing of the SD card access was not right according my logic sniffer, thus I started to dig deeper for the cause.  I figured it out quite quickly (the XC8 compilers warns … Continue reading

SD Card C driver – Read a sector

Initializing the card was the difficult part, now the fun can start.  Once the SD card has been initialized successfully (see this post), the clock speed can be increased to whatever speed your card can handle.  I’m using the SPI’s maximum speed according to the installed crystal and PLL.  This gives me a SPI clock frequency of 12 MHz, well within the range of what most modern SD cards can handle. Once the read sector … Continue reading

SD Card C driver – SD Initialization

1. Power Up During the initialization phase, the SPI clock must be lowered to 400 kHz according to the standards.  However my PIC is unable to lower to that speed,  the lowest I can get with CPU clock of 48 MHz is 750 kHz (Fosc/64).  Tests have proven that, with the cheap Chinese SD cards I use, this higher clock speed is not a problem.  I tested a couple other cards and I couldn’t find … Continue reading

SD Card via SPI – C driver

Together with my TFT LCD screen came also a SD card reader.  The card reader is very useful to extend the microcontroller’s limited memory.  When using LCDs, the memory (ROM) of your controller quickly gets eaten up by the fonts and bitmap images that consume quite some memory.  A typical font takes up about 4 KBytes, a bitmap image for 320×240 pixels takes 133 KBytes (262000 colors).  I’m working mainly with PIC16F and PIC18F series microcontrollers which limits … Continue reading