UART variable length message
Good morning, I'm making a program that should receive from the UART a variable length message. The message ends with '\n'
I tried it with this
uint8_t rxChar=0;
int main() {
HAL_UART_Receive_IT(&huart2, &rxChar, 1);
}
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) {
/ /appendCharToBuffer
rxChar
HAL_UART_Receive_IT(&huart2, &rxChar, 1);
}
but after receiving two bytes I have a 'overrun error'.
using
HAL_UART_Receive_IT(&huart2, serial_command_buffer, COMMAND_BUFFER);
works, but the message must be at least
COMMAND_BUFFER char length.
Is possile to generate an interrupt when UART receives an '\n' although have not yet been receivedCOMMAND_BUFFER
characters? Or can I use an approach like the previous one without causing an overrun error?or what is the proper way to handle the need to receive a variable length message?
Thanks in advance
