SD Card
Accessing SD cards as a filesystem on mbed, using an SPI interface.
Hello World
Import programSDFileSystem_HelloWorld
SD File System Hello World
Library
Import librarySDFileSystem
SDFileSystem
Datasheet
https://www.sdcard.org/downloads/pls/Notes
This library supports:
- FAT12 / FAT16 / FAT32
- SD / SDHC cards up to 32Gb
- long filenames
- time stamp
Details
SD Cards are widely used by loads of devices for storage; phones, mp3 players, pc's etc. That means they are a very cheap option for storing large amounts of non-volatile data (i.e. the data is not lost when the power is removed). They should be ideal for data logging and storing audio/images.
SD and MMC cards support various protocols, but common to them all is one based on SPI. This is the one used here as, whilst not being the most high performance, it uses a generic SPI interface so will be more portable.
SD Cards are block devices. That means you read/write data in multiples of the block size (usually 512-bytes); the interface is basically "read from block address n", "write to block address m". Note that a filesystem (e.g. FAT) is an abstraction on top of this, and the disk itself knows nothing about the filesystem.
Based on a SparkFun MicroSD Breakout Board, here is the wiring that will work (you can obviously use either SPI port, and any DigitalOut):
SparkFun MicroSD Breakout | mbed LPC1768 |
CS | p8 (DigitalOut cs) |
DI | p5 (SPI mosi) |
VCC | VOUT |
SCK | p7 (SPI sclk) |
GND | GND |
DO | p6 (SPI miso) |
CD | (NC) |
Warning
Note that VCC is 3.3V from mbed's VOUT pin. Do not use 5V from mbed's VU pin. 5V power may damage the SD card.
The CD (card detect) pin is optional and not used in the example program, but it can be used to detect a card in the micro SD socket. CD connects to ground when no card is present. No connection is made once a card is inserted. It can be read using a DigitalIn pin, if the mode is set to PullUp.
Reference
- SD Card Simplified Specifications
- Notes on the development of this library: SDCards!
- SD association SD Card Formatter - SD cards come formatted, use this to reformat an SD card when needed
You need to log in to post a discussion
Questions
10 years, 1 month ago