CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

rs232 communication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

rs232 communication
PostPosted: Thu Dec 28, 2023 9:17 am     Reply with quote

How can I create a control code to detect if the connection is lost during communication via RS232? Would you help me with this topic?
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19231

View user's profile Send private message

PostPosted: Thu Dec 28, 2023 9:27 am     Reply with quote

Of itself, serial does not have any detection of the 'state' of the connection.
A lot depends on the nature of what is being sent, and how the wiring is done?.
So (for example), you can wire a connection so that if the connection is not
present the receiver is biased to the 'break' state. This will then give
continuous received zero characters with the framing error bit set.
Alternatively, your friend is the timeout. If you know a packet should arrive
every second, then have a timer interrupt set to timeout at (say) 1.2 seconds,
and reset this whenever a packet arrives. If this triggers the connection has
been lost.
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

PostPosted: Thu Dec 28, 2023 9:57 am     Reply with quote

There are 3 connections on the device. RX,TX,GND. For example, can I do something like the following? or what can i do.
Code:

       if (kbhit(UART1)) {
          printf("There is a connection\r\n");
       } else {
          printf("No connection\r\n");
       }

_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
gaugeguy



Joined: 05 Apr 2011
Posts: 289

View user's profile Send private message

PostPosted: Thu Dec 28, 2023 10:55 am     Reply with quote

What you posted would probably not work well on its own. You are really missing the point of the advice Ttelmah was giving.
The answer relies on information you did not provide. How does your device define a working connection? Are the messages formatted or random? Are messages sent at a regular interval or can the arrive at any random time?
MCUprogrammer



Joined: 08 Sep 2020
Posts: 221

View user's profile Send private message

PostPosted: Thu Dec 28, 2023 11:04 am     Reply with quote

I solved the problem with timeout. thanks
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group