HAL_UART_Transmit() with HAL_UART_Receive_IT() fails if RX when TX not completed.
I used to send AT command to a module with HAL_UART_Transmit():
void send_uart(char * buffer)
{
uint16_t buffer_size = strlen(buffer);
uint8_t CRLFbuff[] = "\r\n";
HAL_UART_Transmit(&hlpuart1, CRLFbuff, 2, 0xFF); // ok
HAL_UART_Transmit(&hlpuart1, (uint8_t *)buffer, buffer_size, 0xFF); // ok
HAL_UART_Transmit(&hlpuart1, CRLFbuff, 2, 0xFF); // ok
}and receive answer with HAL_UART_Receive_IT() byte per byte:
HAL_UART_Receive_IT(&hlpuart1, &Rx_data, 1);
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
if (huart->Instance == LPUART1){ // Current UART
if (Rx_indx + 1 > rx_buffer_size){
Rx_indx = 0;
}
if (Rx_data != 0x0A){ // If received data different from LF
Rx_Buffer[Rx_indx++] = Rx_data; // Add data to Rx_Buffer
}
else {
Rx_indx = 0;
Transfer_cplt++;//transfer complete, data is ready to read
}
HAL_UART_Receive_IT(&hlpuart1, &Rx_data, 1); //activate UART receive interrupt every time
}
}And this is working well at 9600 in nominal TX/RX. But if I send bad data to the module it sends immediately "ERROR: parse error" while my STM32L031 is still transmitting. This as the effect of killing my RX interrupt. Instead of being HAL_UART_STATE_BUSY_RX the UART->RxState switches to HAL_UART_STATE_READY and RX interrupt is never triggered (transmit part still works good).
I changed my transmit code to HAL_UART_Transmit_IT (with little rework) and this behavior is not observed (works well).
Is this normal ?