|
VS1003的DREQ为什么一直是低的,正弦测试正常,MP3测试时DREQ一直是低的,初始化通过,播放测试数据时DREQ一直低
uchar buffer [512];
void VS1003B_PortInit(void)
{
VS1003B_RST_PORT |= BIT(VS1003B_RST);
VS1003B_DREQ_PORT |= BIT(VS1003B_DREQ);
VS1003B_XDCS_PORT |= BIT(VS1003B_XDCS);
VS1003B_XCS_PORT |= BIT(VS1003B_XCS);
VS1003B_DREQ_DDR &= ~BIT(VS1003B_DREQ);
DDRD |= BIT(VS1003B_XCS);
DDRD |= BIT(VS1003B_XDCS);
DDRE |= BIT(VS1003B_RST);
}
/****************************************************************************
* 名称:void VS1003B_WriteCMD(uint8 addr, uint16 data)
* 功能:向VS1003写16位命令
* 入口参数:无
* 出口参数:无
****************************************************************************/
void VS1003B_WriteCMD(uchar addr,uint dat)
{
SPI_LOW();
VS1003B_XDCS_H();
VS1003B_XCS_L();
Write_Byte_SPI(0x02);
Write_Byte_SPI(addr);
Write_Byte_SPI(dat>>8);
Write_Byte_SPI(dat);
VS1003B_XCS_H();
SPI_HIGH();
}
/****************************************************************************
* 名称:void VS1003B_ReadCMD(uint8 addr)
* 功能:读寄存器,参数 地址 返回内容
* 入口参数:无
* 出口参数:无
****************************************************************************/
uint VS1003B_ReadCMD(uchar addr)
{
uint temp;
SPI_LOW();
VS1003B_XDCS_H();
VS1003B_XCS_L();
Write_Byte_SPI(0x03);
Write_Byte_SPI(addr);
temp = Read_Byte_SPI();
temp <<= 8;
temp += Read_Byte_SPI();
VS1003B_XCS_H();
SPI_HIGH();
return temp;
}
/****************************************************************************
* 名称:void VS1003B_WriteDat(uhar dat)
* 功能:写数据
* 入口参数:无
* 出口参数:无
****************************************************************************/
void VS1003B_WriteDat(uchar dat)
{
SPI_HIGH();
VS1003B_XDCS_L();
VS1003B_XCS_L();
Write_Byte_SPI(dat);
VS1003B_XCS_H();
}
/****************************************************************************
* 名称:void VS1003B_SoftReset(void)
* 功能:软件初始化
* 入口参数:无
* 出口参数:无
****************************************************************************/
void VS1003B_SoftReset(void)
{
SPI_HIGH();
VS1003B_WriteCMD(0x00,0x0804); /* reset */
delayms(200);
}
/****************************************************************************
* 名称:uchar VS1003B_Init(void)
* 功能:功能初始化
* 入口参数:无
* 出口参数:成功否
****************************************************************************/
uchar VS1003B_Init(void)
{
VS1003B_PortInit();
SPI_LOW();
VS1003B_XCS_L();
VS1003B_XDCS_H();
VS1003B_RST_L();
delayms(100);
VS1003B_RST_H(); //使能芯片
delayms(100);
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteCMD(0x0,0x0804);
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteCMD(0x2,0x7a00); //内置低音/高音增强
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteCMD(0x3,0x9800); //4.5倍频率
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteCMD(0x5,0xbb81);
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteCMD(0xb,0x0000); //音量最大
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
SPI_HIGH();//提高速度,全速运行
return 1;
}
/**************************************************************************************************
**Name: VS1003B_Test(void)
**Function:test
**Input:
**Output:
**************************************************************************************************/
void VS1003B_Test()
{
VS1003B_RST_L();
delayms(1);
VS1003B_RST_H(); //硬件复位
VS1003B_SoftReset(); //软件复位
Write_Byte_SPI(0xff); //发送一个字节的无效数据,启动SPI传输
VS1003B_XCS_L();
VS1003B_XDCS_H();
VS1003B_RST_H();
VS1003B_WriteCMD(0x00,0x0820); //enter vs1003 test model
while( (PINE & BIT(VS1003B_DREQ) ) == 0); //wait for DREQ Highlevel
//向vs1003发送正弦测试命令:0x53 0xef 0x6e n 0x00 0x00 0x00 0x00
//其中n = 0x24, 设定vs1003所产生的正弦波的频率值,具体计算方法见vs1003的datasheet
VS1003B_WriteDat(0x53);
VS1003B_WriteDat(0xef);
VS1003B_WriteDat(0x6e);
VS1003B_WriteDat(0X24);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
delayms(2000);//程序执行到这里后应该能从耳机听到一个单一频率的声音
//退出正弦测试
VS1003B_WriteDat(0x45);
VS1003B_WriteDat(0x78);
VS1003B_WriteDat(0x69);
VS1003B_WriteDat(0x74);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteCMD(0x00,0x0820); //enter vs1003 test model
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteDat(0x53);
VS1003B_WriteDat(0xef);
VS1003B_WriteDat(0x6e);
VS1003B_WriteDat(0X74);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
delayms(2000);//程序执行到这里后应该能从耳机听到一个单一频率的声音
//退出正弦测试
VS1003B_WriteDat(0x45);
VS1003B_WriteDat(0x78);
VS1003B_WriteDat(0x69);
VS1003B_WriteDat(0x74);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteCMD(0x00,0x0820); //enter vs1003 test model
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteDat(0x53);
VS1003B_WriteDat(0xef);
VS1003B_WriteDat(0x6e);
VS1003B_WriteDat(0X44);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
delayms(2000);//程序执行到这里后应该能从耳机听到一个单一频率的声音
//退出正弦测试
VS1003B_WriteDat(0x45);
VS1003B_WriteDat(0x78);
VS1003B_WriteDat(0x69);
VS1003B_WriteDat(0x74);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteCMD(0x00,0x0820); //enter vs1003 test model
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
VS1003B_WriteDat(0x53);
VS1003B_WriteDat(0xef);
VS1003B_WriteDat(0x6e);
VS1003B_WriteDat(0X74);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
delayms(2000);//程序执行到这里后应该能从耳机听到一个单一频率的声音
//退出正弦测试
VS1003B_WriteDat(0x45);
VS1003B_WriteDat(0x78);
VS1003B_WriteDat(0x69);
VS1003B_WriteDat(0x74);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_WriteDat(0x00);
VS1003B_XDCS_H();
}
void MP3_TEST()
{
ulong i = 0;
uchar n = 0;
uint count = 0;
VS1003B_Init();
//VS1003B_Test();
//FAT32_ReadSector(7673+i,buffer);
//SD_write_sector(15714+i,buffer);
while(count < 4800)
{
while( (PINE & BIT(VS1003B_DREQ) ) == 0);
// {
for(n=0;n<32;n++)
{
VS1003B_WriteDat(vsBeepMP3[count]);
count++;
}
// }
}
} |
阿莫论坛20周年了!感谢大家的支持与爱护!!
曾经有一段真挚的爱情摆在我的面前,我没有珍惜,现在想起来,还好我没有珍惜……
|