Showing results for 
Search instead for 
Did you mean: 

SPI Receive interrupt callback not being called


I designed a breakout board for the STM32F401CEU6. (Schematic attached)

I am using it to receive data from an ADC chip over SPI.

The ADC chip has a data ready output which should be used as an interrupt pin to let the MCU know there is data available to be read.

I have used the ADC chip with the Nucleo-F401RE, and it works perfectly.

Now using it with my breakout board, it works fine when in blocking mode, but not when using the interrupt. I am using the same code (aside from changing some bits relating to the CEU6 package as opposed to the RE package.

The SPI operation starts from the GPIO ISR.

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)
//    exeCMD(ADS1299_RDATA_CMD);
      // read data interrupt mode
      if(SPI_OK != spiRxBytes_IT(raw_data, 3+3*nb_ch))
            // receive failed, need error handling here

spiRxBytes_IT is just a wrapper of the SPI Hal API

HAL_StatusTypeDef hal_stat = HAL_SPI_Receive_IT(&hspi1, pdata, length);

I am supposed to receive 27 bytes of data, thus the callback function below should be called after 27 bytes have been received.

void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
      rx_done = 1;

However, the callback function is never called. When I debug the function below, I find that the counter RxXferCount never counts down. Thus, the branch SPI_CloseRxTx_ISR(hspi) is never reached.

static void SPI_2linesRxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
  /* Receive data in 8bit mode */
  *hspi->pRxBuffPtr = *((__IO uint8_t *)&hspi->Instance->DR);
  /* Check end of the reception */
  if (hspi->RxXferCount == 0U)
#if (USE_SPI_CRC != 0U)
    if (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE)
      hspi->RxISR =  SPI_2linesRxISR_8BITCRC;
#endif /* USE_SPI_CRC */
    /* Disable RXNE  and ERR interrupt */
    if (hspi->TxXferCount == 0U)

Can anyone provide a suggestion on why this is happening?



Hi! Were you able to solve the issue?

I am facing something kinda similar except my RxXferCount decreases and it eventually reaches zero but the receive completed callback never gets called for some reason.