Electrical – How to switch between usb host and slave mode on a micro usb programatically

androidftdiusbusb deviceusb-host

Is it possible to program some chip that can switch between USB host and slave mode over an single micro USB cable talking to an Android device?

It would be OK if there was a slight pause between the switch if we have to reconfigure the chip to reconnect to the Android.

I don't need to be connected in both modes at the same time.

Background:

I have a Android device that supports USB file transfer mode so I can pull files from my GNU/Linux laptop, so you connected to it from the PC where the android device is in slave mode. And you can attach to it with an OTG cable and the device is in master mode so I can attach a external keyboard.
I can switch between it by pulling out the cable and switching between them.

Even better would be to able to have both master and slave connected at the same time via the same cable. Ideally I could connect to a RasPI or some other programmable micro controller like Arduino. But I am not sure exactly.

Possible Solution

I found this note that uses a FTDI Vinculum II controller
https://www.ftdichip.com/Support/Documents/AppNotes/AN_323_VNC2_Host_to_Android_Open_Accessory_and_FT232.pdf but I don't understand it all yet. Does this look like a possible solution?

Any simple devices like rasberry pi that could be used?

Best Answer

Just like the chip in your phone, many (if not even most) of microcontrollers with USB interface can be programmed to be a host or a device, and could hypothetically even switch these roles. Exactly as your phone does!

A USB bus can't have multiple masters, so the "optional" goal of letting the phone be device to a PC and host to a keyboard is impossible to achieve on the same bus.

You really just want a bus switch compatible with USB signalling levels and speeds.

Since USB is such a large market, these things are produced by many IC manufacturers, for example Texas Instruments has a whole range of USB2 and USB3 switches; take the TS3USB30E as an example of a USB2 switch. Octopart tells me it can be had for little more than 1€.

functional diagram

So, you'd just wire up your connector going to your phone to the D+ / D- lines, the one going to your PC to the D1+ and D1- lines, and the one going to your keyboard to the D2+ / D2- lines.

To let the phone know that it's supposed to be in host mode, you will have to pull down its "ID pin" to ground (that's the fifth pin in a micro-USB connector). You can do that by means of yet another simple analog make-or-break switch (example).