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 CCS Technical Support

Detecting a RS232 connection?

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



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

Detecting a RS232 connection?
PostPosted: Fri Mar 06, 2015 4:48 am     Reply with quote

I got a short question. I have connected my pic24hj256 to my pc via rs232.

Is there a way to detect if its connected to the pc? So if it detects the rs232 connection it will start for example the bootloader. If not it starts another program.

I thought about using an #INT_RDA or using something with the dma, but I'm not sure how it works.

thanks
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 06, 2015 6:20 am     Reply with quote

If you mean can the PIC detect when it is connected, when the connecting cable is plugged in .. it matters a GREAT deal on how the 'connection' and 'when' the connection is made.
If the PIC is wired 24/7 to the PC , it's a different problem than 'just plug the cable in now' situation.

you can use one of the control signals associated with RS232 to tell the PIC it's connected to the PC. That's the way RS232 is 'normally' done.Any good website will have info about this

if you mean have software see if it's connected, then you can use the normally unused RTS/CTS pins, tie them together, and poll them to see if the PIC can 'writre/read through them.Obviously RTC/CTS are NOT connected to PC for this.

if the PIC alone has to detect when it's connected any time with NO interaction from the PC then some sort of polling routine would need to be done,again using the 'control' pins of RS232 from the PC to ensure the PC really is there

A lot depends on what program the PC is running.If you have control over it, it's easy to have the PIC find the PC and validate the connection. I did a simple Delphi program to confirm the PIC was 'there' but I think you want the PIC to see if the PC is there without any PC interaction ??

Jay
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Fri Mar 06, 2015 6:50 am     Reply with quote

Thx for the answer.

Yes, I want the PIC to check/see if the PC (connection to the PC) is there.

For example:

On start of the pic. It should see/detect if its connected to the pc via rs232 connection. If yes, then do X and if not do Y.


What I understand is, that the PC (a program) has to send some something to the pic to know that it is connected?
temtronic



Joined: 01 Jul 2010
Posts: 9244
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Mar 06, 2015 7:00 am     Reply with quote

yes... for example
The PC can set the RI ( Ring Indicator) pin of the RS-232 port 'high'.
The PIC can poll that pin( test) and if high do 'X' if not do 'Y'.
The same procedure can be done with the other control pins. You just need to find a good 'RS232 for Dummies' online site and use whatever pins/signals you need for your program.

Jay
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Fri Mar 06, 2015 7:10 am     Reply with quote

All the options mentioned above assume the PC asserts control signals and that these control signals are extended to the PIC. There is a simple alternative that does not care if the control signals are present or not. If the PICs RS232 transceiver's Rx input is below or transitions below zero volts for more than say 1/10 of a bit time then the PIC is connected to an active RS232 device.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
PIC24H



Joined: 02 Mar 2015
Posts: 19

View user's profile Send private message

PostPosted: Fri Mar 06, 2015 7:26 am     Reply with quote

thank you guys for your help
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