|
在 章其波 的程序上做了修改, 只是想测试一下VS1003是否能正常工作. 使用的是M32
初始化成功, 但正弦测试不发音
初始化代码如下:
unsigned char VS1003B_Init()
{
unsigned char retry;
PORT_INI(); /* Prot Initialize */
VS1003B_XRESET_L(); /* A hardware reset */
_delay_ms(20);
VS1003B_XRESET_H();
VS1003B_SPI_Low(); /* Low initialize spi clock */
_delay_ms(20);
retry=0;
while(VS1003B_ReadCMD(0x03) != CLOCK_REG) /* set PLL register */
{
VS1003B_WriteCMD(0x03,CLOCK_REG);
if(retry++ >10 )return 1;
}
_delay_ms(20);
VS1003B_WriteCMD(0x05,0x000a);
retry=0;
while(VS1003B_ReadCMD(0x0b) != 0xfefe) /* set Volume to minimum */
{
VS1003B_WriteCMD(0x0b,0xfefe);
if(retry++ >10 )return 1;
}
VS1003B_WriteCMD(0x05,0xac45); /* Soft start */
retry=0;
while(VS1003B_ReadCMD(0x0b) != DEFAULT_VOLUME) /* Set volume to default value */
{
VS1003B_WriteCMD(0x0b,DEFAULT_VOLUME);
if(retry++ >10 )return 1;
}
retry=0;
while(VS1003B_ReadCMD(0x00) != 0x0800) /* set mode register */
{
VS1003B_WriteCMD(0x00,0x0800);
if(retry++ >10 )return 1;
}
_delay_ms(1);
retry=0;
while(VS1003B_ReadCMD(0x02) != DEFAULT_BASS_TREMBLE) /* set bass/tremble register */
{
VS1003B_WriteCMD(0x02,DEFAULT_BASS_TREMBLE);
if(retry++ >10 )return 1;
}
_delay_ms(20);
VS1003B_SoftReset(); /* A soft reset */
_delay_ms(20);
VS1003B_SPI_High(); /* High SPI clock, for internal pll has been works now */
return 0;
}
正弦测试代码如下:
void VS1003_Test(void)
{
//VS1003_HwRst();
VS1003B_SoftReset();
VS1003B_WriteByte(0xff);
VS1003B_XCS_H() ;
VS1003B_XDCS_H();
VS1003B_XRESET_H();
//delay100ms
VS1003B_WriteCMD(0x00 ,0x0820); //enter vs1003 test model
while ((VS1003B_DREQ_PIN & (1<<VS1003B_DREQ_BIT))== 0); //wait for DREQ Highlevel
VS1003B_WriteByte(0x53);
VS1003B_WriteByte(0xef);
VS1003B_WriteByte(0x6e);
VS1003B_WriteByte(0x7e);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
//程序执行到这里后应该能从耳机听到一个单一频率的声音
//退出正弦测试
VS1003B_WriteByte(0x45);
VS1003B_WriteByte(0x78);
VS1003B_WriteByte(0x69);
VS1003B_WriteByte(0x74);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003B_XDCS_H();
//再次进入正弦测试并设置n值为0x44,即将正弦波的频率设置为另外的值
VS1003B_WriteByte(0x53);
VS1003B_WriteByte(0xef);
VS1003B_WriteByte(0x6e);
VS1003B_WriteByte(0x44);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
//退出正弦测试
VS1003B_WriteByte(0x45);
VS1003B_WriteByte(0x78);
VS1003B_WriteByte(0x69);
VS1003B_WriteByte(0x74);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003B_WriteByte(0x00);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
VS1003_Delay_Nmicrosecond(50000);
}
一直听不到声音,请问这是怎么回事啊?
谢谢先 |
|