Showing results for 
Search instead for 
Did you mean: 

STM32F405 UART communication between PC

Associate II

I am sending a command to the STM32F405 through the UART (COM) port for receiving data from the STM32F405. Once the command send from PC it will continously send data from STM32F405. What if the PC drops the connection and goes to sleep. And my STM32F405 still performing to send data and how can I make the STM32F405 to stop automatically. I couldnt find much details on this. Any one could help on this matter. Thank you

Senior III

Maybe two options:

a) you use DTR/CTS signals (HW handshaking): if PC goes to sleep, it will not allow to send (CTS, DTR disable sender (assuming these signals are changed, not sure)

b) an easier way: have a "ping pong": send messages like "are you still alive" to host PC: if it does not respond anymore - PC sleeps

c) or: if you have already a handshake, like: MCU sends to PC, PC has to respond (acknowledge) or sends a simple "
prompt" back - if you miss it after a short while - PC sleeps.
Do a bi-directional handshake: MCU sends something - PC has to respond (at lest with "OK"). If respond does not come anymore = "connection lost".

The main question would be:
when would you try again, to check if PC is awake again?
Looks like, you need anyway a "ping" approach: MCU sends a "are you alive" message and PC has to reply on it. If not, PC is not there. And you have to start "pinging" PC periodically when you have a lost connection (until it responds again).

"Keep alive" messages or "Are you alive" requests...

Thank you for the reply. Its very useful information . I couldnt find any example's how to do this. Whether you could guide me through with examples.

It can be very simple; eg, just:


while( 1 )




@cjaya.2 wrote:

I am sending a command to the STM32F405 through the UART (COM) port 

So you already have the mechanism in place to initially wait for the command from the PC - you just need to do the same thing waiting for the Acknowledgement after each send ... 



while( 1 )