Electronic – How to detect RS232 and USB connectivity

picrs232usb

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?

Best Answer

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.