本帖最后由 492072866 于 2015-1-8 13:51 编辑
代码如下,那位大神帮看看问题在哪?目测是spi的问题
void SPI_send(uint8_t data) //spi发送函数
{
SPI1->TX[0] = data;
SPI1->CNTRL.GO_BUSY = 1;
while ( SPI1->CNTRL.GO_BUSY == 1 ); //check data out?
}
void SPI_read(uint8_t data) //spi接受函数
{
data=SPI1->RX[0];
SPI1->CNTRL.GO_BUSY = 1;
while ( SPI1->CNTRL.GO_BUSY == 1 ); //check data out?
}
int DREQ() //获取DREQ引脚
{
int sssp;
sssp=DrvGPIO_GetBit(E_GPA, 1);
return sssp;
}
void SPI_init(void) //spi初始化
{
DrvGPIO_InitFunction(E_FUNC_SPI1);
DrvSPI_Open(eDRVSPI_PORT1,eDRVSPI_MASTER,eDRVSPI_TYPE1,8);
DrvSPI_SetBitLength(eDRVSPI_PORT1,8);
DrvSPI_SetEndian(eDRVSPI_PORT1, eDRVSPI_MSB_FIRST);
DrvSPI_DisableAutoSS(eDRVSPI_PORT1);
DrvSPI_SetSlaveSelectActiveLevel(eDRVSPI_PORT1, eDRVSPI_ACTIVE_LOW_FALLING);
DrvSPI_SetClockFreq(eDRVSPI_PORT1, 9000000, 0);
DrvGPIO_Open(E_GPE, VS_CS,E_IO_OUTPUT);
SPI_send(0xFF);
}
void VS1053_Reset() //vs1053硬复位
{
DrvGPIO_SetBit(E_GPE, VS_XCS);
DrvGPIO_SetBit(E_GPE, VS_CS);
DrvGPIO_ClrBit(E_GPE, 4);
DrvSYS_Delay(1000);
DrvGPIO_SetBit(E_GPE, 4);
while(DREQ()==0)
{;}
}
void VS1053_writeReg(uint8_t addr,uint16_t dat) //vs1053写指令
{DrvSPI_SetClockFreq(eDRVSPI_PORT1, 1125000, 0);
DrvGPIO_SetBit(E_GPE, VS_XCS);
DrvGPIO_ClrBit(E_GPE, VS_CS);
SPI_send(VS_WRITE_COM);
SPI_send(addr);
SPI_send((uint8_t)(dat>>8));
SPI_send((uint8_t)(dat));
DrvGPIO_SetBit(E_GPE, VS_CS);
DrvSPI_SetClockFreq(eDRVSPI_PORT1, 9000000, 0);
}
void VS1053_writeData(uint8_t dat) //向vs1053写数据
{
DrvGPIO_ClrBit(E_GPE, VS_XCS);
//DrvGPIO_SetBit(E_GPE, 3);
//DrvGPIO_ClrBit(E_GPC, 8);
//SPI_send(VS_WRITE_COM);
//SPI_send(VS_SCI_AUDATA);
SPI_send((uint8_t)(dat));
DrvGPIO_SetBit(E_GPE, VS_XCS);
}
void VS1053_SoltReset() //软件复位vs1053
{DrvSPI_SetClockFreq(eDRVSPI_PORT1, 281000, 0);
VS1053_writeReg(VS_SCI_MODE,0x0807);
while(DREQ()==0)
{;}
VS1053_writeReg(VS_SCI_CLOCKF,0x9800);
DrvSPI_SetClockFreq(eDRVSPI_PORT1, 9000000, 0);
DrvGPIO_ClrBit(E_GPE, VS_XCS);
SPI_send(0x0);
SPI_send(0x0);
SPI_send(0x0);
SPI_send(0x0);
DrvGPIO_SetBit(E_GPE, VS_XCS);
while(DREQ()==0)
{;}
}
void VS1053Init() //初始化vs1053
{
VS1053_Reset();
VS1053_SoltReset();
VS1053_writeReg(VS_SCI_MODE,0x0803);
VS1053_writeReg(VS_SCI_BASS,0x0055);
VS1053_writeReg(VS_SCI_CLOCKF,0x9800);
VS1053_Vol=0xCA;
VS1053_writeReg(VS_SCI_VOL,(VS1053_Vol<<8)|VS1053_Vol);
while(DREQ()==0)
{;}
}
uint16_t VS1053read(uint8_t addr) //读取vs1053寄存器
{
uint16_t tem;
while(DREQ()==0)
{;}
DrvSPI_SetClockFreq(eDRVSPI_PORT1, 1125000, 0);
DrvGPIO_SetBit(E_GPE, VS_XCS);
DrvGPIO_ClrBit(E_GPE, VS_CS);
SPI_send(VS_READ_COM);
SPI_send(addr);
SPI_read(tem);
tem=tem<<8;
SPI_read(tem);
DrvGPIO_SetBit(E_GPE, VS_CS);
DrvSPI_SetClockFreq(eDRVSPI_PORT1, 9000000, 0);
return tem;
}
void playmusic(uint8_t *mp3File) //播放音乐
{
uint16_t k;
int t;
FATFS fs;
BYTE MMcbuf[512];
FIL file;
UINT br;
FRESULT res;
f_mount(0,&fs); // 加载文件系统
res = f_open(&file,(const TCHAR *)mp3File, FA_OPEN_EXISTING|FA_READ); // 打开文件
if(res == FR_OK) // 如果没有正确打开文件
{
while(1)
{
res=f_read(&file,MMcbuf,512,&br);
k=0;
do
{
if(DREQ()==1&&res == FR_OK)
{
for(t=0;t<32;t++)
{VS1053_writeData(MMcbuf[k++]);}
}
if (ScanKey()!=0) keyhave();
}while(k<512);
if((res!= FR_OK)||(br<512)) break;
}
}
f_close(&file);
f_mount(0,0);
}
|
|