How to reduce STM32f303 SPI Overhead time and what is the min. running time?
- October 8, 2020
- 9 replies
- 3188 views
I want to get a two 16 bit values through two spi interface within 4µs . So I set the baudrate 18Mbits/s so that for 16bits it takes just < 1µs. Everything is working fine.
But the problem is the overhead time between twice HAL_SPI_RECEIVE is nealry 8µs by STM43F303 with 72MHz clock.
How could I reduce the overhead time?
Here are the code for the SPI Interface:
hspi4.Instance = SPI4;
hspi4.Init.Mode = SPI_MODE_MASTER;
hspi4.Init.Direction = SPI_DIRECTION_2LINES;
hspi4.Init.DataSize = SPI_DATASIZE_16BIT;
hspi4.Init.CLKPolarity = SPI_POLARITY_HIGH;
hspi4.Init.CLKPhase = SPI_PHASE_1EDGE;
hspi4.Init.NSS = SPI_NSS_HARD_OUTPUT;
hspi4.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_4;
hspi4.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi4.Init.TIMode = SPI_TIMODE_DISABLE;
hspi4.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi4.Init.CRCPolynomial = 7;
hspi4.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
hspi4.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
if (HAL_SPI_Init(&hspi4) != HAL_OK)
{
Error_Handler();
}
/* USER CODE BEGIN SPI4_Init 2 */
/* USER CODE END SPI4_Init 2 */
}
I test them in the main loop:
while(1)
{
uint16_t data_in;
HAL_SPI_Receive(&hsp4,(uint8_t *)&data_in,1,1);
}
And here you could see the SPI SCK, there are nearly 8µs overhead time between twice received data which is more than the transmit time 16/18MHz:
