Playing MP3 with Music Shield and WIZwiki-W7500
Dependencies: FTPClient javakysSDFileSystem2 WIZnetInterface mbed
Prerequisite
This example is for playing MP3 file stored in SD card on WIZwiki-W7500 and updating MP3 files from server to SD card via FTP protocol.
To implement this function, you need a Platform board, network Interface board, MP3 decoder board and SD card. Below are what we used.
- WIZwiki-W7500 from WIZnet (Platform board and Ethernet I/F board)
- Music shield from Seeed Studio
- SD card
Hardware Configuration
WIZwiki-W7500 Pin map
SPI1 for SD Card
SPI1 on WIZwiki-W7100 is for reading from or writing to SD card and pins for SPI1 are PB_0, PB_1, PB_2 and PB_3.
SPI0 and other control pins for MP3 decoder
WIZwiki-W7500 communicates to MP3 decoder on Music Shield via SPI0 pins of which consists of PC_12, D11, D12 and D13.
And PC_13, PC_14 and PC-15 are used for DCS, DREQ and RST, respectively.
InterruptIn pins for 5-Way Navigation Switch
D3, D4, D5, D6 and D7 are connected to 5 way navigation switch on Music Shield.
When user pushes the switch to one way, a relevant pin is grounded so that he or she should make it set high at the beginning.
Software
SPI Initialization
//Declaration in VS1002.cpp VS1002::VS1002(PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName dreq, PinName dcs) : _DREQ(dreq), _RST(rst), _spi(mosi, miso, sck), _CS(cs), _DCS(dcs), _sd(mmosi, mmiso, ssck, ccs, name) { } //Initialization in main.cpp VS1002 mp3(PB_3, PB_2, PB_1, PB_0,"sdc",D11, D12 ,D13, PC_12, PC_15, PC_14, PC_13);
Mapping 5-Way Navigation Switch into InterruptIn pins
main.cpp
InterruptIn K_VU(D3); // Volume UP Key InterruptIn K_VD(D7); // Volume Down Key InterruptIn K_FW(D4); // Foward Key InterruptIn K_BW(D6); // Backward Key InterruptIn K_ONOFF(D5); //Play/Resume or Pause Key
Additional codes due to mbed library bug of WIZwiki-W7500
main.cpp
//Operating Clock Frequency Set *(volatile uint32_t *)(0x41001014) = 0x0060100; //Set all InterruptIn pins to Internal PullUp *(volatile uint32_t *)(0x41003000) = 0x00000002; //D6 *(volatile uint32_t *)(0x41003004) = 0x00000002; //D5 *(volatile uint32_t *)(0x41003008) = 0x00000002; //D4 *(volatile uint32_t *)(0x41003080) = 0x00000002; //D3 *(volatile uint32_t *)(0x41003098) = 0x00000002; //D7
Caution
This example can play only MP3 files with up to 192KHz sample rate//
VS1002.h@2:cea9f6564641, 2017-03-30 (annotated)
- Committer:
- javakys
- Date:
- Thu Mar 30 10:29:51 2017 +0000
- Revision:
- 2:cea9f6564641
- Parent:
- 1:fc4e0c572992
Function Description Update
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
javakys | 1:fc4e0c572992 | 1 | #ifndef VS1002_H |
javakys | 1:fc4e0c572992 | 2 | #define VS1002_H |
javakys | 1:fc4e0c572992 | 3 | |
javakys | 1:fc4e0c572992 | 4 | #include "mbed.h" |
javakys | 1:fc4e0c572992 | 5 | #include "SDFileSystem.h" |
javakys | 1:fc4e0c572992 | 6 | #include "string" |
javakys | 1:fc4e0c572992 | 7 | #include "string.h" |
javakys | 1:fc4e0c572992 | 8 | |
javakys | 1:fc4e0c572992 | 9 | |
javakys | 1:fc4e0c572992 | 10 | //SCI_MODE register bits as of p.26 of the datasheet |
javakys | 1:fc4e0c572992 | 11 | #define SM_DIFF 0x0001 |
javakys | 1:fc4e0c572992 | 12 | #define SM_SETTOZERO 0x0002 |
javakys | 1:fc4e0c572992 | 13 | #define SM_RESET 0x0004 |
javakys | 1:fc4e0c572992 | 14 | #define SM_OUTOFWAV 0x0008 |
javakys | 1:fc4e0c572992 | 15 | #define SM_PDOWN 0x0010 |
javakys | 1:fc4e0c572992 | 16 | #define SM_TESTS 0x0020 |
javakys | 1:fc4e0c572992 | 17 | #define SM_STREAM 0x0040 |
javakys | 1:fc4e0c572992 | 18 | #define SM_PLUSV 0x0080 |
javakys | 1:fc4e0c572992 | 19 | #define SM_DACT 0x0100 |
javakys | 1:fc4e0c572992 | 20 | #define SM_SDIORD 0x0200 |
javakys | 1:fc4e0c572992 | 21 | #define SM_SDISHARE 0x0400 |
javakys | 1:fc4e0c572992 | 22 | #define SM_SDINEW 0x0800 |
javakys | 1:fc4e0c572992 | 23 | #define SM_ADPCM 0x1000 |
javakys | 1:fc4e0c572992 | 24 | #define SM_ADPCM_HP 0x2000 |
javakys | 1:fc4e0c572992 | 25 | |
javakys | 1:fc4e0c572992 | 26 | extern int new_song_number; |
javakys | 1:fc4e0c572992 | 27 | extern int volume_set; |
javakys | 1:fc4e0c572992 | 28 | extern bool pause; |
javakys | 1:fc4e0c572992 | 29 | extern bool mute; |
javakys | 1:fc4e0c572992 | 30 | extern char * song_name[9]; |
javakys | 1:fc4e0c572992 | 31 | |
javakys | 1:fc4e0c572992 | 32 | |
javakys | 1:fc4e0c572992 | 33 | class VS1002 { |
javakys | 1:fc4e0c572992 | 34 | |
javakys | 1:fc4e0c572992 | 35 | public: |
javakys | 1:fc4e0c572992 | 36 | |
javakys | 1:fc4e0c572992 | 37 | VS1002(PinName mmosi, PinName mmiso, PinName ssck, PinName ccs, const char *name, PinName mosi, PinName miso, PinName sck, PinName cs, PinName rst, PinName dreq, PinName dcs); |
javakys | 1:fc4e0c572992 | 38 | |
javakys | 1:fc4e0c572992 | 39 | void cs_low(void); |
javakys | 1:fc4e0c572992 | 40 | void cs_high(void); |
javakys | 1:fc4e0c572992 | 41 | void dcs_low(void); |
javakys | 1:fc4e0c572992 | 42 | void dcs_high(void); |
javakys | 1:fc4e0c572992 | 43 | void sci_en(void); |
javakys | 1:fc4e0c572992 | 44 | void sci_dis(void); |
javakys | 1:fc4e0c572992 | 45 | void sdi_en(void); |
javakys | 1:fc4e0c572992 | 46 | void sdi_dis(void); |
javakys | 1:fc4e0c572992 | 47 | |
javakys | 1:fc4e0c572992 | 48 | void sci_initialise(void); |
javakys | 1:fc4e0c572992 | 49 | void sdi_initialise(void); |
javakys | 1:fc4e0c572992 | 50 | void reset(void); |
javakys | 1:fc4e0c572992 | 51 | void power_down(void); |
javakys | 1:fc4e0c572992 | 52 | |
javakys | 1:fc4e0c572992 | 53 | void sci_write(unsigned char, unsigned short int); |
javakys | 1:fc4e0c572992 | 54 | void sdi_write(unsigned char); |
javakys | 1:fc4e0c572992 | 55 | unsigned short int read(unsigned short int); |
javakys | 1:fc4e0c572992 | 56 | void sine_test_activate(unsigned char); |
javakys | 1:fc4e0c572992 | 57 | void volume(signed int,signed int); |
javakys | 1:fc4e0c572992 | 58 | void sine_test_deactivate(void); |
javakys | 1:fc4e0c572992 | 59 | void play_song(int); |
javakys | 1:fc4e0c572992 | 60 | |
javakys | 1:fc4e0c572992 | 61 | int num_of_files; |
javakys | 1:fc4e0c572992 | 62 | |
javakys | 1:fc4e0c572992 | 63 | DigitalIn _DREQ; |
javakys | 1:fc4e0c572992 | 64 | DigitalOut _RST; |
javakys | 1:fc4e0c572992 | 65 | |
javakys | 1:fc4e0c572992 | 66 | protected: |
javakys | 1:fc4e0c572992 | 67 | |
javakys | 1:fc4e0c572992 | 68 | SPI _spi; |
javakys | 1:fc4e0c572992 | 69 | DigitalOut _CS; |
javakys | 1:fc4e0c572992 | 70 | DigitalOut _DCS; |
javakys | 1:fc4e0c572992 | 71 | SDFileSystem _sd; |
javakys | 1:fc4e0c572992 | 72 | |
javakys | 1:fc4e0c572992 | 73 | }; |
javakys | 1:fc4e0c572992 | 74 | #endif |