//Usage: vs1002SCIWrite(SCI_MODE, SM_SDINEW); //Inputs: unsigned char address - Adress of the register to be written to // unsigned short int data - Data to write to the register //Outputs: None //Description: Writes "data" to the register defined in "address" void vs1002SCIWrite(unsigned char address, unsigned short int data) { SELECT_MP3_SCI(); SPI0_send(WRITE_COMMAND); SPI0_send(address); SPI0_send(data >> 8); // Send High Byte of data SPI0_send(data & 0x00ff); // Send Low Byte of data UNSELECT_MP3_SCI(); delay_ms(1); }
//Usage: vs1002SendMusic(bufferedSongData, BUFFERSIZE); //Inputs: unsigned char* songData - pointer to MP3 data that is to be sent to mp3 player // int buffer_size - size of song data in bytes //Outputs: None //Description: Sends the data in the songData buffer to the MP3 player void vs1002SendMusic(unsigned char* songData, int buffer_size){ SELECT_MP3_SDI(); for(int i=0; i<buffer_size; i++){ SPI0_send(*songData++); //Send the buffered byte of data, then increment the buffer position } UNSELECT_MP3_SDI(); }
/*---------------------------------------------------------------------------- MAIN function *----------------------------------------------------------------------------*/ int main (void) { /* Main Program */ char state = 0; uint8_t buf[] = {0x5, 0xA, 0x3, 0x5A}; SysTick_Config(SystemCoreClock/100); /* Generate IRQ each ~10 ms */ LED_init(); /* LED Initialization */ SER_init(); /* UART#1 Initialization */ SPI0_init(); while (1) { /* Loop forever */ if (clock_1s) { clock_1s = 0; state++; if (state & 0x01) { LED_On(); sendchar('A'); sendchar('\n'); sendchar('\r'); SPI0_send(buf, 4); } else LED_Off(); } } }
//Usage: register_value = vs1002SCIRead(SCI_MODE); //Inputs: unsigned char address - Address of the register to be read //Ouputs: None //Description: Returns the value of the vs1002 register defined by "address" unsigned short int vs1002SCIRead(unsigned char address) { unsigned short int temp; SELECT_MP3_SCI(); //delay_ms(1); SPI0_send(READ_COMMAND); SPI0_send(address); temp = SPI0_recv(); temp <<= 8; temp |= SPI0_recv(); //delay_ms(1); UNSELECT_MP3_SCI(); delay_ms(1); return temp; }
//Usage: vs1002SineTest(126); //Inputs: unsigned char pitch - pitch of the sine wave to be produced //Outputs: None //Description: Runs the Sine Test defined in the vs1002 datasheet //**NOTE: ** for a sine wave test @ 5168 hz, send sequence: 0x53, 0xEF, 0x6E, 126, 0, 0, 0, 0 void vs1002SineTest(unsigned char pitch) { SELECT_MP3_SDI(); SPI0_send(0x53); SPI0_send(0xEF); SPI0_send(0x6E); SPI0_send(pitch); //Send the Pitch SPI0_send(0); SPI0_send(0); SPI0_send(0); SPI0_send(0); UNSELECT_MP3_SDI(); }