View previous topic :: View next topic |
Author |
Message |
PIC24H
Joined: 02 Mar 2015 Posts: 19
|
Detecting a RS232 connection? |
Posted: Fri Mar 06, 2015 4:48 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Fri Mar 06, 2015 6:20 am |
|
|
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
|
|
Posted: Fri Mar 06, 2015 6:50 am |
|
|
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: 9229 Location: Greensville,Ontario
|
|
Posted: Fri Mar 06, 2015 7:00 am |
|
|
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
|
|
Posted: Fri Mar 06, 2015 7:10 am |
|
|
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
|
|
Posted: Fri Mar 06, 2015 7:26 am |
|
|
thank you guys for your help |
|
|
|