我设置STM32F301为从机接收(接收ADC芯片出来的I2S数据),以下是我的I2S设置和中断,我的问题是,我用逻辑分析仪可以看到ADC可以输出波形,但是I2S中断读出的数据一直为0(我用仿真器看过也用串口打印出来过还是0),请原子哥帮忙看看是哪里问题?/* I2S Interface */
#define SPI SPI2
#define I2Sext I2S2ext
#define RCC_APBPeriph_SPI RCC_APB1Periph_SPI2
#define RCC_AHBPeriph_GPIO RCC_AHBPeriph_GPIOB
#define I2S_GPIO_PORT GPIOB
#define I2S_GPIO_AF GPIO_AF_5
#define I2S_CK_PIN GPIO_Pin_13 /* PB.13 */
#define I2S_CK_SOURCE GPIO_PinSource13
#define I2S_DIN_PIN GPIO_Pin_14 /* PB.14 */ //把ADC的输出接到PB14上或者PB15上,读出的数据都为0
#define I2S_DIN_SOURCE GPIO_PinSource11
#define I2S_DOUT_PIN GPIO_Pin_15 /* PB.15 */
#define I2S_DOUT_SOURCE GPIO_PinSource12
#define I2S_WS_PIN GPIO_Pin_12 /* PB.12 */
#define I2S_WS_SOURCE GPIO_PinSource12
#define SPI_IRQHandler SPI2_IRQHandler
#define SPI_IRQn SPI2_IRQn
//-----------------I2S配置------------------
void I2S_Configuration(void)
{
I2S_InitTypeDef I2S_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable SPI APB clocks */
RCC_APB1PeriphClockCmd(RCC_APBPeriph_SPI, ENABLE);
/* Enable GPIO clocks */
//RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIO, ENABLE);
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE);
/* SPI Pins configuration */
/* Configure SPI2 pins: PB12-WS(LRCK),PB13-CK(SCLK),PB14-DIN,PB15-DOUT */
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_DIN_PIN |I2S_DOUT_PIN|I2S_WS_PIN;
GPIO_Init(I2S_GPIO_PORT, &GPIO_InitStructure);
/* Connect pin to Peripheral */
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_CK_SOURCE, I2S_GPIO_AF);
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_DIN_SOURCE, I2S_GPIO_AF);
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_DOUT_SOURCE, I2S_GPIO_AF);
GPIO_PinAFConfig(I2S_GPIO_PORT, I2S_WS_SOURCE, I2S_GPIO_AF);
/* I2S peripheral configuration */
SPI_I2S_DeInit( SPI );
I2S_StructInit( &I2S_InitStructure );
I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_96k; // I2S_AudioFreq_48k;
I2S_InitStructure.I2S_Standard = I2S_Standard_Phillips; // I2S_Standard_Phillips;
I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_24b; // I2S_DataFormat_16bextended;
I2S_InitStructure.I2S_CPOL = I2S_CPOL_High;
I2S_InitStructure.I2S_Mode = I2S_Mode_SlaveRx; //从机接收
I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable; // I2S_MCLKOutput_Disable;
I2S_Init(SPI2, &I2S_InitStructure);
//I2S_FullDuplexConfig(I2S2ext,&I2S_InitStructure); //也试过开启全双工,I2S读出的数据还一直是0
/* 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 I2Sext TX Interrupt */
//SPI_I2S_ITConfig(I2S2ext, SPI_I2S_IT_TXE, ENABLE);
/* Enable the I2S2 and I2Sext*/
I2S_Cmd(SPI, ENABLE);
//I2S_Cmd(I2S2ext, ENABLE);
}
//-------------------I2S中断-------------
void SPI2_IRQHandler(void)
{
static uint32_t spitmpreg = 0x00, i2stmpreg = 0x00;
u16 temp0;
u16 temp1;
if(SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_RXNE ) == SET)
{
I2S2_Buffer_Rx[0] = SPI_I2S_ReceiveData16(SPI2);
I2S2_Buffer_Rx[1] = SPI_I2S_ReceiveData16(SPI2);
if(SPI_I2S_GetFlagStatus(SPI2, I2S_FLAG_CHSIDE) == RESET)
{
/* Store the I2S2 received data in the relative data table */
SaveToFifoBuf[RxIdx++] = (u8)(I2S2_Buffer_Rx[0]>>8); //打印SaveToFifoBuf一直为0,打印I2S2_Buffer_Rx也一直为0
SaveToFifoBuf[RxIdx++] = (u8)(I2S2_Buffer_Rx[0]);
SaveToFifoBuf[RxIdx++] = (u8)(I2S2_Buffer_Rx[1]>>8);
if(RxIdx==LENTHIDX)
{
RxIdx=0;
Flag_Int=1;
SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, DISABLE);
}
}
//SPI_I2S_ClearFlag(SPI2,SPI_I2S_FLAG_RXNE);
}
}
file:///C:Documents and Settingsld-td-02Application DataTencentUsers362506417QQWinTempRichOleP`A`BQQB60`V0GKXCTEEX`L.png
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>