2021-06-10 11:22 AM
I'm communicating between STM32F746G-Discovery ans ESP32 using UART (PC6 and PC7 pins on STM). ESP receives some data at certain intervals over WiFi and transmits it to STM via UART.
On STM I want UART to receive data only when ESP32 has transmitted. Probably STM has to keep listening to UART port until there is data. I want this in non-blocking mode, since there are other peripherals and display working on STM.
How does STM32 know that ESP is sending data over UART and HAL_UART_Receive_IT has to be called to receive it.
Solved! Go to Solution.
2021-06-10 12:46 PM
RX_BUFF_SIZE tends to ONE ?
Otherwise you're wait on other characters that may, or may not, turn up in any given time.
2021-06-10 12:01 PM
HAL_UART_Receive_IT should be called before data is sent. The receive complete interrupt callback is called through an interrupt when data is actually received.
2021-06-10 12:22 PM
You leave HAL_UART_Receive_IT() constantly pending, I'd suggest waiting for one byte, and without any timeout expectations.
When data arrives, the UART will interrupt, and your IRQ/Callback implementation will fetch the data into a buffer, and submit a new HAL_UART_Receive_IT() to catch the next byte. In some worker-task, or periodic loop, you check the buffer for inbound data, and accumulate or process that, parsing when you have enough data to act upon.
2021-06-10 12:32 PM
Could you please suggest how to keep HAL_UART_Receive_IT() pending and wait for one byte?
So inside callback implementation, should I call HAL_UART_Receive_IT() again to get the next data?
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
// set flag
HAL_UART_Receive_IT(&huart6, Rx_buff, RX_BUFF_SIZE);
}
2021-06-10 12:32 PM
Could you please suggest how to keep HAL_UART_Receive_IT() pending and wait for one byte?
So inside callback implementation, should I call HAL_UART_Receive_IT() again to get the next data?
void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)
{
// set flag
HAL_UART_Receive_IT(&huart6, Rx_buff, RX_BUFF_SIZE);
}
2021-06-10 12:46 PM
RX_BUFF_SIZE tends to ONE ?
Otherwise you're wait on other characters that may, or may not, turn up in any given time.