12
\$\begingroup\$

I've got a Full speed USB device which I want to provide 2 ports for - one each on opposite ends of the enclosure. This is so the cable can be connected wherever is most convenient. My MCU (atmega32u4) has only one interface, so the physical ports will shared, but only one should be plugged in at one time.

Of course users can't be trusted to not plug in both sides at once. How to protect against this?

Ideas I've come up with:

  • Just wire them up "as-is" and hope the host can deal with joined D+/D- pins
  • NAND gate with separate 5V pins as input, output to a MOSFET that disconnects Vcc when both are plugged in.

Does the second option sound reasonable, or is a more complex solution required?

\$\endgroup\$
  • \$\begingroup\$ How do you propose wiring the two ports to connect D+ and D- together? You should add a diagram explaining the layout you propose. \$\endgroup\$ – Solar Mike Sep 16 '18 at 7:23
  • \$\begingroup\$ @SolarMike Shared between the two - in the "correct" scenario, with only one cable connected, the other connector's D+/D- will be left dangling. \$\endgroup\$ – monty Sep 16 '18 at 8:58
  • 7
    \$\begingroup\$ You should also consider designing the case with a moving cover so that only one usb port is exposed at once. That way you clearly communicate to the user that they are only allowed to plug in to one of the ports at once instead of confusing them when they plug in two hosts and one doesn't work. \$\endgroup\$ – Nonny Moose Sep 16 '18 at 13:48
  • 4
    \$\begingroup\$ don't forget about the user who manages to find a male-male usb cable and plugs the device into itself !!! \$\endgroup\$ – RozzA Sep 16 '18 at 21:59
23
\$\begingroup\$

As pointed out, you can't directly connect two hosts to a device - so if you just wired them together and somebody plugged it in on both ends, you'd have a problem.

However you also have a problem if only one end is plugged in. USB, especially high-speed (480Mbps) mode is controlled impedance. If you wire both connectors data lines together you end up with what is known as a stub in high frequency design. The cable going to the unused connector will degrade the performance of the active connector.

To do this properly, you want a multiplexer IC. You can buy dedicated USB2.0 multiplexers designed specifically for this sort of application - something like the TS3USB30. That would allow you to connect the data lines from both ports to the mux inputs, and connect the output to your device internally. The mux will disconnect the unused connector which will disconnect the transmission line stubs.

For power I would probably use a power multiplexer such as a diode OR-ing circuit. The VBUS line from one of the ports (before the power multiplexer) can then be used as the input to the data multiplexer.

Ground would be common (connected) between the two USB ports and your device.

\$\endgroup\$
  • 1
    \$\begingroup\$ I didn't consider the stubs - that multiplexer (combined with power multiplex) looks ideal! \$\endgroup\$ – monty Sep 16 '18 at 9:16
  • 3
    \$\begingroup\$ Stubs shouldn't be a problem at Full Speed, which is all you asked about in your question. \$\endgroup\$ – Dave Tweed Sep 16 '18 at 12:45
  • 1
    \$\begingroup\$ @DaveTweed I added the Full Speed clarification after I realised this answer covered High Speed. Knowing I can "get away with it" is good for this design, but I definitely appreciate knowing the implications at higher speeds. \$\endgroup\$ – monty Sep 16 '18 at 15:08
  • \$\begingroup\$ Now I'm genuinely interested how to make atmega32u4 support 480Mbps :) \$\endgroup\$ – Dmitry Grigoryev Sep 17 '18 at 7:15
9
\$\begingroup\$

Multiplexer as suggested by Tom Carpenter is a good solution.

But for full speed USB (12 Mbps), the stubs in the signals are not particularly important. If the distance between the stub ends remain below 1/10th of wavelength, i.e. below ~2 meters, the reflections will not distort the waveform much.

Also, the voltage levels on D+ and D- pins will remain within the acceptable range, so there is not much risk of electronic damage to either host.

The main problem that remains is if you connect the +5V pins from both hosts together, there could be large currents involved. You could use a diode from each USB connector's +5V pin to only let current come in, never out.

\$\endgroup\$
4
\$\begingroup\$

The lazy electronical design way would just be to use a physical multi connector switch to choose between which one is used.

Note that this would have the added benefit of being able to leave them both plugged in and use the switch to select which input is to be used.

\$\endgroup\$
2
\$\begingroup\$

There is no USB compliant way of doing this. USB is not designed to be shared between two hosts and attempting to do so will lead to potentially disastrous situations.

At best, you can use a USB multiplexer or switch IC, with GPIO to determine which connector is connected. You'll have to decide which USB connection has precedence, because both cannot be connected to your USB interface at the same time.

Or look at alternatives. Have one computer communicate to the other. Or use Bluetooth or use Wi-Fi or a different connection type.

\$\endgroup\$
  • \$\begingroup\$ I've added clarification to the question - only one port will ever be used at once, and (hopefully) the NAND gate can solve the precedence issue by simple denying the "both plugged in" scenario. \$\endgroup\$ – monty Sep 16 '18 at 8:56
  • \$\begingroup\$ What kind of disastrous situations do you think it could lead to? \$\endgroup\$ – jpa Sep 16 '18 at 11:59
  • 1
    \$\begingroup\$ @jpa suppose the two systems have "ground" potentials that are 50V different, for example. Connecting them both to D- could be "interesting". Even if the potentials are only 50mV different, you may have created a noise-generating "ground loop". \$\endgroup\$ – alephzero Sep 16 '18 at 13:07
  • 1
    \$\begingroup\$ @alephzero Sure, but even a typical multiplexer or switch IC wouldn't handle that. The ground connecting first in USB connector, however, mostly eliminates that problem. \$\endgroup\$ – jpa Sep 16 '18 at 14:14
2
\$\begingroup\$

I have a Wacom tablet with this feature. They handle the problem you're describing by using a mechanical interlock.

There's a plastic slider that blocks one port, or the other, depending on it's position.

enter image description here

\$\endgroup\$
1
\$\begingroup\$

Perhaps it would be easier to leave the USB connector at one side of the enclosure and duplicate and / or relocate all other user-facing elements symmetrically. Then the enclosure can be rotated so that the USB port is facing the connector, while all other elements are still conveniently accessible.

Another option is to locate both ports on one side of the enclosure (at the opposite ends) and add a sliding stub inside the enclose which the user can move to open one port or the other. 12 MHz USB has a good chance of working with an extra disconnected port attached to it.

\$\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.