stm32f4的i2s设置
求stm32f4的i2s的初始化设置我这么弄得
void I2S_GPIO_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_SPI3);
GPIO_PinAFConfig(GPIOC, GPIO_PinSource12, GPIO_AF_SPI3);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7 | GPIO_Pin_10 | GPIO_Pin_12;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOC, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_PinAFConfig(GPIOA, GPIO_PinSource4, GPIO_AF_SPI3);
}
void Audio_I2S_Init(uint32_t AudioFreq)
{
I2S_InitTypeDef I2S_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE);
SPI_I2S_DeInit(SPI3);
I2S_InitStructure.I2S_AudioFreq = AudioFreq;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
I2S_InitStructure.I2S_MCLKOutput =I2S_MCLKOutput_Enable;
I2S_Init(SPI3,&I2S_InitStructure);
I2S_Cmd(SPI3, ENABLE);
}
int main ()
{
I2S_GPIO_Init();
Audio_I2S_Init(8000);
while(1)
{
while((SPI3->SR&SPI_I2S_FLAG_TXE)==RESET);
SPI3->DR =0;
while((SPI3->SR&SPI_I2S_FLAG_TXE)==RESET);
SPI3->DR =0;
while((SPI3->SR&SPI_I2S_FLAG_TXE)==RESET);
SPI3->DR =0xffff;
while((SPI3->SR&SPI_I2S_FLAG_TXE)==RESET);
SPI3->DR =0xffff;
}
}
程序就卡在主函数里的第二个while那里,应该是初始化问题吧
可能是IIC器件没反映 阿南 发表于 2013-4-22 09:30 static/image/common/back.gif
可能是IIC器件没反映
是iis,从器件是不用反应的 回楼主,应该是你的iis时钟没有打开
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
RCC_PLLI2SCmd(ENABLE);
RCC_GetFlagStatus(RCC_FLAG_PLLI2SRDY);
写上这个看看 1020165558 发表于 2013-4-22 19:02 static/image/common/back.gif
回楼主,应该是你的iis时钟没有打开
RCC_I2SCLKConfig(RCC_I2S2CLKSource_PLLI2S);
RCC_PLLI2SCmd(ENABLE ...
多谢了啊,终于好了 哦不了意思看错了
页:
[1]