正在用i2s 外设,发现很纠结的问题,
设备配置为master模式, 在stm32f4上都可以,但是跑到stm32f2上就不行了,
我是这样配置的。
GPIO:
/*Enable or disable the AHB1 peripheral clock */
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC | RCC_AHB1Periph_GPIOA | RCC_AHB1Periph_GPIOB, ENABLE);
/*Configure GPIO pin : PC */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOC, &GPIO_InitStruct);
/*Configure GPIO pin : PA */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
/*Configure GPIO pin : PB */
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_5;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
/*Configure GPIO pin alternate function */
GPIO_PinAFConfig(GPIOC, GPIO_PinSource7, GPIO_AF_SPI3);
/*Configure GPIO pin alternate function */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource15, GPIO_AF_SPI3);
/*Configure GPIO pin alternate function */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource3, GPIO_AF_SPI3);
/*Configure GPIO pin alternate function */
GPIO_PinAFConfig(GPIOB, GPIO_PinSource5, GPIO_AF_SPI3);
外设部分:
/* Enable the CODEC_I2S peripheral clock */
RCC_APB1PeriphClockCmd(CODEC_I2S_CLK, ENABLE);
I2S_Cmd(CODEC_I2S, DISABLE);
/* CODEC_I2S peripheral configuration */
SPI_I2S_DeInit(CODEC_I2S);
I2S_InitStructure.I2S_AudioFreq = 48000;
I2S_InitStructure.I2S_Standard = 0x00;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
I2S_Init(CODEC_I2S, &I2S_InitStructure);
SPI_I2S_ITConfig(SPI3, SPI_I2S_IT_TXE, ENABLE);
I2S_Cmd(SPI3, ENABLE);
中断部分
NVIC_InitStructure.NVIC_IRQChannel = SPI3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
void SPI3_IRQHandler(void)
{
/* Check on the I2S TXE flag */
if (SPI_I2S_GetFlagStatus(SPI3, SPI_I2S_FLAG_TXE) != RESET)
{
/* Send dummy data on I2S to avoid the underrun condition */
SPI_I2S_SendData(CODEC_I2S, EVAL_AUDIO_GetSampleCallBack());
}
}
现在用SPI_I2S_SendData();发数据,居然没有任何输出,请熟悉的朋友帮看一下。
|