SPI Slave Receiving Every Other Byte
I am using STM32H7B3I-DK running a touchgfx application and acting as SPI Master, and Nucleo-H743ZI as SPI Slave. Both are configured in interrupt mode not using HWNSS.
The Master is sending 0,1,2,3,4,5,6,7, but the slave is only receiving 0,2,4,6,0,2,4,6.
I am sending one byte at a time and receiving one byte then adding it to a buffer.
The master is properly sending data, as checked by oscilloscope. I have tried introducing a HAL-Delay(1) between transmissions and the data is then received perfectly fine; however, that is way to slow for proper communication. I have double checked the compatible settings for Master-Slave communication in the .ioc files such as Data Size, First Bit, etc...
Here is my following relevant code for the master:
for(;;)
{
HAL_GPIO_WritePin(GPIOI, GPIO_PIN_0, GPIO_PIN_RESET); // Pull CS low
for (int i = 0; i < 8; i++) {
data[i] =i;
HAL_SPI_Transmit(&hspi2, &data[i], 1, HAL_MAX_DELAY); // Transmit one byte
HAL_UART_Transmit(&huart1, &data[i], 1, 0);
}
}
Here is the slave code:
void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) {
if (GPIO_Pin == GPIO_PIN_14) {
if (HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_14) == GPIO_PIN_RESET) {
HAL_SPI_Receive_IT(&hspi1, &rxBuffer[rxIndex], 1); // Start receiving
}
}
}
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
if ((hspi->Instance == SPI1) && (HAL_GPIO_ReadPin(GPIOD, GPIO_PIN_14) == GPIO_PIN_RESET)) {
// Process received data
rxIndex = (rxIndex + 1) % RX_BUFFER_SIZE;
// Re-enable SPI interrupt for the next byte
HAL_SPI_Receive_IT(&hspi1, &rxBuffer[rxIndex], 1);
}
}
[...]
while (1)
{
for (int i = 0; i < 8; i++) {
printf("%u ", rxBuffer[i]);
}
printf("\n\r");
HAL_Delay(1000);
}
