/******************************************************************************* * Function Name : VsRamTest * Description : Test VS1003's register,if received value is 0x807F,then indicate the VS1003 is OK. * Input : None. * Output : None * Return : None *******************************************************************************/ void VsRamTest(void) { u16 regvalue ; regvalue = 0; ControlReset(SET); Delay(100); SPIPutChar(0xff); //����ҝ���ֽھ���Ч���ݣ�����SPI���� SCI_ChipSelect(RESET); SDI_ChipSelect(RESET); ControlReset(RESET); Delay(100); Mp3WriteRegister(SPI_MODE,0x09,0x00); // ����vs1003�IJ���ģʽ while(DREQ); // �ȴ�DREQΪ�� SDI_ChipSelect(SET); // xDCS = 1��ѥ��vs1003�����ݽӿ� SPIPutChar(0x4d); SPIPutChar(0xea); SPIPutChar(0x6d); SPIPutChar(0x54); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); Delay(500); SDI_ChipSelect(RESET); regvalue = Mp3ReadRegister(SPI_HDAT0); // ����þ���־Ϊ0x807F���������å� }
void SFEMP3Shield::SetVolume(unsigned char leftchannel, unsigned char rightchannel){ VolL = leftchannel; VolR = rightchannel; Mp3WriteRegister(SCI_VOL, leftchannel, rightchannel); }
/******************************************************************************* * Function Name : Mp3SoftReset * Description : Soft reset the VS1003 chip * Input : None. * Output : None * Return : None *******************************************************************************/ void Mp3SoftReset(void) { Mp3WriteRegister (SPI_MODE, 0x08, 0x20); while(DREQ); Mp3WriteRegister(SPI_CLOCKF, 0x8b, 0xe8); Mp3WriteRegister(SPI_BASS, 0x00, 0x55); Mp3WriteRegister(SPI_AUDATA,0xAC,0x45); Mp3SetVolume(0x7a,0x7a); // SDI_ChipSelect(SET); SPIPutChar(0); SPIPutChar(0); SPIPutChar(0); SPIPutChar(0); SDI_ChipSelect(RESET); // Mp3WriteRegister(SPI_MODE,0x00,0x04); }
/** Plays a disk file. Returns 1) if the file ends or 2) if the global variable playingState is not PS_NORMAL i.e. user has requested stop or next or previous.*/ void PlayCurrentFile() { char c, nFragments; playingState = PS_NORMAL; /* Request to play normally */ //uiMode = UI_SPEC; /* User interface: show title SPECANA FOR VS1003*/ ///LcdLocateHome(); ///LcdPutConstantString("Opening "); //Serial.print("\r\nBuilding file fragment table..."); //sectorAddress.l = album[currentAlbumCnt].track[currentFile].trackAddr.l; delay(100);//delay here is very important, give some time to sd card.---by Icing nFragments = BuildFragmentTable(); /* Too slow, rewrite! */ //Serial.print("Fragments: "); //Serial.print(nFragments,DEC); ///LcdLocateHome(); ///LcdPutConstantString("Playing "); for (c=0; c<nFragments; c++){ sectorAddress.l = fragment[c].start; //ConsoleWrite ("\r\nPlayer: Playing from sector "); //ConsolePutUInt (sectorAddress.l); if (PlayDiskSectors(fragment[c].length)!=0){ Mp3WriteRegister(SPI_MODE,0,SM_OUTOFWAV); SendZerosToVS10xx(); return; //return without touching the value of playingState } } SendZerosToVS10xx(); // After finishing normally default to requesting to play next song playingState = PS_NEXT_SONG; }
void VS1053_Start() { ControlReset(SET); Delay(100); SPIPutChar(0xFF); SCI_ChipSelect(RESET); SDI_ChipSelect(RESET); ControlReset(RESET); Mp3SoftReset(); Delay(100); while(GPIO_ReadInputDataBit(DREQ_PORT,DREQ_PIN) == 0); Mp3WriteRegister(SPI_MODE,0x08,0x00); Mp3WriteRegister(SPI_CLOCKF,0x98,0x00); Mp3WriteRegister(SPI_AUDATA,0xAC,0x45); Mp3WriteRegister(SPI_BASS,0x08,0x00); Mp3WriteRegister(SPI_VOL,0x0B,0x0B); Mp3WriteRegister(SPI_STATUS,0,0b00110011); while(GPIO_ReadInputDataBit(DREQ_PORT,DREQ_PIN) == 0); }
/******************************************************************************* * Function Name : VsSineTest * Description : VS1003 sine test * Input : None. * Output : None * Return : None *******************************************************************************/ void VsSineTest(void) { Mp3PutInReset(); //xReset = 0 ��Νvs1003 Mp3Reset(); Delay(1000);//wait(100); //��ʹ100ms SPIPutChar(0xff);//����ҝ���ֽھ���Ч���ݣ�����SPI���� SCI_ChipSelect(RESET); SDI_ChipSelect(RESET); Mp3ReleaseFromReset(); Mp3Reset(); Delay(500);//wait(100); Mp3SetVolume(50,50);//�������� Mp3WriteRegister(SPI_MODE,0x08,0x60);//����vs1003�IJ���ģʽ Delay(500); while(DREQ); //�ȴ�DREQΪ�� SDI_ChipSelect(SET); //xDCS = 1��ѥ��vs1003�����ݽӿ� //��vs1003�������Ҳ������0x53 0xef 0x6e n 0x00 0x00 0x00 0x00 //����n = 0x24, �蜨vs1003�����������Ҳ���ƾ��־��������㡽����vs1003��datasheet SPIPutChar(0x53); SPIPutChar(0xef); SPIPutChar(0x6e); SPIPutChar(0x24); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); Delay(1000); SDI_ChipSelect(RESET);//����ִ�о������ӌ���ܴӜ�������ҝ����ҝƾ�ʾ����� //�˳����Ҳ��� SDI_ChipSelect(SET); SPIPutChar(0x45); SPIPutChar(0x78); SPIPutChar(0x69); SPIPutChar(0x74); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); Delay(1000); SDI_ChipSelect(RESET); //�ٴν������Ҳ��Բ�����n־Ϊ0x44���������Ҳ���ƾ������Ϊ�����־ SDI_ChipSelect(SET); SPIPutChar(0x53); SPIPutChar(0xef); SPIPutChar(0x6e); SPIPutChar(0x44); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); Delay(1000); SDI_ChipSelect(RESET); //�˳����Ҳ��� SDI_ChipSelect(SET); SPIPutChar(0x45); SPIPutChar(0x78); SPIPutChar(0x69); SPIPutChar(0x74); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); SPIPutChar(0x00); Delay(1000); SDI_ChipSelect(RESET); }
//Inits everything uint8_t SFEMP3Shield::begin(){ pinMode(MP3_DREQ, INPUT); pinMode(MP3_XCS, OUTPUT); pinMode(MP3_XDCS, OUTPUT); pinMode(MP3_RESET, OUTPUT); digitalWrite(MP3_XCS, HIGH); //Deselect Control digitalWrite(MP3_XDCS, HIGH); //Deselect Data digitalWrite(MP3_RESET, LOW); //Put VS1053 into hardware reset //Setup SD card interface //Pin 10 must be set as an output for the SD communication to work. //pinMode(10, OUTPUT); //pinMode(53, OUTPUT); //Initialize the SD card and configure the I/O pins. if (!card.init(SPI_FULL_SPEED, SD_SEL)) return 1; // Serial.println("Error: Card init"); //Initialize a volume on the SD card. if (!volume.init(&card)) return 2; //Serial.println("Error: Volume ini"); //Open the root directory in the volume. if (!root.openRoot(&volume)) return 3; //Serial.println("Error: Opening root"); //Open the root directory in the volume. //We have no need to setup SPI for VS1053 because this has already been done by the SDfatlib //From page 12 of datasheet, max SCI reads are CLKI/7. Input clock is 12.288MHz. //Internal clock multiplier is 1.0x after power up. //Therefore, max SPI speed is 1.75MHz. We will use 1MHz to be safe. SPI.setClockDivider(SPI_CLOCK_DIV16); //Set SPI bus speed to 1MHz (16MHz / 16 = 1MHz) SPI.transfer(0xFF); //Throw a dummy byte at the bus //Initialize VS1053 chip delay(10); digitalWrite(MP3_RESET, HIGH); //Bring up VS1053 SFEMP3Shield::SetVolume(40, 40); VolL = 40; VolR = 40; //Let's check the status of the VS1053 int MP3Mode = Mp3ReadRegister(SCI_MODE); //int MP3Clock = Mp3ReadRegister(SCI_CLOCKF); /* Serial.print("SCI_Mode (0x4800) = 0x"); Serial.println(MP3Mode, HEX); Serial.print("SCI_Status (0x48) = 0x"); Serial.println(MP3Status, HEX); Serial.print("SCI_ClockF = 0x"); Serial.println(MP3Clock, HEX); */ if(MP3Mode != 0x4800) return 4; //Now that we have the VS1053 up and running, increase the internal clock multiplier and up our SPI rate Mp3WriteRegister(SCI_CLOCKF, 0x60, 0x00); //Set multiplier to 3.0x //From page 12 of datasheet, max SCI reads are CLKI/7. Input clock is 12.288MHz. //Internal clock multiplier is now 3x. //Therefore, max SPI speed is 5MHz. 4MHz will be safe. SPI.setClockDivider(SPI_CLOCK_DIV4); //Set SPI bus speed to 4MHz (16MHz / 4 = 4MHz) //test reading after data rate change int MP3Clock = Mp3ReadRegister(SCI_CLOCKF); if(MP3Clock != 0x6000) return 5; return 0; }