cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi) is not working!

SEROL.1
Associate

I'm trying to set up a basic SPI interface using the HAL provided by ST on the STM32H750VBT mcu. What I am currently trying to do is to write anything to the SPI bus and while trying this i am using HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)  function.

The callback I am referring to is called when the amount of data specified in the transmit functions after spi interrupt called. As far as I know the SPI interrupt service routine (ISR) is called every time a character is transmit and when we use the HAL that happens internally to the library and doesn't need to be managed by me.

But the HAL library does not set up this call back function. This refers to there might be a bug in the ST HAL libraries.

By the way, whenever i try to call this function it causes hard fault and calls HardFault_Handler(); . In my opinion when we can not call this function the data to be sent is getting stacked. And this causes over flow in the flow of code

i will be very appreciated if you could help me about this problem asap.

Thanks in Advance.

I used the following initial parameters for the SPI bus

void MX_SPI2_Init(void)
{
  hspi2.Instance = SPI2;
  hspi2.Init.Mode = SPI_MODE_MASTER;
  hspi2.Init.Direction = SPI_DIRECTION_2LINES;
  hspi2.Init.DataSize = SPI_DATASIZE_8BIT;
  hspi2.Init.CLKPolarity = SPI_POLARITY_LOW;
  hspi2.Init.CLKPhase = SPI_PHASE_1EDGE;
  hspi2.Init.NSS = SPI_NSS_SOFT;
  hspi2.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
  hspi2.Init.FirstBit = SPI_FIRSTBIT_MSB;
  hspi2.Init.TIMode = SPI_TIMODE_DISABLE;
  hspi2.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
  hspi2.Init.CRCPolynomial = 7;
	hspi2.Init.CRCLength=SPI_CRC_LENGTH_DATASIZE;
  hspi2.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
  hspi2.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
  hspi2.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
  hspi2.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi2.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
  hspi2.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
  hspi2.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
  hspi2.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
  hspi2.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
  hspi2.Init.IOSwap = SPI_IO_SWAP_DISABLE;
  if (HAL_SPI_Init(&hspi2) != HAL_OK)
  {
    Error_Handler();
  }
 
}

1 REPLY 1
TDK
Guru

> By the way, whenever i try to call this function it causes hard fault and calls HardFault_Handler(); 

You need to track down why you're getting a hard fault before you try to debug the SPI. Likely that is the source of the issue, rather than the result.

If you feel a post has answered your question, please click "Accept as Solution".