Working with SD cards
We are going to use the SD card as flash memory. It will not have a full (FAT
) file system, and can not be read on a PC by the usual methods. It will not be possible to drag and drop a raw audio file to the card and read it with the MSP430, nor will it be possible see recordings from the file browser on a Mac or PC. Special disk tools provide access to the raw disk, but a full FAT file system implementation is too big for the tiny microcontroller. The F2013 has 128 bytes of RAM and 2 kilobytes of flash. A workable FAT implementation
requires 1024 bytes of RAM
and several kilobytes of flash program space.
The prototype design accesses the SD card using the simple SPI protocol
. SPI is a simple three wire interface that allows a microcontroller to read and write data from external chips. If you want the dirty details on how the SD card works in SPI mode, read some of these tutorials [Tutorial 1
, Tutorial 2
]. A source code library
from TI provides easy access to the disk without writing our own initialization and read/write routines (mmc.c/mmc.h in the project archive).
SD card storage is divided into 512 byte chunks called sectors
. A full 512 byte sector must be read or written at once. The MSP430F2013 has only 128 bytes of RAM -- not enough to hold a whole sector for random access. We can still read/write each byte in order, as it's needed. This method will suffice as long as each byte is read or written sequentially.
Playing an audio file is as simple as reading a byte from the SD card and writing it to the PWM duty cycle register.
Converting audio to a raw format
My 'hello world' audio clip comes from the intro to my videos. I converted the clip to an 8KHz .wav file with Audacity
and then saved it to raw text file with the free version of Switch
, as described here
- First, install Switch.
- Start Switch, and add your desired files to the queue by clicking "add files".
- Now set the output format to ".raw", and then click "Encoder Options". Set the encoder format to "8 bit unsigned", sample rate to "8000", and channels to "mono".
- Now click convert and the raw version of the audio files are created.
The raw text version of the audio file is included in the project archive