Delay issues on HAL_SPI libraries
Hello everyone,
I am using SPI to communicate two Nucleo Boards (a NUCLEO-L432KC and a NUCLEO-F411RE one), and i found out a weird behavior. The idea was to perform a transaction Master -> Slave in order to select a "register" to read. Once the Slave has received the "register", the Master request the information and the Slave shall send the information to the master.
In order to perform this, interruptios were used in the slave side. The "register" logic is still not present, but the concept is the aforementioned one.
The Master code is as follows (only SPI-Related lines):
HAL_SPI_Transmit(&hspi2, txbuff, 2, 1000);
HAL_Delay(1); /* DELAY BETWEEN TRANSACTIONS */
HAL_SPI_Receive(&hspi2, rxbuff, 12, 1000);
And for the slave, following code is used:
/* USER CODE BEGIN 2 */
HAL_SPI_Receive_IT(&hspi1, buffreg, BUFFREG);
/* USER CODE END 2 */
SPI Interruption handlers are as follows:
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
{
HAL_SPI_Transmit_IT(&hspi1, buffdat, BUFFDAT);
rxData++;
}
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
{
HAL_SPI_Receive_IT(&hspi1, buffreg, BUFFREG);
txData++;
}
When the delay (HAL_Delay(1)) in the first pice of code (MASTER code) is not present, the communications cannot be performed properly, and weird values are read in the reception. But when it is pressent, the program works properly.
Are there any way to overcome this delay?
Is there another better approach to do so?
Thanks in advance.
