Validating received UART message
Sorry if this is a rookie question. I have set up USART 2 to receive a UART command. If the sent command is "<EN>", I need to toggle the value of a global state variable. When transmitting the received data via the callback interrupt, I have no issues, so I know that UART is receiving the data no problem. My issue is with checking that the value of the data received is indeed "<EN>". I've attached the contents of my callback function as it currently stands.
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart){
if (huart->Instance == USART2 && strncmp((char*)huart->pRxBuffPtr, "<EN>", 4) == 0)
{
state = !state; //Toggle state variable
memset(rx_data, 0, 1); //Clear data buffer
HAL_UART_Receive_IT(&huart2, rx_data, 1); //Receive next command
}
I believe that I might have to use a larger buffer, and fill it with every character, then perform a check on that. As it currently stands, the code runs, but the state variable isn't changed upon receiving the "<EN>" command. Any help is appreciated.
