各位路过的,有谁用过PCM1770这颗DA芯片,我在使用时,好像不能对它进行配置。贴出源码,帮看看。用示波器量过波形,都是符合芯片手册描述的。正好几天了,是在搞不懂。
void PCM1770Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
//使能控制信号的时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_14 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
//硬件复位一下
PCM_PD_SET_L;
Delay(900);//
PCM_PD_SET_H;
Delay(900); //
PCM_CS_SET_H ;
PCM_CLK_SET_H;
PCM_DAT_SET_H;
s_Volume = C_VOLUME_MAX/2;
PCM_WriteData(0x01, 0xc0);//0xc0);//左右耳机静音 ,左耳机音量设为中间大小
PCM_WriteData(0x02, 0x00);//0x00);//右耳机音量设为中间大小
PCM_WriteData(0x03, 0x84);//256fs IIS格式 stm32的iis mclk规定为256fs ( 84= 16 right)
PCM_WriteData(0x04, 0x00);//
}
/**
* @brief
* @param Reg Index, Data
* @retval None
*/
void PCM_WriteData(const u8 Reg, const u8 Data)
{
vu16 TrasferData, i;
TrasferData = Data;
TrasferData |= (Reg<<8)&0xff00;
printf(" data is %x \n",TrasferData);
PCM_CS_SET_L;//select
Delay(10);
for (i = 0; i < 16; i++)
{//传输时MSB first
PCM_CLK_SET_L;
if (TrasferData&(0x8000>>i))
{
PCM_DAT_SET_H;
}
else
{
PCM_DAT_SET_L;
}
Delay(10);//等数据稳定
PCM_CLK_SET_H; //上升沿写入
Delay(10);//等待从机读数据
}
PCM_CLK_SET_H;
PCM_DAT_SET_H;
PCM_CS_SET_H;//relase
Delay(20);
} |