STM32F0 SPI transmit via interrupt
Hello everyone,
I'm useing the NUCLEO-F072RB and I'm trying to get the SPI via interrupts to work.
Here is the CubeMX initialization of the SPI:
/* SPI1 init function */
void MX_SPI1_Init(void){hspi1.Instance = SPI1;
hspi1.Init.Mode = SPI_MODE_MASTER; hspi1.Init.Direction = SPI_DIRECTION_2LINES;hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi1.Init.NSS = SPI_NSS_HARD_INPUT;
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_32;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 7;
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi1) != HAL_OK)
{
_Error_Handler(__FILE__, __LINE__);
}
}
In my main I start sending 3 bytes every 10 seconds by calling:
if (!(HAL_GetTick() % 10000))
{ u8_spi_tx_buffer[0] = 0xaa;u8_spi_tx_buffer[1] = 0x00;
u8_spi_tx_buffer[2] = 0xff;
if(HAL_SPI_Transmit_IT(&hspi1,u8_spi_tx_buffer,3) != HAL_OK)
{
/* Transfer error in transmission process */
Error_Handler();
}}
The 3 bytes are getting transmitted. However after about 30�s they are getting transmitted again. This happens about 20 times before they are getting stopped transmitting.
Do I have to do anything in the HAL_SPI_TxCpltCallback function to prevent this?
#stm32f0 #spi #stm32-spi-interrupts