2
\$\begingroup\$

I have two computers, a USB keyboard and a USB mouse. I want to build something that lets me switch the USB devices between the two computers. My approach would be to buy a new powered USB hub and plug the keyboard and the mouse into it. Then, I would use a microcontroller to control transistors for the DATA- and DATA+ lines to the two PCs (so four transistors total). I would just short all the GND wires (from the powered hub and the PCs) – that shouldn't do any harm, right? – and leave the +5V wires from the PCs unconnected. As far as I can see, that should work fine for switching.

However, how would the PCs (or the powered hub?) know when to do a new handshake and so on? Is it sufficient to have the +5V wire to the USB hub high by default and pull it to GND while switching? Would the USB hub initiate a handshake or something when its USB +5V wire goes up?

Also, how would the other PC find out that it has just lost the connection? By checking whether there's a voltage between Data+ and Data-?

\$\endgroup\$
  • 2
    \$\begingroup\$ The USB standard is freely available and well worth reading if you're going to attempt this. \$\endgroup\$ – pjc50 Apr 26 '13 at 17:51
4
\$\begingroup\$

What you're looking for is called a "KVM switch" (keyboard, video and mouse), you just don't need the video part. These are commonly available and easy to find once you know the correct term.

But to your specific question about USB enumeration: Every USB device has a pullup resistor on one of the Data lines (one for low-speed devices, the other for all others). A USB host or hub recognizes the presence of this resistor and initiates enumeration when it appears.

\$\endgroup\$
  • 1
    \$\begingroup\$ There are also plain USB switch boxes which have no video functionality and might be cheaper than a full KVM switch. \$\endgroup\$ – Kevin Reid Apr 27 '13 at 15:51
  • \$\begingroup\$ Does the Usb hub raises an interrupt? How does the hub notifies about the new USB? \$\endgroup\$ – KYHSGeekCode Mar 8 at 7:48
  • 1
    \$\begingroup\$ @KYHSGeekCode: The USB host is constantly polling for status, every millisecond, IIRC. \$\endgroup\$ – Dave Tweed Mar 8 at 12:22
2
\$\begingroup\$

USB uses polling to enumerate, and detect when a device is lost. If the usb slave device does not respond in a certain time frame, the usb connection is lost, even if the device is not unplugged.

See usbtiny and v-usb for software usb implementations for the amtel brand microcontrollers.

\$\endgroup\$
0
\$\begingroup\$

You can use a FSUSB30MUX. It has 2 x SPST switches to switch the data lines between two ports.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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