Sparkfun MP3 Decoder Breakout Board

VS1002

This is an MP3 decoder breakout board availiable from Sparkfun MP3 Decoder Breakout Board.

Mission Statement

The goal is to be able to stream music from an SD Card via the MBED and send it to the VS1002 MP3 Decoder hopefully ending up with some nice music to listen to.

MP3 Decoder Basic Interface

The VS1002 uses SPI Serial Peripheral Interface which is supported in the MBED library. This can be further split up into SCI Serial Control Interface and SDI Serial Data Interface. SCI is used for controlling the decoder hardware and sending out commands and SDI is for sending the actual data to be decoded or placed in registers. SPI can be described as a 4-pin interface; MOSI - Master Output, Slave Input, MISO - Master Input, Slave Input, SCK - Serial Clock, CS - Chip Select. The VS1002 has the interesting function that it has 2 Chip Selects for SCI and SDI, however it is possible to combine these onto one pin, which is what I have done in my code. CS low enables SCI and CS high enables SDI, however, in order to initate a data transfer there must be transition of the state of the CS pin, whereupon the first bit to be read by the VS1002 will be at the first rising edge on the SCK line.

Pinout



TRS Jack
       MBED            VS1002 Breakout               MBED                     TRS Earphone Jack

       NC             MICP           VIN-----------o (40) VOUT                        /\
       NC             MICN         RIGHT-----------------------------------------\   |__|-\
  i.e.(15) o----------RST           GBUF----------------------------------------\ \--|__|  \
  i.e.(16) o----------DREQ          LEFT--------------------------------------\  \___|  |  |
       NC             GPIO 2      GPIO 1              NC                       \     |  |  |
       NC             GPIO 3      GPIO 0              NC                        \__________|
  i.e.(17) o----------BSYNC           SO-----------o (12) miso \
       NC             TX              SI-----------o (11) mosi  }SPI Bus
       NC             RX            SCLK-----------o (13) sck /
   GND (1) o----------GND             CS-----------o i.e.(14)

Beginners' Code

The first task is to get a the VS1002 to talk to the MBED and run a preliminary sine wave test. On top I have included a volume control function, which works by taking the attenuation for both left and right channels in -dB i.e. volume(-20, -40) means left channel attenuation = -20dB and right channel attenuation = -40dB. Here is the example code.





Sparkfun MP3 Decoder Breakout Board









SparkFun MicroSD Breakout Board

#include "mbed.h"
//SCI_MODE register bits as of p.26 of the datasheet
#define SM_DIFF         0x0001
#define SM_SETTOZERO    0x0002
#define SM_RESET        0x0004
#define SM_OUTOFWAV     0x0008
#define SM_PDOWN        0x0010
#define SM_TESTS        0x0020
#define SM_STREAM       0x0040
#define SM_PLUSV        0x0080
#define SM_DACT         0x0100
#define SM_SDIORD       0x0200
#define SM_SDISHARE     0x0400
#define SM_SDINEW       0x0800
#define SM_ADPCM        0x1000
#define SM_ADPCM_HP     0x2000

VS1002 mp3(11, 12, 13, 14, 15, 16, 17);
/*==================================================
 * Main
 *==================================================*/
int main ()
{
    cs_high();                              //chip disabled
    initialise();                           //initialise MBED
    write(0x00, (SM_SDINEW+SM_SDISHARE+SM_TESTS));      //SCI
    cs_low();                               //enable for SDI
    while(1)
    {
    sine_test_activate(170);                    //sine wave should sound every 0.5secs for that
    volume(-20, -20);                           //length, volume -20dB in each channel
    wait(0.5);
    sine_test_deactivate();
    wait(0.5);
    }
}

Now for a .wav file

Sine waves are nice because they tell you that the VS1002 is actually working but, what is really nice is to be able to play something with a bit more variation. The next program includes being able to stream data from a file on the SDCard into an array on the MBED and then to send it to the VS1002. This naturally has to be done as fast as possible to optimise the quality of the sound heard. Despite this, there is a limit at which the speed of the data transmission does not matter because none of the information is being lost. The major problem which audio systems suffer is that they are tempermental and sometimes very subjective. Certain frequencies of data transmission, despite being fast enough, can lead to horrid sound quality whereas others are just better. My SDCard Micro is a Transcend and running at 2GHz! and the VS1002 at 7MHz. The SD Card may seem unnecessarily fast but it is really to free up extra time for the MBED to fulfill other operations in the meantime. Note that the last pin in the constructor is the volume control - an AnalogIn.

#include "mbed.h"
#include "VS1002.h"

VS1002 mp3(5, 6, 7, 8, "sd", 11, 12, 13, 18, 15, 16, 17, 20);               //5, 6, 7, 8, "sd", - SDCard connections
                                                                            //11, 12, 13, 18, 15, 16, 17, - VS1002 connections
int main ()                                                                 //20 - volume pin
{
    /*============================================================
     * MP3 Initialising
     *==========================================================*/
    
    mp3._RST = 1;
    mp3.cs_high();                              //chip disabled
    mp3.sci_initialise();                           //initialise MBED
    mp3.sci_write(0x00,(SM_SDINEW+SM_STREAM+SM_DIFF));                      //enable data streaming
    mp3.sci_write(0x03, 0x9800);
    mp3.sdi_initialise();                                                   //chip enabled
        
    /*============================================================
     * This is the good part
     *==========================================================*/
    
    mp3.play_song("redreded.mp3");  
    return EXIT_SUCCESS;
}

This is great but I'd rather just say that I wish to play the songs all in a row or randomly, so I assign each track a number automatically depending on how they are ordered on the SDCard and when I wish to play track I simply say...

mp3.play_song(TRACK NUMBER HERE); 

i.e.

mp3.play_song(6); 

This means that if I put the function in an IF loop I can increment the track number each cycle and run through several tracks, the application possibilities go on and on...



Files to download

The files
The library

Datasheet

VS1002 MP3 Decoder Datasheet

Enjoy

Dan W