2
\$\begingroup\$

My project involves a PIC communicating over USB and RS-232 channels, which are then multiplexed to 1 UART by means of a dual SPDT analog switch. As such, the PIC has to know which ports are physically connected, in order to select either the USB port or the RS232 port.

How would I go about doing this? For RS-232, I could set an externan interrupt for the DTR line, but in my industry field, only Tx, Rx and Gnd are used.

For USB, I could potentially use Vbus to detect the presence, but overcurrent is possible

Or would it be more feasible to monitor the impedance of the usb differential lines and the rs232 tx rx lines, like in the audio jack sensing circuits?

\$\endgroup\$
1
  • \$\begingroup\$ By Dual SPDT analog switch, do you mean a standard dpdt mechanical switch? \$\endgroup\$
    – Passerby
    Commented Dec 27, 2012 at 20:29

1 Answer 1

3
\$\begingroup\$

For USB, the easiest way it to monitor for the presence of VBUS.

I'm not sure what you mean by "overcurrent", you shouldn't need to load the USB power line much if at all. If you're really worried, stick a 10K resistor in series with the USB Vcc, and just run it to an input pin. That should protect you from any faults.


Unfortunately, for serial, it can be a lot more involved.

If you're lucky, your system uses either inverted TTL level signaling, which means the line level when there is no traffic is Vcc, or RS232 level signaling, which means the no-traffic line voltage is either ~+10v or ~-10v, depending on whether your bus is inverted.

Then, you can simply monitor for the voltage level. 0v means nothing connected.

If you're unlucky, your system uses TTL level signaling, with the quiescent bus state being 0V. In this case, really the only possible way to determine if a device is connected is to actually send out some traffic, and see if you get a response.

\$\endgroup\$
7
  • \$\begingroup\$ To further clarify, my RS232 comm. is simply the rs232 Tx and Rx converted to TTL via MAX3232, and the line pulses when data is being sent or received, so how would detection occur, when the tx and rx lines keep pulsing? \$\endgroup\$
    – Siidheesh
    Commented Dec 27, 2012 at 9:46
  • \$\begingroup\$ Uh.... if the Rx is pulsing, something must be connected. If it's not pulsing, nothing is connected. \$\endgroup\$ Commented Dec 27, 2012 at 9:54
  • \$\begingroup\$ Yeah, so how do I get a stable logic 1 from the pulsing signal?... \$\endgroup\$
    – Siidheesh
    Commented Dec 27, 2012 at 10:07
  • \$\begingroup\$ Ok, it seems the Tx line of the RS232 is -10V when plugged in, and 0V when disconnected, it seems to pulse as well, but I should be able to figure out the threshold with an oscilloscope. All in all, you were right, thanks! \$\endgroup\$
    – Siidheesh
    Commented Dec 27, 2012 at 10:14
  • 3
    \$\begingroup\$ A simple strategy would be to detect USB, and assume RS232 whenever USB is not connected. \$\endgroup\$ Commented Jan 21, 2013 at 15:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.