If you read my
Here's a logic analyzer session file of my MP3 player playing one file. You'll need Saleae's Logic software to view it. Below is a screenshot:
Open it and zoom in to explore. The file shows how I read the data from the SD card and then stream it to the decoder. It also shows how all the pins behave (such as CS, DCS, DREQ, reset). The MOSI and MISO signals are not available for viewing (oops, I'll try to get another snapshot later).
The VS1002d is a MP3 decoder, digital to analog converter, and headphone driver all built into one package, with some other bells and whistles such as recording. VLSI makes these chips, and the VS1002d is actually obsolete because of the new audio formats used today such as .acc and .ogg . Sparkfun now sells the VS1033D on an identical breakout board, go buy that instead.
This chip has two SPI interfaces, one for commands and settings called SCI, the other for streaming audio data called SDI. Both SPI buses use SPI mode 0, meaning the clock starts low and leaves low, and data is read on the rising edge. There’s an active low chip select for both interfaces (CS for SCI and DCS for SDI, the DCS pin is also called BSYNC). With the 12.288 MHz crystal provided on the breakout board, you’re SPI clock speed can’t be more than 2 MHz.
I may have called DCS (correct) as CDS (incorrect) in various places on this website, so if you read CDS anywhere and don't know what I am talking about, I meant DCS. DCS is the active low chip select for the SDI interface.

Green shows the SCI pins and red shows the SDI pins
This chip uses 16 bit registers, and each register has an 8 bit address. To access the registers, you use the SCI interface. To write to a register, first send the write command (0x02), then the address, then the most significant 8 bits of the register, then the least significant 8 bits of the register. Reading a register is the same except the command is 0x03.
You can send an entire MP3 file to the chip at the right bitrate and it’ll play automatically. If you exceed this bitrate, the decoder chip will become too busy as its internal buffer becomes full, and indicate so by making the DREQ pin low. When the DREQ pin is high, it means the decoder can decode at least 32 more bytes of data. When it’s low, you should stop sending the decoder data, although it can take at most 32 more bytes of data before audio glitches occur. If you send data too slowly, your music will sound broken. Only communicate with the VS1002d when the DREQ pin is high, this goes for both the SDI and SCI interfaces.
There’s a hardware reset pin that’s active low, holding this pin low makes the decoder go into a power-down mode. You should reset the decoder as a part of your initialization. The DREQ pin will go low for a brief period of time and then high when the decoder is ready.
This chip needs a clock source between either 12-13 or 24-26 MHz, on the Sparkfun breakout board, a 12.288 MHz crystal is provided for you. There’s a settings register you need to adjust, SCI_CLOCKF must equal the crystal frequency divided by 2000, and then if the crystal is between 12-13 MHz, then you must set bit 15 of SCI_CLOCKF (doubles the frequency), the result is 0x9800 with the 12.288 MHz crystal. This is the only register you ever need to edit, or you can replace the crystal with a 24.576 MHz crystal and then you can even forget about the SCI_CLOCKF register forever. To change this register, write 0x9800 to address 0x03.
You can adjust the left and right side volume with one register at 0x0B, the first 8 bits changes the left side volume, and the second 8 bits is for the right side. 255 will mute the decoder (power down the analog parts of the decoder completely) and 0 will set the volume to loudest.
With all that said, there really isn’t much to initialize, just write to SCI_CLOCKF and set your volume and you are ready to feed MP3 data to the decoder. However, with multiple devices on the SPI bus (the MMC card that stores your MP3 files is the other one), you should be using VS1002’s native SPI modes by setting bit 11 (SM_SDINEW) of register 0x00 (SCI_MODE), this is actually default, but remember this if you choose to configure SCI_MODE.
MP3 data is divided into frames, each frame has a metadata header that contains some general information about the frame, identifying it as MPEG 1.0 layer 3 data (hence MP3), it also includes the bit-rate, and some other info. The decoder will automatically synchronize with this frame header and play the data as you feed it in. This makes rewinding or fast forwarding an MP3 extremely simple. The duration of the song is calculated from the file size and the bit-rate. To play from the middle of a song, just start sending data from the middle of the file, and the decoder will catch the next frame header and start playing from the header. Note that sending an incomplete frame or extra invalid data can cause some audio glitches which are extremely short and mostly unnoticeable.
The decoder can also play WAV files. A WAV file has only one header and the header tells the decoder how long the WAV file is, and the decoder will only play however many bytes it needs to reach the end of the file. This means you can’t rewind or fast forward a WAV file as easily. However, you can trick the decoder into thinking the WAV file is infinitely long (modify the header before you send it to the decoder), and then change your file pointer like you would with a MP3 file to change which part of the song you play. Once the decoder is in “infinitely long WAV” mode, you can’t go back into MP3 mode until you either reset the decoder, or do some stuff to the SCI_MODE register (read the datasheet for details).
That’s about all you need to know about the decoder right now, it has more features but if you want a MP3 player built, that’s all you need to know.
Buy the Sparkfun breakout board! I believe Futurlec also sells a similar board but the Sparkfun version is much more compact and user friendly. The breakout board takes care of almost everything, the clock source, power supply, appropriate pull down resistors, even some capacitors you need to make headphones work. I have a VS1002d board but now they stock some newer chips which support more formats.
Now I’ll talk about connecting it to your microcontroller. This chip uses 3.3 volts and there is no level shifting provided on the breakout board. The board does have a 3.3V regulator so you can power the breakout board with up to 6V (I think… not sure what part number the regulator is but I’ve fed it 5V and it worked fine). If you already connected a SD card to your microcontroller, you shouldn’t have to worry about level shifting since SD cards also use 3.3V.
Link to a page about voltage level shifting
The breakout board already took care of the pull down resistors on the GPIO pins for you. Also note that because the SCI interface is on the decoder is on the SPI bus, there’s a tiny chance that the SCI will mess up SPI communications between the microcontroller and an in-circuit serial programmer during programming, so use a 10 k ohm pull-up resistor on the CS pin.
If you can, either remove the LED from the breakout board or change the LED’s current limiting resistor to another resistor with a higher resistance. I personally find the LED way too bright to look at.
I have my MP3 files stored on a microSD card, I use FatFs to read the files 32 bytes at once, store that in a buffer, and then send it to the decoder’s SDI interface when the DREQ pin indicates that the decoder is not busy. I found it much easier to handle MP3 files by containing the FIL handle inside another struct called MP3File, which contains data such as file name, song title, and song duration. The song title is extracted from the MP3 files by looking for the ID3 tags, both ID3v1 and ID3v2 are checked, but if no tags are found, then the file name is used as the title.
To see some source code, check out my MP3 Alarm Clock.