本帖最后由 zhexun 于 2016-3-10 15:28 编辑
年前用STM32F301C8T6的I2S一直有问题,现在还是存在问题,准备要问ST的FAE了,我的I2S初始我认为是没问题的,48K/24BIT,设置为MCLK输出,I2S_Mode_MasterRx模式,接收ADC芯片输出数据(I2S接口),现在配置之后,通过示波器和逻辑分析仪测试MCLK正常,256fs。LRCK有约为48K的波形(STM32F301本身有误差),SCLK也正常。ADC芯片的数据输出脚也量到有信号(不是0),但是我I2S中断接收后的数据一直为0,不知道什么原因,请高手帮忙解决一下!(用DMA接收也一直为0,真心怀疑是不是芯片的问题了)把代码都贴出来如下:
void I2S_Configuration(void)
{
I2S_InitTypeDef I2S_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable SPI APB clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2, ENABLE); //RCC_I2SCLKConfig(RCC_I2S2CLKSource_SYSCLK);
/* Enable GPIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB, ENABLE);
/* SPI Pins configuration */
/* Configure SPI2 pins: PB12-WS(LRCK),PB13-CK(SCLK),PB15-DOUT, PA8-MCK */
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; //不上拉
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //推挽输出
GPIO_InitStructure.GPIO_Pin = I2S_CK_PIN|I2S_DOUT_PIN|I2S_WS_PIN;
GPIO_Init(I2S_GPIO_PORT, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = I2S_MCK_PIN;
GPIO_Init(I2S_MCK_GPIO_PORT, &GPIO_InitStructure);
/* Connect pin to Peripheral */
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_CK_SOURCE, I2S_GPIO_AF);//I2S_GPIO_AF = GPIO_AF_5
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_DOUT_SOURCE, I2S_GPIO_AF);
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_WS_SOURCE, I2S_GPIO_AF);
GPIO_PinAFConfig(I2S_MCK_GPIO_PORT, I2S_MCK_SOURCE, I2S_GPIO_AF);
/* I2S peripheral configuration */
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_48k; // I2S_AudioFreq_48k;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; // I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b; //
I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;
I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx; //只有设置主机模式才有MCLK输出
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Enable; // I2S_MCLKOutput_Enable;
I2S_Init(SPI2, &I2S_InitStructure);
/* SPI2 IRQ Channel configuration */
NVIC_InitStructure.NVIC_IRQChannel = SPI_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable the I2S2 RXNE interrupt */
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);
/* Enable the I2S2*/
I2S_Cmd(SPI, ENABLE);
}
void SPI2_IRQHandler(void)
{
static uint32_t spitmpreg = 0x00, i2stmpreg = 0x00;
u16 temp0;
u16 temp1;
spitmpreg = SPI2->SR;
if ((spitmpreg&0x01)==0x01)
{
I2S2_Buffer_Rx[0] = SPI2->DR; //****************读出来一直为0,******************
//I2S2_Buffer_Rx[0] = SPI_I2S_ReceiveData16(SPI2);
if((spitmpreg&0x04)==0x00) //判断是否是左声道数据
{
/* Store the I2S2 received data in the relative data table */
SaveToFifoBuf[RxIdx++] = (u8)(I2S2_Buffer_Rx[0]>>8); //把左声道24BIT数据分四个字节放到SaveToFifoBuf中
SaveToFifoBuf[RxIdx++] = (u8)(I2S2_Buffer_Rx[0]);
if(RxIdx==LENTHIDX)
{
RxIdx=0;
Flag_Int=1;
}
}
}
}
一周热门 更多>