cancel
Showing results for 
Search instead for 
Did you mean: 

I2S/SPI interrupts

nikhil2399
Associate
Posted on May 10, 2012 at 17:07

Hi, I am using STM32F105RB and I have a problem with an I2S master receive connection, using SPI2.

I have configured SPI2 in I2S master Receiver mode, and enabled a SPI2 receive interrupt but immediately after SPI2 initialization in I2S mode I am getting Receive interrupt continuously.

SPI2 init. function and I2S2 IRQ handler..

VOID I2S_2_Init( VOID )

{

    GPIO_InitTypeDef GPIO_InitStructure;

    NVIC_InitTypeDef NVIC_InitStructure;

    I2S_InitTypeDef I2S_InitStructure;

        

    // Clock configurations

    /* SPI3 and SPI2 clocks enable */

  RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI3 | RCC_APB1Periph_SPI2, ENABLE);

    

    // NVIC Config

    /* SPI2 IRQ channel configuration */

  NVIC_InitStructure.NVIC_IRQChannel = SPI2_IRQn;

  NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;

  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

  NVIC_Init(&NVIC_InitStructure);

    

    // GPIO config

    /* Configure SPI2 pins: CK, WS and SD ---------------------------------*/

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13 | GPIO_Pin_15;

  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

  GPIO_Init(GPIOB, &GPIO_InitStructure);

    

    // I2S config

    /* I2S peripheral configuration */

    SPI_I2S_DeInit(SPI2);

    

    I2S_InitStructure.I2S_Standard = I2S_Standard_PCMShort;

    I2S_InitStructure.I2S_DataFormat = I2S_DataFormat_16b;

    I2S_InitStructure.I2S_MCLKOutput = I2S_MCLKOutput_Disable;

    I2S_InitStructure.I2S_AudioFreq = I2S_AudioFreq_8k;

    I2S_InitStructure.I2S_CPOL = I2S_CPOL_Low;

    I2S_InitStructure.I2S_Mode = I2S_Mode_MasterRx;                        // I2S2 as master RX

 

    I2S_Init(SPI2, &I2S_InitStructure);

    

    /* Enable the I2S2 RxNE interrupt */

  SPI_I2S_ITConfig(SPI2, SPI_I2S_IT_RXNE, ENABLE);                        // RX Int.

    

    /* Enable the I2S2 */

  I2S_Cmd(SPI2, ENABLE);

    

    STM_EVAL_LEDToggle(LED1);                // NC

}

/*   IRQ handlear */

VOID SPI2_IRQHandler ( VOID )

{

    STM_EVAL_LEDToggle(LED2);                // NC

    

    /* Check the interrupt source */

    /* RX */

  if (SPI_I2S_GetITStatus(SPI2, SPI_I2S_IT_RXNE) == SET)

  {

        STM_EVAL_LEDToggle(LED3);                // NC

    /* Store the I2S2 received data in the relative data table */

        usnI2SDatBuf[ucIndex++] = SPI_I2S_ReceiveData(SPI2);

  }

}

   

#i2s-spi-interrupts-interrup
0 REPLIES 0