Пример #1
0
/*******************************************************************************
* 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���������å�

}
Пример #2
0
	SPI_Cmd(SPI1, ENABLE); // enable SPI1

//  SPI_SSOutputCmd(SPI1, ENABLE);

  /* Enable SPI1 */
  SPI_Cmd(SPI1, ENABLE);


//  GPIOB->BSRRL|=GPIO_BSRR_BR_3; /////w�acznie uk��du

}

uint16_t VS1003_GetBitrate(void)
{
	uint16_t bitrate = (Mp3ReadRegister(SPI_HDAT0) & 0b1111000000000000) >> 12;
	uint8_t ID = (Mp3ReadRegister(SPI_HDAT1) & 0b0000000000011000) >> 3;
	uint16_t res;
	if (ID == 3)
	{	res = 32;
		while(bitrate>13)
		{
			res+=64;
			bitrate--;
		}
		while (bitrate>9)
		{
			res+=32;
			bitrate--;
		}
		while (bitrate>5)
//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;
}