\0 is added in the front of my message when using HAL_SPI_Receive_DMA()
Hello,
I'm commucating two STM32 F4 boards using SPI
The first board is configured as a Master and used to only transmit data
#define message_tx_size 4
uint8_t message_tx[message_tx_size] = "ABCD";
....
int main(void){
while (1){
HAL_SPI_Transmit(&hspi1, message_tx, message_tx_size, HAL_MAX_DELAY);
}
}
The second board is configured as a Slave and used to only receiver data
//main.c
#define message_rx_size 4
uint8_t message_rx[message_rx_size];
int main(void){
while (1){
if ((1 == msgRX)){ //Process the message
msgRX = 0;
} else if (0 == msgRX){
msgRX = -1;
memset(&struct_example_data_rx, '\0', size_of_struct_example_data);
HAL_SPI_Receive_DMA(&hspi1, (uint8_t *)&struct_example_data_rx, size_of_struct_example_data);
}
HAL_Delay(200);
}
}
//stm32f4xx_it.c
extern volatile int msgRX;
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi) {
if(hspi->Instance == hspi1.Instance && -1 == msgRX) {
msgRX = 1;
}
}
The problem is: for the first iteration, I receive the exact data. But after a few itteration, the data I received becomes "\0ABC".
And if I re-run the receiver, without re-runing the transmiter, then I got the same exact result: OK at the begening, but altered after.
Thank you for help

