做一个项目,需要使用I2S3的主接收模式驱动TI的PCM1808,爬论坛爬了半天,没有找到对应的示例代码,求助帮忙看下哪里有问题。
调用过程代码如下:
I2S3_Init();
I2S3_DMA_Read(Buffer, 512);
delay_ms(10);
inc = 0;
while(1)
{
if(I2S3_DMA_Status())
{
printf("The %d th data:
", inc);
for(i = 0; i < 512; i++)
{
printf("%02x ", Buffer[i]);
if(i % 16 == 0 && (i > 0))
{
printf("
");
}
}
I2S3_DMA_Read(Buffer, 512);
inc++;
}
}
函数定义如下:
void I2S3_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
I2S_InitTypeDef I2S_InitStructure;
/* I2S3 GPIO Configuration
PA15 ------> I2S3_WS
PB3 ------> I2S3_CK
PB5 ------> I2S3_SD
PC7 ------> I2S3_MCLK
*/
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3, ENABLE); //SPI3??
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOC, ENABLE);
//I2S_Cmd(SPI3, DISABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE); //??JTAG????
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_15;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_3; //
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_5; //
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IN_FLOATING;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_7; // MCLK Output Mode.
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStruct);
SPI_I2S_DeInit(SPI3);
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterTx;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16bextended;
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable;
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_Init(SPI3, &I2S_InitStructure);
}
u8 I2S3_DMA_Status(void)
{
u8 status = 0;
if(DMA_GetFlagStatus(DMA2_FLAG_TC1)!=RESET) //ÅD¶Ïí¨μà4′«êäíê3é
{
DMA_ClearFlag(DMA2_FLAG_TC1);//Çå3yí¨μà4′«êäíê3é±êÖ¾
status = 1;
}
return status;
}
void I2S3_DMA_Read(u16 *buffer, u32 size)
{
DMA_InitTypeDef DMA_InitStructure;
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA2, ENABLE);
//SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Tx | SPI_I2S_DMAReq_Rx, DISABLE);
DMA_DeInit(DMA2_Channel1);
DMA_SetCurrDataCounter(DMA2_Channel1, 0);
DMA_ClearFlag(DMA2_FLAG_TC1 | DMA2_FLAG_TE1 | DMA2_FLAG_HT1 | DMA2_FLAG_GL1);//??DMA1 channel5??
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)(&SPI3->DR);
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)buffer;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = size;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord;
DMA_InitStructure.DMA_Mode = DMA_Mode_Circular;
DMA_InitStructure.DMA_Priority = DMA_Priority_High;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMA2_Channel1, &DMA_InitStructure);
DMA_Cmd(DMA2_Channel1, ENABLE);
SPI_I2S_DMACmd(SPI3, SPI_I2S_DMAReq_Rx, ENABLE);
DMA_ITConfig(DMA2_Channel1, DMA_IT_TC, ENABLE);
I2S_Cmd(SPI3,ENABLE);//SPI3 I2S ENê1Äü.
//I2S_Cmd(SPI3,ENABLE);//SPI3 I2S ENê1Äü.
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>