cancel
Showing results for 
Search instead for 
Did you mean: 

CubeMx dma spi:Getting spi overrun

teijo
Associate II
Posted on January 24, 2017 at 14:39

Hi,

I'm using latest version of Cube (download 20.01). I'm trying to read ADC-values from SPI with DMA. Read is activated on ADC-dataready.

#define ADC_BLOCK_SIZE 24

uint8_t tempBuf[ADC_BLOCK_SIZE ];

// This interrupt is called every 100 us.

void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin)

{

    status =  HAL_SPI_Receive_DMA(&hspi1, tempBuf, ADC_BLOCK_SIZE);

}

First read calls the DMA ready Callback correctly

HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)

but further interrupts cause SPI overrun error and transfer stops. Any ideas what to do differently?

APB2 is at 42 MHz

I tested the same transfer with SPI polling method and it was working without errors.

/* SPI1 init function */

static void MX_SPI1_Init(void)

{

  hspi1.Instance = SPI1;

  hspi1.Init.Mode = SPI_MODE_MASTER;

  hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY;

  hspi1.Init.DataSize = SPI_DATASIZE_8BIT;

  hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;

  hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;

  hspi1.Init.NSS = SPI_NSS_SOFT;

  hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;

  hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;

  hspi1.Init.TIMode = SPI_TIMODE_DISABLE;

  hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;

  hspi1.Init.CRCPolynomial = 10;

  if (HAL_SPI_Init(&hspi1) != HAL_OK)

  {

    Error_Handler();

  }

}

1 REPLY 1
teijo
Associate II
Posted on January 24, 2017 at 15:17

Edit: i commented hal errorcode line, so code doesn't abort. Code running ok and the spi input values seems to be ok too.

I'm not really undestand what happening here. I have to test this more

/* SPI in Error Treatment --------------------------------------------------*/

  if(((itflag & (SPI_FLAG_MODF | SPI_FLAG_OVR | SPI_FLAG_FRE)) != RESET) && ((itsource & SPI_IT_ERR) != RESET))

  {

    /* SPI Overrun error interrupt occurred ----------------------------------*/

    if((itflag & SPI_FLAG_OVR) != RESET)

    {

      if(hspi->State != HAL_SPI_STATE_BUSY_TX)

      {

        //SET_BIT(hspi->ErrorCode, HAL_SPI_ERROR_OVR); // Do not set error code

        __HAL_SPI_CLEAR_OVRFLAG(hspi);

      }