I want to connect a microcontroller to my smartphone through its(smartphone) only available micro USB port, and at the same time enable charging and data sync capability of the phone with the PC or other external devices through another micro usb port.

I know there are micro usb hub available in the market but the problem with them is that I can not connect a PC (to any of the hub's downstream ports) to charge and sync data through a downstream port simultaneously.

So I was thinking to add a microcontroller with 2 USB channels in the following way. enter image description here

So I was looking for a feedback/suggestion on (1) Whether the microcontroller could be programmed in such a manner so that it could pass data from one USB port to another identifying the type(host/otg) of device connected to it? (2) For charging the smartphone can a microcontroller with inbuit battery detect/charger feature could be used for the same?

  • \$\begingroup\$ I'm voting to close this question as off-topic because it unavoidably depends on details of unspecified and potentially undocumented synch protocols of an unidentified consumer product \$\endgroup\$ – Chris Stratton Aug 20 '18 at 16:57
  • \$\begingroup\$ @ChrisStratton, the Android OTG function is present on pretty much all smartphones. The complexity of the rest is outlined in my answer, there is no need on any particular details. \$\endgroup\$ – Ale..chenski Aug 20 '18 at 18:37
  • \$\begingroup\$ @AliChen - Nothing in the question says it is about Android. But if it is, then it's all but unanswerable as Android infamously lacks a traditional USB data synch mechanism. OTG, of course has absolutely nothing to do with synching with a PC, and in fact is an operating mode mutually exclusive with doing so. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 18:42
  • \$\begingroup\$ @ChrisStratton, I don't know what the "data synch" means, nor do I care. In any case this is something high in application level of network model. I am merely addressing difficulties in basic USB transport level, whether "it could pass data from one USB port to another", I don't care much what kind of data the OP wants to transmit, it is inconsequential. If one can't provide clear transport level, the concerns about poorly-defined higher levels make no sense, your concern makes no sense at all. \$\endgroup\$ – Ale..chenski Aug 20 '18 at 20:24
  • \$\begingroup\$ @AliChen - the point (and reason the question must be closed if not edited) is that even after investing in hardware, the poster still won't be able to meet their goal, or even determine if their goal is achievable at all until they identify and study the actual traffic to be moved. If this were transparent pass through, they wouldn't need USB interfaces at all but merely a wire or USB A/B switch chip. Instead it is combining distinct streams, and we have no evidence that their phone platform permits that. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 20:52

This only works for USB 3.1 Type-C.

All older USB types do not support this. Since the phone must be Host to use OTG, and Device to charge.


  • \$\begingroup\$ Even then, it still won't work, as the asker wants the USB port to operate in two data roles at once and that just isn't possible. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 16:53
  • \$\begingroup\$ @ChrisStratton Type C is capable of this, see all the laptop docks with Type C. \$\endgroup\$ – Jeroen3 Aug 20 '18 at 17:50
  • \$\begingroup\$ no, it's not. In a laptop dock, the laptop may be receiving power, but in terms of data it is only being a host. Here, the phone needs to be both a host and a device at the same time, and that isn't supported. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 18:54
  • \$\begingroup\$ @ChrisStratton The type-c docks offer USB hub/HDMI out and have the charger input. Laptop will charge through the dock. Dock is a device, with power delivery. \$\endgroup\$ – Jeroen3 Aug 20 '18 at 18:57
  • \$\begingroup\$ You are still confusing power and data. Irrespective of power flow, in terms of data, the laptop is only a USB host. But the asker here needs the phone to be both a USB host and a USB device at the same time. And that's not something USB supports - it can be either of these things at different times, but not at the same time. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 18:58

Yes, it can be done, theoretically, under certain "boundary conditions".

A smartphone with USB micro-B port should support the standard OTG function, with ID pin that controls the data direction of the smartphone. This standard function also simultaneously controls the direction of VBUS: in host role the VBUS is supplied (therefore no charging), and in device mode the phone will accept charge.

If you need to have the roles "mixed" up (get the phone to be charged while in host mode), the phone must support this feature called "accessory charging mode". The mode should be engaged if the ID pin impedance to ground is 20k or 120k. So the upstream link must conform to "accessory charger mode". This is regarding the second part of the question.

Regarding the first part, you have to have a sizable MCU like 32-bit STM32, with two (!) USB OTG controllers (since you indicate the bottom link as "USB Upstream/Downstream" as well. This means that MCU must have FOUR controllers, two of HOST type, and TWO of device type. I am not sure if such a monster does exist.

For the "upstream" OTG link you will need to have two GPIOs to control the state of ID pin (grounded, floating, or 120k), which will need some analogish circuitry. To transmit this information from your MCU to phone, you will need a proprietary 5-wire cable, with ID pin connection. These cables only exist for automated testers. And then write software to control the mode.

Then you will need to write a ton of bridging software to manipulate all four controllers in accord, and channel the data. You will need to decide on (invent and implement) internal communication protocols, depending to what extent do you want the devices to be transparent to standard USB framework. So one-two years of work for a team of USB architect, a hardware engineer, and a software engineer, and you are done. Good luck.

  • \$\begingroup\$ MCU's with two USB ports each of which can be either a host or device are not all that uncommon (the spec sheets would not refer to them as having four interfaces, but rather two dual-role interfaces). However, this is unlikely to be practical as implementing a pass through for the various modes is rather complicated. Further, the question is off topic here until those modes can actually be specified. It's by no means clear that the phone OS will allow multiplexing anything with the unspecified synch protocol. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 16:56
  • \$\begingroup\$ @ChrisStratton, would you care to provide a name/link to any processor with TWO OTG interfaces? Your uncanny contribution will be much appreciated. Regarding "unlikely to be practical as implementing a pass through for the various modes is rather complicated", isn't my entire answer is all about the project being hugely complicated? \$\endgroup\$ – Ale..chenski Aug 20 '18 at 18:43
  • \$\begingroup\$ The point you're missing is that it's not clear that there's any phone with an openly documented protocol for generic PC data synch - android for example notoriously lacks this, so if the poster means mass storage or PTP or something then they need to say explicitly that, otherwise presumably they mean something that does have a data synch mechanism, albeit proprietary, like an iphone or maybe some non-standard vendor-specific extension of Android. As for processors, the STM32F407/417 are an obvious example. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 18:51
  • \$\begingroup\$ @ChrisStratton, obvious example? Do you call a 20-years-old FS (12 Mbps) interface as USB interface? Are you joking, right? You can't transfer any modern files with that in a reasonable time, yet to "data sync" anything. So, there is no real MCU with two OTG. Even the Chinese "Allwiner H5", a full-blown quad-core processor for phones and tablets, has ONE OTG (although 3 hosts), androidtvbox.eu/… \$\endgroup\$ – Ale..chenski Aug 20 '18 at 20:16
  • \$\begingroup\$ Since the asker still hasn't specified what they want to do in the way of sync or even the phone OS, we don't know that full speed is unsuitable. Since you want to make this about Android, I'd point out that just about every "DIY I/O gadget connected to Android" project has been full speed, especially where the gadget had to play the host role. Even with dual high speed interface (vs the one high speed interface that that STM32 has along with its full speed one), it's doubtful that a microcontroller (vs. a system on a chip) could juggle data between fast enough to leverage that. \$\endgroup\$ – Chris Stratton Aug 20 '18 at 20:56

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.