Playing MP3 and Wav files on the uMedia boards

PIC24FJ uMedia

I have received a couple of requests recently for support interfacing a PIC32 or a PIC24 to some popular MP3 decoders/codecs from VLSI technology. Since I had a PIC24 MicroMedia board on my desk that begged to be used, I  took the opportunity to give it a test ride and put the VS1011E chip to its pace.

First of all, I downloaded the VS1011E datasheet and noticed how they had significantly simplified the communication interface since the VS1001 models I had used in the past. In those earlier models you had to use an I2C bus for the control interface (to control volume etc..) and a separate DSP interface (framed SPI-like) for the data stream. Now the two are nicely replaced by a pair of “vanilla” SPI ports with the possibility to share most of the pins and making the whole much easier to handle even with the smallest and simplest microcontrollers. The VS1011 model in particular offers only decoding/play back options (no microphone or line inputs for recording). It has the ability to handle the most advanced MP3 protocols but  it can also handle the most basic WAV files and, through the same format, PCM data streams you might want to generate directly (as zero-length wav files).

The code required to feed the VS1011 has become really trivial, with a single command required, right out of reset, to select the “new” mode (which the VLSI documentation refers to as “VS1002 native” ) and from there it is just a matter of sending batches, of 32-bytes at a time, of data from your media files.

The differences between a PIC24 and a PIC32 implementation can be reduced to the single initialization of the SPI interface (SPI2 is used on the uMedia boards) as the the SPICON register differs slightly between the two architectures. In detail: the PIC32 has a proper baudrate generator, while the PIC24 has only a rudimentary pre-scaler and the module enable bit is found on the SPIxSTAT register of the PIC24 while it is standardized as bit15 of the SPIxCON register of the PIC32.

As you will see in the project included below, there are actually more lines of code dedicated to the test modes than for MP3 playing proper:

  • testMP3Sine(), plays a 1kHz sinusoid
  • playMP3Rom(), plays a short MP3 message from the PIC24  FLASH memory (courtesy of VLSI appnotes)
  • playMP3File(), plays an MP3 or WAV file from the uMedia uSD card


I used the Microchip Application Library to enable graphics and file system access (I had the April 2012 release installed and that’s what I used).  You will find the hardwareprofile.h file useful to configure the MAL for the specific hardware definition of the PIC24uMedia board.

Next, you will realize how the playback code really would benefit from being handled with interrupts, but for a quick start you will appreciate the absolute simplicity of this approach.


This entry was posted in PIC24, PIC32, Tools and tagged . Bookmark the permalink.