测试一下使用VS1053播放MP3的效果
1. 1. 使用自带的SD_Card例程,把MP3文件写在sd卡上
2.2. 增加vs1053驱动
3.3. 编写相关的应用程序
系统的理解效果图如下:
测试的效果还是不错的,只要不连错线,美妙的音乐你是可以听到的,到这里网络收音机底层的硬件基本上就这样了,网络和VS1053都可以正常工作,下一步的工作重点是网络!
代码流程:
主程序流程
-
Int main(void) /*power_on() spi速率3Mbps */
{
int nStatus;
USHORT i,k,temp;
FRESULT fresult;
/////////////////////////////////
FIL fsrc, fdst; // file objects
UCHAR buffer[512]={0};
FRESULT res; // FatFs function common result code
UINT br, bw,file_size=881664;; // File R/W count
// Set the system clock to run at 8 MHz from the main oscillator.
//
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL |
SYSCTL_XTAL_8MHZ | SYSCTL_OSC_MAIN);
//
// Enable the peripherals used by this example.
//
SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
//
// Configure SysTick for a 100Hz interrupt. The FatFs driver
// wants a 10 ms tick.
//
SysTickPeriodSet(SysCtlClockGet() / 100);
SysTickEnable();
SysTickIntEnable();
/*VS1053初始化 */
vs1053_io_init();
vs1053_softreset();
//
// Enable Interrupts
//
IntMasterEnable();
//
// Set GPIO A0 and A1 as UART.
//
GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
//
// Initialize the UART as a console for text I/O.
//
UARTStdioInit(0);
//
// Print hello message to user.
//
UARTprintf("\n\nSD Card Example Program\n");
UARTprintf("Type \'help\' for help.\n");
//
// Mount the file system, using logical disk 0.
//
fresult = f_mount(0, &g_sFatFs);
if(fresult != FR_OK)
{
UARTprintf("f_mount error: %s\n", StringFromFresult(fresult));
return(1);
}
while(1)
{
play2("test3.wma"); //播放MP3等音频文件
}
}
复制代码
播放函数:
-
void play2(char *wavFile)
{
UINT num_size;
USHORT i,endFillByte;
USHORT k;
FIL file;
FRESULT res;
UCHAR Buffer[32]={0};
UINT br;
disk_initialize (0);
res = f_open(&file, (const char *)wavFile, FA_OPEN_EXISTING|FA_READ);
if(res)
{
UARTprintf("Openning wav_file failed!\n");
while(1);
}
else
{
UARTprintf("Openning wav_file succeed!\n");
}
if (res == FR_OK)
{
UARTprintf("Openning wav_file succeed,and playing the music!\n");
num_size = file.fsize;
while(num_size>31)
{
if(f_read(&file, Buffer, 32, (WORD *)&br)==0)
{
while(VS_DREQ_READ()==0);
VS_DCn_LOW();
VS_CSn_HIGH();
for(k=0;k<br;k++)
{
_ssi_readwrite(Buffer[k]);
}
VS_DCn_HIGH();
VS_CSn_LOW();
}
num_size = num_size - 32;
}
if(num_size)
{
while(VS_DREQ_READ()==0);
VS_DCn_LOW();
VS_CSn_HIGH();
for(k=0;k<num_size;k++)
{
_ssi_readwrite(0);
}
VS_DCn_HIGH();
VS_CSn_LOW();
}
}
f_close(&file);
vs1053_io_init();
vs1053_softreset();
disk_initialize (0);
}
复制代码
代码下载:
SD_VS1053.rar
(470.5 KB, 下载次数: 122)