2022-02-23 05:02 AM
2022-02-23 06:26 AM
Receive-only mode sends the clock continuously and code is not fast enough to keep up at high data rates. Instead, use HAL_SPI_TransmitReceive with dummy data to receive an exact number of bytes.
2022-02-23 10:29 AM
That was not the solution the SPI is configured as full Master so when you can HAL_SPI_Receive it then calls HAL_SPI_TransmitReceive. I found out by testing the HAL function is not Thread safe. I changed the code to use HAL_SPI_TransmitReceive_IT. It also has the same issue. If you add code to stop RTOS interrupting the code it works
void SPI4_IRQHandler(void)
{
/* USER CODE BEGIN SPI4_IRQn 0 */
UBaseType_t uxSavedInterruptStatus = taskENTER_CRITICAL_FROM_ISR();
/* USER CODE END SPI4_IRQn 0 */
HAL_SPI_IRQHandler(&hspi4);
taskEXIT_CRITICAL_FROM_ISR(uxSavedInterruptStatus);
/* USER CODE BEGIN SPI4_IRQn 1 */
/* USER CODE END SPI4_IRQn 1 */
}