SD Card Interface Example
For Microchip dsPIC30F4013 Microcontroller and DSP
SD Card Example
TRAXMOD Forum

Schematic Diagram
Firmware Source Code

Microchip dsPIC30F4013
SanDisk SD Card Product Manual

PIC16F876 Example

While developing our TRAXMOD digital audio player, we spent a lot of time trying to get an SD Card to interface with our microcontroller successfully. Yes, the specifications are available to download, but moving from documentation to actual working hardware is still difficult when you don't have at least one working example sitting on your desk to expand upon.

Here we provide our simplest bare bones example schematic and firmware source code for reading one sector (512 bytes) of data off a standard SD Card. This example initializes the SD Card into SPI Mode. In theory, native SD Card mode has higher maximum bandwidth. However, unless you are designing some kind of FPGA hardware, SPI is the fastest way to move data in and out of a PIC microcontroller lacking an external memory interface.

The SanDisk SD Card Product Manual specifies that maximum clock rate for SD Cards in SPI Mode is 25MHz. This is a problem when running the dsPIC at 30MIPS. On my 32MB Kingston SD Card, if I try to read data when clocking the SPI port at 30MHz, I get junk. You'll need to configure the SPI port to prescale the clock 1:2 for it to work properly when the CPU is running at 30MIPS.

This example is powered by 3.3VDC. As far as I know, SD Cards are not 5V tolerant, so be careful not to over voltage them. Running at 3.3VDC means that you can not crank your dsPIC up to the fastest clock setting. This example does not attempt to do any dual voltage power and thus the dsPIC is running at a measly 7.37MIPS. It is not too hard to implement 5V/3.3V logic voltage conversion because all of the signals are "one way" only in SPI mode (no bi-directional signals). A cheap 74VHC08 logic chip should be able to provide voltage conversion. Make sure it is "VHC" type - those are the ones with 7VDC tolerant inputs. You can look at the TRAXMOD/dsPIC project for an example that uses voltage conversion.

If you have further questions, feel free to ask in the TRAXMOD Forum.

Where to Buy Cheap SD Cards?

It looks like Surplus Computers has some really cheap SD Cards available for sale. At the time of this writing, you can get a refurbished HP 32MB SD Card for $5.99 (with free shipping!). Even though 32MB is pitiful, you probably don't want to use a big expensive SD Card when you are first trying to get your new interface debugged, just in case you end up frying the card. For initial development purposes, grab a couple of these smokin' cheap cards!

Copyright © 2005, K9spud LLC.