Secure Digital (SD) Card Interface

Custom PCB Boards Getting Started Tips Timing Pulse Generation Object Exchange FAQ Programming Examples

 

bullet

Thanks to Thomas Rokicki (forum user "rokicki"), we can easily interface to a Secure Digital flash memory card for mass storage.  His original post is here.  You can download his code from the Object Exchange.

bullet

Mike Green used this code as part of "Femto Basic", which reads and writes data and programs to the SD Card (as well as running "Basic"). 

bullet

There are two cheap ways to connect an SD card to a breadboard:

bullet

Get a Mini or Micro SD card.  These usually come with an adapter to full size SD card.  You can solder directly to this adapter to make the connections.  Here, I've soldered to a uSD card to full size SD card adapter:

bullet
    It is important to prewet both wires and SD card to minimize melting!
bullet
Note that only pins 1..7 only really need to be connected!
bullet

Get a full size surface mount connector and solder it to a single row pin header like this:

bullet

bullet
Note:  If you stick the pin header up the connector, like I did above, just make sure that your connector doesn't have a metal edge on the bottom that shorts out some pins (I had to bend some metal away from the pins to get one working...).
bullet

The better way is to buy an SD card adapter...

bullet
Sparkfun sells a breakout board
bullet
Or, many vendors sell surface mount connectors

  bullet

Here's the pinout for the SD card and connections to Propeller:

bullet

   SD pin #s

bullet
SD Pin SPI Signal Prop Pull-Up Resistor
1 (data line #3) CS (chip select) P3 Yes
2 (command line) MOSI (Master Out/Slave In) P2 Yes
3 (ground)   Vss  
4 (supply)   Vdd  
5 (clock) SCK (clock) P1 Yes
6 (ground)   Vss  
7 (data line #0) MISO (Master In/Slave Out) P0 Yes
8 (data line #1)   -- Yes
9 (data line #2)   -- Yes

  bullet

Use 20k resistors for Vdd for the pull-ups.

bullet

Here's an example with the "Demo" board:    (I used 18k resistors)

bullet

You don't have to use P0-P3.  You can easily change the code to use any four consecutive pins by just calling "mount(n)" instead of "mount(0)", where n is your base pin.

bullet

Rokicki's Object comes with two programs "sdrw_test" and "fsrw_speed" ready to use to test your setup.

bullet

Note:  To use VGA instead of TV with demo board, as in the above photo, just change:

bulletterm:  "tv_text"    to    term: "vga_text" bulletterm.start(12)  to    term.start(16)  bullet

Also, note that the speed test takes several seconds to complete and the time indication may come out negative...  I got this with a 1 GB Lexar SD card.

bullet
"Writing 2M took -1598624256" ,  "Reading 2M took 477277616"
bullet

Also, be aware that you must format your SD card so that it comes out being FAT16.  Here's a table from Rokicki that says what cluster size range you can pick (my Lexar card came formatted correctly):

bullet
Card Size min   max
   4M     512   512
   8M     512    1K
   16M    512    2K
   32M    512    4K
   64M     1K    8K
   128M    2K   16K
   256M    4K   32K
   512M    8K   32K
   1G     16K   32K
   2G     32K   32K
bullet

 Updates: 

bullet

You usually don't need the pull-up resistors and I've left them off my newer designs.

bullet

There's a new version of FSRW in the forum that is much faster, supports multiple files, supports SDHC cards, and FAT32.

bullet

I've figured out a way to add 4 resistors in order to add card detection and write-protect switch detection without using any additional pins.  See literature on my PSM unit for more info.