0
\$\begingroup\$

What's the hardware and software detect mechanism of the Android cellphone Micro USB devices attached and detached?

schematic

simulate this circuit – Schematic created using CircuitLab

  • Hardware Schematic hardware sch

Fig1 is my application draft, and more details are as follows:

  1. My cellphone support OTG function and is enabled

  2. As the picture says, my device has connected the ID pin to the ground in order to get the power of 5V.

  3. I connect the D- pin to 5V so that it tells the phone this is a low-speed device.

  4. I have an APP installed on my phone to supervise if there is a device plugged in.

    My device is a non-standard USB device, I don't use the D+/D- pin to communicate with the phone

In my point of view, as soon as the device plugged in, firstly the ID pin of the micro USB receptacle get a falling edge and thus tell the phone there is a device plugin and the device is working as a HOST.

so, anybody familiar with the process of the detect?

I upload the PCB board photo so you can see clearly about my situation. the PCB board

update : I have measured the output of VBUS when I insert the device, and the VBUS=5V, also as a power indicator a LED is mounted on the PCB, it works well.

Ultimate question: If my hardware connect is right? and then can somebody give me some instructions about the software code?

\$\endgroup\$
4
  • \$\begingroup\$ You should explain what you want to achieve ultimately. It seems you want to be able to detect the plugging of a "dumb" (using passive components only) device on the phone from an application. Is that it? \$\endgroup\$
    – dim
    Commented May 29, 2018 at 10:35
  • \$\begingroup\$ I think you are right, the detection needs both hardware and software. now I basically confirm my hardware is correct, and then I need an appropriate software support@ dim \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 2:11
  • \$\begingroup\$ How do you determine that your phone does support OTG host function? \$\endgroup\$ Commented May 30, 2018 at 4:38
  • \$\begingroup\$ @AliChen my phone manufacturer has told this type of cell phone support OTG function.BTW, this is not my key point. My question is if the hardware is right, how to implement by code? \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 5:56

2 Answers 2

1
\$\begingroup\$

The simplified legacy OTG works in the following way.

Initial state: The OTG device/host (phone in this case) has ID pin pulled up, this is correct. VBUS is inactive, no voltage supply. ID = HIGH, VBUS = low.

CASE 1: a cable with u-B end is plugged in; the other end is Type-A plug, which goes into USB host (PC for example). In the u-B connector, the ID pin is floating. The phone senses two conditions: ID=HIGH, VBUS=HIGH (normal PC host supplies VBUS). The phone turns its software stack into device mode, will pull D+ up to 3.3V with a 1.5k resistor, and PC host sees the phone either as a mass storage device (old fashion), or MTP - media transfer protocol device.

CASE 2: a cable having ID-pin grounded is plugged in. The phone senses ID=LOW, and VBUS=don't care, normally low as well. This makes the phone to load the USB host software stack, which will turn the VBUS on, and act as a normal USB host. If the other end of a cable is connected to a device, it will pull-up D wire that corresponds to device basic speed.

In theory, the phone receptacle is supposed to be of micro-AB style, and the cable in case2 should have micro-A type shell (rectangular). But this is confusing for customers, and most manufacturers resort to using of u-B receptacle. The OTG swap is done by illegal micro-B plug, with illegally grounded ID pin.

In reality, in CASE1 there is a step of identifying charger signature before the data connection occurs, but this is a different topic.

So, basically, you got it right.

\$\endgroup\$
6
  • \$\begingroup\$ Thanks a lot! My connect is as your case 2. But my problem is the phone doesn't detect my device(as long as I insert my device my APP has got no notification). I have read this variable 'android.hardware.usb.action.USB_STATE or UsbManager.ACTION_USB_DEVICE_ATTACHED ' \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 0:43
  • \$\begingroup\$ @lukeluck, what is "your device"? What kind of cable of connector does it have? \$\endgroup\$ Commented May 30, 2018 at 1:31
  • \$\begingroup\$ my device has no cable the micro USB plug is welded on the PCB as I update the pic. \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 1:37
  • \$\begingroup\$ In your case2 The phone senses ID=LOW, and VBUS=don't care, normally low as well. This makes the phone to load the USB host software stack, which will turn the VBUS on, and act as a normal USB host. does process produces a notification, if so my app can use the state change? \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 2:17
  • \$\begingroup\$ @lukeluck, first you need to check if your phone is working as host. Does it output VBUS when you plug your device in? Does it work with a regular mouse if you use so-called "OTG adapter"?, something like this, gearbest.com/chargers-cables/pp_366686.html \$\endgroup\$ Commented May 30, 2018 at 4:37
0
\$\begingroup\$

I connect the D- pin to 5V so that it tells the phone this is a low-speed device.

Bad idea. The data pins are actually only allowed to reach 3.6 volts maximum. You are supposed to connect the 1k5 resistor to a 3.3V source.

as soon as the device plugged in, firstly the ID pin of the micro USB receptacle get a falling edge and thus tell the phone there is a device

Correct.

and the device is working as a HOST.

Nope. The resistor on D+ or D- is on the DEVICE side. The host side is supposed to pull both data lines down with about 15kOhms.

I have an APP installed on my phone to supervise if there is a device plugged in

That app won't receive anything unless I am missing something.

One can observe a non-conforming device attach in the dmesg output of the Linux kernel, but the app would only be notified when the device identified itself over USB (sending descriptors).

\$\endgroup\$
3
  • \$\begingroup\$ Thanks a lot! In my situation, I connect D- pin to 5V via a 1.5k pull-up resistor,and I measured the voltage of D- pin is about 3.5V.In your advice a 1.5k resistor with a 15k pull-down resistor makes the voltage of D- pin got 3V,so when I adjust my 1.5k to 10k and I can get 3V on D- pin as your case. Is this ok? \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 0:50
  • \$\begingroup\$ because of my device does not support USB communication, I only use the phone micro USB receptacle to output the 5V power to my device. In my device, the D- pulled up to 5V, and D+pin is floating. My question is why these voltage change(ID and D- pin voltage change) cannot cause the phone to detect a device plugin. I think these signals is enough for the android.hardware.usb.action.USB_STATE to toggle. I don't need the host and device to communicate with each other. @Turbo JCan you give more advice? I just need a viable toggle when the device is plugin don't care the kind of the USB device \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 1:05
  • \$\begingroup\$ link This link gives the detect process, but in my situation it seems doesn't work, can you give some advice? \$\endgroup\$
    – lukeluck
    Commented May 30, 2018 at 2:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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