⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 vs1003.c

📁 Read MP3 from sd,send vs1003 decode
💻 C
📖 第 1 页 / 共 3 页
字号:
**         
** Used global variables:	VS_READ_COMMAND
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void VS1003_Read(uint8 Address,int Count,unsigned int *pData) 
{ 
	uint8 read_data;
	MP3_XCS_Select();       // XCS Low 
	Write_Byte_SPI(VS_READ_COMMAND); 
	Write_Byte_SPI(Address); 
	while(Count--) 
      		{ 
//      			*pData = (uint32)Write_Byte_SPI(0) << 8; 
//      			*pData++ |= (uint32)Write_Byte_SPI(0);
					read_data = Read_Byte_SPI();
					*pData = read_data << 8;
					read_data = Read_Byte_SPI();
					*pData++ |= read_data;
      		} 
	MP3_XCS_Deselect();       // XCS High 
	ms_wait(5); 
} 


/*********************************************************************************************************
** Function name:		Mp3SoftReset
**
** Descriptions:		reset vs1003 using soft method
**
** input parameters:		none
** Returned value:		none
**         
** Used global variables:	SPI_MODE,SPI_CLOCKF
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

void Mp3SoftReset(){                                                            
                                                                                 
   /* Soft Reset of VS10xx */                                                    
   Mp3WriteRegister (SPI_MODE, 0x08, 0x04); /* Newmode, Reset, No L1-2 */        
                                                                                 
   ms_wait(1); /* One millisecond delay */                                         
   while (!MP3_DATA_REQ_STATUS()) /* wait for startup */                                      
     ;                                                                           
                                                                                 
   /* Set clock register, doubler etc. */                                        
 #ifdef VS1003                                                                   
   Mp3WriteRegister(SPI_CLOCKF, 0xa6, 0x96);                                     
 #else                                                                           
   Mp3WriteRegister(SPI_CLOCKF, 156, 204);                                       
 #endif                                                                          
                                                                                 
   ms_wait(1); /* One millisecond delay */                                         
                                                                                 
                                                                                 
   /* Send null bytes to data interface */                                       
   MP3_XDCS_Select();                                                              
   SPIPutCharWithoutWaiting(0);                                                  
   SPIPutChar(0);                                                                
   SPIPutChar(0);                                                                
   SPIPutChar(0);                                                                
   SPIWait();                                                                    
   MP3_XDCS_Deselect();                                                            
                                                                                 
 }       

/*********************************************************************************************************
** Function name:		Mp3Reset
**
** Descriptions:		reset vs1003 using soft method
**
** input parameters:		none
** Returned value:		none
**         
** Used global variables:	SPI_AUDATA,SPI_CLOCKF
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

 void Mp3Reset()
 {                                                                
                                                                                 
   	Mp3PutInReset();                                                              
   	ms_wait(1);                                                                     
                                                                                 
   	/* Send dummy SPI byte to initialize SPI */                                   
   	SPIPutCharWithoutWaiting(0xFF);                                               
                                                                                 
   	/* Un-reset MP3 chip */                                                       
   	MP3_XCS_Select();                                                         
  	MP3_XDCS_Deselect();                                                            
  	Mp3ReleaseFromReset();                                                        
   	Mp3SetVolume(0xff, 0xff);                                                      
                                                                                 
   	/* Set clock register, doubler etc. */                                        
 	#ifdef VS1003  
	
   	Mp3WriteRegister(SPI_CLOCKF, 0xa6, 0x6c);   
	
 	#else                                                                           
   	Mp3WriteRegister(SPI_CLOCKF, 156, 204);                                       
 	#endif                                                                          
                                                                                 
   	/* Wait for DREQ */                                                           
   	while (!MP3_DATA_REQ_STATUS())                                                             
     	;                                                                           
                                                                                 
  	 /* Slow sample rate for slow analog part startup */                           
   	Mp3WriteRegister(SPI_AUDATA, 0, 10); /* 10 Hz */                              
   	ms_wait(100);                                                                   
                                                                                 
   	/* Switch on the analog parts */                                              
   	Mp3SetVolume(0xfe,0xfe);                                                      
   	Mp3WriteRegister (SPI_AUDATA, 31, 64); /* 8kHz */                             
   	Mp3SetVolume(20,20);                                                          
   	Mp3SoftReset();       
   
  	LPC2210SPI_CLK(64);		//	TO Set Fasting Clock of SPI
                                                                                 
   Uart_Printf ("Init: VS10XX\r");                                              
                                                                                 
 }       

/*********************************************************************************************************
** Function name:		VsSineTest
**
** Descriptions:		To test the sine funcion of vs1003 
**
** input parameters:		none
** Returned value:		none
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

void VsSineTest()
{                                                              
                                                                                 
   	/* Reset MP3 chip */                                                          
   	Mp3PutInReset();       /* Pull xRESET low -> hardware reset */                
   	ms_wait(100);            /* 100 ms delay */                                     
                                                                                 
   	/* Send dummy SPI byte to initialize SPI of Atmel microcontroller */          
   	SPIPutCharWithoutWaiting(0xFF);                                               
                                                                                 
   	/* Un-reset MP3 chip */                                                       
   	MP3_XCS_Deselect();  /* Pull xCS high    */                                 
   	MP3_XDCS_Deselect();     /* Pull xDCS high   */                                 
   	Mp3ReleaseFromReset(); /* Pull xRESET high */                                 
   	ms_wait(100);            /* 100 ms delay     */                                 
                                                                                 
	LEDStatu(LEDCON);
	
   	/* VS10xx Application Notes, chapter 4.8 ---------------------------------*/  
   	/* As an example, let's write value 0x0820 to register 00 byte by byte    */  
   	MP3_XCS_Select();    /* Now SPI writes go to SCI port                   */  
   	SPIPutChar(0x02);      /* Send SPI Byte, then wait for byte to be sent.   */  
   	SPIPutChar(0x00);      /* 0x02 was WRITE command, 0x00 is register number */  
   	SPIPutChar(0x08);      /* This byte goes to MSB                           */  
   	SPIPutChar(0x20);      /* ..and this is LSB. (0x20=Allow Test Mode)       */  
   	SPIWait();             /* Wait until Atmel MCU signals SPI write complete */  
   	MP3_XCS_Deselect();  /* Now SPI writes don't go to SCI port             */  
                                                                                 
   	while (!MP3_DATA_REQ_STATUS())      /* Wait for DREQ = 1                               */  
     	;                    /* Do nothing while waiting for DREQ = 1           */  
                                                                                 
   	/* Send a Sine Test Header to Data port                                   */  
   	MP3_XDCS_Select();       /* Now SPI writes go to SDI port                   */  
                                                                                 
   	SPIPutChar(0x53);      /* - This is a special VLSI Solution test header - */  
   	SPIPutChar(0xef);      /* - that starts a sine sound. It's good for     - */  
   	SPIPutChar(0x6e);      /* - testing your code, the chip and also for    - */  
   	SPIPutChar(0x44);      /* - seeing if your MP3 decoder was manufactured - */  
   	SPIPutChar(0x00);      /* - by VLSI Solution oy. ------------------------ */  
   	SPIPutChar(0x00);                                                             
   	SPIPutChar(0x00);                                                             
   	SPIPutChar(0x00);                                                             
   	SPIWait();                                                                    
   	MP3_XDCS_Deselect();                                                            
                                                                                 
   	ms_wait(500);           /* 500 ms delay */        
	LEDStatu(LEDOFF);
                                                                                 
   	/* Stop the sine test sound */                                                
   	MP3_XDCS_Select();                                                              
   	SPIPutChar(0x45);                                                             
   	SPIPutChar(0x78);                                                             
   	SPIPutChar(0x69);                                                             
   	SPIPutChar(0x74);                                                             
   	SPIPutChar(0x00);                                                             
   	SPIPutChar(0x00);                                                             
   	SPIPutChar(0x00);                                                             
   	SPIPutChar(0x00);                                                             
   	SPIWait();                                                                    
   	MP3_XDCS_Deselect();                                                            
                                                                                 
   	ms_wait(500);            /* 500 ms delay */                                     
 }    

/*********************************************************************************************************
** Function name:		SendZerosToVS10xx
**
** Descriptions:		send zeros to vs1003 
**
** input parameters:		none
** Returned value:		none
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/

 void SendZerosToVS10xx(int numzero)
{                                                       
	int i;
	MP3_XDCS_Select();                                                              
   	SPIPutCharWithoutWaiting(0);                                                  
   	for (i=0; i<numzero; i++)
		{ /* TESTING 1048 TESTING */             
    			while (!MP3_DATA_REQ_STATUS())                                                           
       			;                                                                         
     			SPIPutChar(0);                                                              
   		}                                                                             
   	SPIWait();                                                                    
  	MP3_XDCS_Deselect();                            
}     
/*********************************************************************************************************
** Function name:		VS1003_Stream
**
** Descriptions:		continue to write data  from address
**
** input parameters:		Qte,*Data
** Returned value:		
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void VS1003_Stream(uint8 *Data,uint8 Qte) 
{ 
  	MP3_XDCS_Select();		// BSYNC Low 
	while((Qte --) > 0) 
		{
  			Write_Byte_SPI(*Data++); 
		}
  	MP3_XDCS_Deselect();       // BSYNC High 
} 
void VS1003_nulls(int nNulls)
{
	while(nNulls--)
		{
			vs1003_data_write(0);
		}
}


 /*********************************************************************************************************
** Function name:		VS1003_SetVolume
**
** Descriptions:		Set vs Volume
**
** input parameters:		Left, Right
** Returned value:		none
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void VS1003_SetVolume(uint8 Left, uint8 Right) 
{ 
	unsigned int buf[2]; 

	buf[0] = (((unsigned int)Left) << 8) | ((unsigned int)Right); 
	VS1003_Write(SPI_VOL, 1, buf); 
} 
                                                            
void Mp3SetVolume(uint8 leftchannel, uint8 rightchannel)
{            
	Mp3WriteRegister(SPI_VOL, (leftchannel), (rightchannel));
}        



/*********************************************************************************************************
** Function name:		Working_Test
**
** Descriptions:		test volume
**
** input parameters:		none
** Returned value:		none
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Working_Test(void) 
{ 
	unsigned int i; 
	for(i=0;i<10;i++) 
		{ 
  			while(!MP3_DATA_REQ_STATUS());         // wait for DREQ 
  			VS1003_SetVolume(0,0); 
  			ms_wait(500); 
			
  			while(!MP3_DATA_REQ_STATUS());         // wait for DREQ 
  			VS1003_SetVolume(255,255); 
  			ms_wait(500); 
		} 
} 

/*********************************************************************************************************
** Function name:		Reg_Test
**
** Descriptions:		vs clock register test
**
** input parameters:		none
** Returned value:		none
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
uint8 Reg_Test() 
{ 
	unsigned int buf; 
	unsigned int j; 

	for (j=0;j<20;j++) 
  		{ 
  			buf = j*256+j; 
    			while(!MP3_DATA_REQ_STATUS());         // wait for DREQ 
  			VS1003_Write(SPI_CLOCKF, 1, &buf); 
			
  			buf = 0xffff; 
  			VS1003_Read(SPI_CLOCKF,1,&buf); 
  			if (buf != j*256+j) 
				{
					return j; 
  				}
  		} 
	return 0; 
} 


/*********************************************************************************************************
** Function name:		Sine_On
**
** Descriptions:		vs sine test
**
** input parameters:		freq
** Returned value:		none
**         
** Used global variables:	none
** Calling modules:		None
**
** Created by:			JOSEPH
** Created Date:		2006/10/19
**-------------------------------------------------------------------------------------------------------
** Modified by:
** Modified date:
**------------------------------------------------------------------------------------------------------
********************************************************************************************************/
void Sine_On(unsigned int freq) 
{ 
	uint8 buf[4]; 

	buf[0] = 0x53; 
	buf[1] = 0xef; 
	buf[2] = 0x6e; 
	buf[3] = ((freq * 128) / 44100) & 0x1f; 
	while(!(MP3_DATA_REQ_STATUS()));         // wait for DREQ 
	VS1003_Stream(&buf[0],4); 

	buf[0] = 0x00; 
	buf[1] = 0x00; 
	buf[2] = 0x00; 
	buf[3] = 0x00; 
	while(!MP3_DATA_REQ_STATUS());         // wait for DREQ 
	VS1003_Stream(&buf[0],4); 
} 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -