cancel
Showing results for 
Search instead for 
Did you mean: 

Issue with STM32 UART Communication and Data Loss in Continuous Transmission

syedaayesha
Associate

I am currently working on an STM32-based project using UART for continuous data transmission between the microcontroller and a PC application.

The system works fine initially, but I am facing intermittent data loss and incomplete packets during long-running communication. The issue becomes more noticeable when the baud rate is increased or when multiple interrupts are active in the system.

What I have already tried:

  • Verified baud rate and clock configuration in STM32CubeMX
  • Enabled UART interrupt-based receiving
  • Increased buffer size for RX handling
  • Checked wiring and physical connection stability

Despite this, the problem still occurs randomly after some time of operation.

I would like to ask the community:

  • What are the best practices for stable UART communication in STM32 under continuous data flow?
  • Should I switch to DMA-based UART instead of interrupt mode for better reliability?
  • Are there any known issues with buffer overflow or interrupt priority that could cause this behavior?

Any guidance or real-world experience would be greatly appreciated.

3 REPLIES 3
TDK
Super User

Use HAL_UARTEx_ReceiveToIdle_DMA with a circular buffer. You will get no data loss, provided you handle the data in a reasonable time frame.

If you feel a post has answered your question, please click "Accept as Solution".
mƎALLEm
ST Employee

Hello,

What STM32 part number are you using?

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Andrew Neil
Super User

How do you detect the loss?

What testing have you done to find where the data is being lost:

  • on the PC side ?
  • on the STM32 side ?
  • both ?

Does the loss correlate with anything else happening in the system?

Are UART errors occurring (framing, overrun, etc) ?

Is your interrupt handling tight and efficient?

Are your interrupt priorities well thought out?

A complex system that works is invariably found to have evolved from a simple system that worked.
A complex system designed from scratch never works and cannot be patched up to make it work.