最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

stm32 - When data arrives before calling the STM32G4 UART receive function - Stack Overflow

programmeradmin0浏览0评论

Data reception is locked if data arrives before the STM32 UART reception function is called.

  • I simulated this in the code example given below.
  • I send a data packet and receive an immediate response from the other device.
  • I am not interested in this response, so I do not call the receive function.
  • But later when I need to receive data, I call the function. But when I send a data from the serial monitor, it does not receive the data. It behaves as if no data is coming.
      HAL_UART_Transmit(&huart1, send_packet, 8, 340);
      // This is where data is sent to the other 
      // device and a response is received.
      // In less than 1 second, this answer comes.
      HAL_Delay(1000);
      HAL_UARTEx_ReceiveToIdle_IT(&huart1, buffer, BUFFER_SIZE);

This has happened on different occasions. For example; I am configuring a BLE module with AT commands. If the setting is successful, it responds back. But since I do not call the UART receive function, the UART locks up.

When I need to read data from the UART in the rest of the software, there is no data reception. It does not give any error.

To avoid this error, I deinit the UART and then init it again. Or I use the UART receive function continuously if there is data to be received.

Data reception is locked if data arrives before the STM32 UART reception function is called.

  • I simulated this in the code example given below.
  • I send a data packet and receive an immediate response from the other device.
  • I am not interested in this response, so I do not call the receive function.
  • But later when I need to receive data, I call the function. But when I send a data from the serial monitor, it does not receive the data. It behaves as if no data is coming.
      HAL_UART_Transmit(&huart1, send_packet, 8, 340);
      // This is where data is sent to the other 
      // device and a response is received.
      // In less than 1 second, this answer comes.
      HAL_Delay(1000);
      HAL_UARTEx_ReceiveToIdle_IT(&huart1, buffer, BUFFER_SIZE);

This has happened on different occasions. For example; I am configuring a BLE module with AT commands. If the setting is successful, it responds back. But since I do not call the UART receive function, the UART locks up.

When I need to read data from the UART in the rest of the software, there is no data reception. It does not give any error.

To avoid this error, I deinit the UART and then init it again. Or I use the UART receive function continuously if there is data to be received.

Share Improve this question edited Apr 4 at 23:50 Peter Mortensen 31.6k22 gold badges110 silver badges133 bronze badges asked Jan 15 at 9:24 burkeburke 131 silver badge2 bronze badges 1
  • Re "I am configuring a BLE module with AT commands": What module? ESP32? – Peter Mortensen Commented Apr 4 at 23:52
Add a comment  | 

1 Answer 1

Reset to default 1

If you don't call the receive function for data that is received then an overrun will occur.

If you don't want the data then you need to clear the overrun flag yourself before receiving again.

De-init and re-init is clearing the flag for you, but perhaps you can search in the library header for a function that only clears the flag without having to set up all the other registers again.

发布评论

评论列表(0)

  1. 暂无评论