Skip to main content
Recording to a SD card (example firmware 5)
The whole series of articles comes down to this moment -- it's time to save audio samples to the SD card. Like last time, a MMC/SD card library from TI takes care of accessing the SD card. The original TI library requires a 512 byte block of memory to hold a whole SD card sector, but the F2012/3 chip only has 128 bytes of RAM. A low memory version of the write routine is possible if we write the bytes into the sector sequentially. I broke the write function into three smaller functions that:
  1. mount a sector for writing,
  2. send a single byte to the SD card, and
  3. starts the sector save and unmounts the sector.
If we only write a single byte to the card at a time, a full 512 byte cache is unnecessary. This is the same technique I used to read from the card in Make a talking MSP430 microcontoller.

The example firmware builds on the existing projects. A timer generates an interrupt 8000 times per second. Ten seconds of audio is recorded immediately after the circuit is powered. For these ten seconds, each timer interrupt begins an ADC measurement. Upon completion, the ADC triggers an interrupt that stores the audio sample in a buffer and sets a flag. This flag triggers code in the main program loop to write the byte to the SD card. After ten seconds (80000 samples, 157 sectors), recording stops.

Next, the recorded audio is played in a loop. As in the previous project, each timer interrupt (8000 per second) copies a sample from the SD card to the PWM duty cycle register.

Sector switching and management is handled in the background by the sdRead() and sdWrite() functions. Every 512 bytes the sector is switched -- the old sector is closed and the next sector is mounted. If you use these functions, pay close attention to the setup steps that prepare the card for a sequential read or write. Set the start location to read or write in the flashDisk and audio variables, and manually mount the start sector.

NOTE: The SD card is used as a cheap and handy source of flash storage. Audio data is recorded to the SD card in a raw format. Audio files will not appear if you put the card into a memory card reader and attach it to a PC. The MSP430F2012/3 lacks the resources needed to implement a full FAT file system. The raw data can still be viewed and extracted with special disk tools, such as HxD.

The example program starts recording audio at the beginning of the SECOND sector of the SD card (sector 1). The first sector (sector 0) will be used to record the length of the file in the final digital audio projects. The reserved sector provides 512 bytes for meta data, allowing us to delineate the flash storage space into multiple audio clips.

Next time, I'll finish up with the MSP430 by designing a complete digital audio recording experimenter's board. The final project joins everything from the previous four articles with an amplifier chip that drives a small speaker.

This project uses the digital audio recorder prototype from Make a singing MSP430 microcontoller. I replaced the original F2013 with a F2012. The only difference between these chips is the type of ADC: the F2012 has a 10 bit ADC, the F2013 has a 16 bit sigma delta ADC.

The microphone amplifier prototype is included in the project archive. The circuit was designed with the freeware version of Cadsoft Eagle.

Parts list

U1 - TLV2221 (surface mount, SOT23-5L). TLV2211, and TLV2231 would also work.

Capacitors: (through-hole unless noted)
C4 - 0.1uF (surface mount, 0805)
C5 - 0.01uF
C7,8 - 4.7uF
C9 - 470pF

Resistors: (all through-hole)
R2 - 2K
R5,6 - 18K
R7,8 - 1K1
R9 - 56K

MSP430 electret microphone ampifier(click thumbnails to view gallery)

Microphone amplifier circuitPCB and part placementMic amp renderingMic amp prototypePrototype overview

Related links
Program a MSP430 microcontroller.
Make a singing MSP430 microcontroller.
Make a talking MSP430 microcontroller.


Follow Us

  • No features currently available.

  • More Hot Topics The Daily Fix  •  DIY Warrior  •  Home Ec  •  Handmade
    DIY Disaster Doctor  •  In the Workshop  •  Product Picks

    Home Improvement Videos