Problem with UART communication functions.
All these functions have one problem, let's say in this function HAL_UART_Receive_IT(&huart4, data,5);
the third parameter is the number of transmitted characters.
If you enter more or less characters in the COM port of the terminal than specified in the HAL_UART_Receive_IT function, then various reception problems begin. Either there is no data reception or the function works several times and combines different data transfers into one array.
My code may not be entirely correct, but it works and shows what the problem is.
//main.c
#include <stdio.h>
extern uint8_t data[5];
void HAL_UARTEx_RxEventCallback(UART_HandleTypeDef *huart, uint16_t Size)
{
printf("%s\n", data);
}
while (1)
{
HAL_UARTEx_ReceiveToIdle_IT (&huart4, data,5);
}
//stm32f4xx_it.c
uint8_t data[5]={0};
void UART4_IRQHandler(void)
{
HAL_UARTEx_ReceiveToIdle_IT (&huart4, data,5);
HAL_UART_IRQHandler(&huart4);
}
Enter less than 5 characters or more than 5 characters into the COM port terminal.