Showing results for 
Search instead for 
Did you mean: 

Why is the overflow flag (OVR) set as soon as the I2S peripheral has been enabled when using I2S2 in Interrupt mode with Nucleo F401RE?


I am trying to use the I2S2 interface in Master Rx mode with the Nucleo 401RE and X-Nucleo-CCA02M2 audio shield. I enable the SPI2 global interrupt in NVIC settings, setup the required GPIOs and generate the code. I want to receive data from the on-board microphones of the audio shield and I want the MCU to generate the clock.

As soon as the I2S peripheral is enabled in the HAL_I2S_Receive_IT() function, which is called once before the infinite while loop (__HAL_I2S_ENABLE(hi2s)), the OVR flag is raised due to which the interrupt handler is serviced only once as the below code in the I2S_IRQHandler is executed -

/* I2S Overrun error interrupt occurred -------------------------------------*/
    if (((i2ssr & I2S_FLAG_OVR) == I2S_FLAG_OVR) && (__HAL_I2S_GET_IT_SOURCE(hi2s, I2S_IT_ERR) != RESET))
      /* Disable RXNE and ERR interrupt */
      __HAL_I2S_DISABLE_IT(hi2s, (I2S_IT_RXNE | I2S_IT_ERR));
      /* Clear Overrun flag */
      /* Set the I2S State ready */
      hi2s->State = HAL_I2S_STATE_READY;
      /* Set the error code and execute error callback*/
      SET_BIT(hi2s->ErrorCode, HAL_I2S_ERROR_OVR);
      /* Call user error callback */

Can anyone help me figure out why the overflow flag is getting raised right after the I2S peripheral is enabled and how to get interrupt mode to work with I2S?


Do you single-step the initialization? I2S does not stop while you single-step, it keeps clocking and receiving, and as during single-step the code execution is stopped, there's no code to pick the received data, hence the overflow.

Other than that, it may also be the code being too slow to pick the data in interrupt.