www.nutsvolts.com/index.php?/magazine/article/october2010_Kibalo
2 GB. These cards ship preformatted with a FAT16 or
FAT32 file system. This is the exact file format for all of
Windows’ machines (we will discuss this more a little
later). Because of this, the SD card can be accessed on
virtually any PC with an SD reader. Once inserted into a
PC reader, Windows allows the SD card to assume the
“identity” of another disk drive within the PC. At that
point, Windows’ operating system can be used seamlessly
with the SD card files, and file data can be read as long as
Windows software recognizes the file extension
associated with the file. For these demos, I restricted
myself to Secure Digital SD cards using card sizes of 256
MB, 512 MB, and 2.0 GB. They are readily available, and
my suggestion is to use one for these experiments.
■ FIGURE 2. SD cards.
Background on FAT16 and
FAT32 File Systems
Just to give some background on this subject, in
order to store files, the PC needs a filing system that
defines the names of the files, as well as a system to track
which sector (512 bytes or smallest traceable data
“chunk” in a file system) is stored in which file. In addition
to reading and writing data, the system should be able to
create, delete, and rename files. The File Allocation Table
(or FAT) is used as the filing system or “personal card
catalog” that supports these functions for both the PC and
the SD card.
The job of FAT is to keep track of all files on a given
system. FAT16 is the oldest of the Windows file systems
and the 16 refers to the fact
that this file system allocates 16
bits to store addresses of each
sector. It therefore has a
limitation of supporting SD
cards of up to 2 GB. FAT32, on
the other hand, uses 32 bits as
a sector address to support up
to 2 TERA bytes of data.
The Microchip library is
configured to support both
formats. This provides a lot of
removable data storage
capability for microcontrollers
(like the Experimenter) to take
advantage of.
Experimenter. Note that SD cards operate from 2.0V to
3.6V and this is easily accommodated with the
Experimenter + 3.3V operations. SD cards support nine
electrical contacts in addition to two contacts for insertion
detection and write-protection switch setting. The nine
electrical contacts can work in two distinct modes of
communication: the native original SD bus (4-bit parallel
interface); or an SPI (Synchronous Serial Interface) mode.
SPI is the mode we will use for the Experimenter. When
using SPI, not all of the electrical pins are used and are
therefore tied high. For the Experimenter, that leaves us
with just eight signals in total that we must support (see
Figure 4).
• CD — SD card detect
• CS — Card select
• WP — Card write protection setting
• DO — SPI serial data out of
card
• DI — SPI serial data into card
• CLK — SPI clock for data
transfer (originates in
Experimenter)
• Power, GND — + 3. 3 VDC
and ground from the
Experimenter
The SD Card
Hardware Interface
The hardware interfaces are
shown in Figure 3. The card
interface itself is shown first;
then the card with the carrier
interface second; and finally a
block diagram of the entire
system connected to the
The PIC24F microcontroller
on the Experimenter has two
internal SPI peripherals, SPI1
and SPI2. All the demos
configure the Experimenter
I/O expansion bus for SPI2
and digital I/O. The SPI2
supplies three basic pins for
communication: Serial Data
in (SDI), Serial Data out
(SDO), and Serial Clock (SCK).
Chip Select (CS), card detect,
and write-protect are
configured as digital I/O. The
final I/O expansion bus
■ FIGURE 3. SD card and
connector interfaces.
October 2010 47