Author Topic: USB Micro connectors and software interfacing  (Read 6514 times)

Doug D.

  • Member
  • ***
  • Posts: 16
USB Micro connectors and software interfacing
« on: February 24, 2018, 01:03:16 pm »
Hello Jan,

I was wondering if you could help me with a couple of basic USB questions.  I have the Third Edition of USB Complete, and I'm trying to design a battery-powered USB 2.0 Full Speed (device-only) that communicates with an Android tablet.  The tablet would act as host and send periodic data requests, and the device would respond with the latest data.  My Samsung tablet has a Micro-B receptacle, and for size and durability I'd like to use a Micro receptacle on the device as well.

Is this possible?  I'm assuming I can get my tablet to work as an OTG host somehow, but I can't find Micro-B to Micro-B cables.

My second question is about communicating with the device.  It uses a PIC microcontroller, and I was considering implementing it as a Mass Storage Device (MSD class).  My rationale was to be compatible with any host that can see a USB thumb drive, without needing a separate device driver for every different device.  I'm wondering if it would then be possible to use a web browser or an app to communicate by reading and writing to virtual files on the device's virtual disk drive.

Does this sound reasonable?  How would you approach this?

Thanks,
Doug


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Micro connectors and software interfacing
« Reply #1 on: February 24, 2018, 08:04:47 pm »
First you need to find out if the tablet supports host mode. If so it should have a micro-AB receptacle:

https://www.gradconn.com/Products/MicroUSB

Since you want to use a mass-storage device, one way to test would be to attach a flash drive, using a series-A-to-micro-AB adapter:

https://www.bestbuy.com/site/insignia-otg-on-the-go-micro-usb-to-usb-type-a-adapter-cable-black/4644300.p?skuId=4644300

If that checks out, you can access the device in any way you can access other mass-storage devices, for example:

https://stackoverflow.com/questions/32201169/how-app-can-access-files-on-usb-otg-storages-in-android-6-0-api-level-23-witho

Also see

http://janaxelson.com/forum/index.php?topic=1351.msg6091#msg6091




Doug D.

  • Member
  • ***
  • Posts: 16
Re: USB Micro connectors and software interfacing
« Reply #2 on: February 24, 2018, 09:25:45 pm »
Jan,

Thanks very much for your reply.  I tried your flash drive test suggestion, and it worked like a miracle!  I could even use my tablet to play MP3 files that were on the flash drive.

I double-checked my Samsung Galaxy Tab 8.0 A USB port, and confirmed that it has a D-shaped receptacle shell, not a rectangular shell.  So apparently a Micro Type-B OTG host can talk to a Type-A device.  Are things supposed to work like that?  I thought hosts had to be Type-A.

Regarding USB cable availability, since my tablet has a Micro Type-B receptacle, does this mean I need to design in either a Micro Type AB receptacle or a full-size Type A receptacle, in order to get cables for my microcontroller project?

Doug

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Micro connectors and software interfacing
« Reply #3 on: February 25, 2018, 12:38:26 pm »
Apparently some devices are using micro-B receptacles instead of the required micro-AB on OTG ports:

https://electronics.stackexchange.com/questions/242619/why-do-most-usb-otg-dual-role-devices-use-micro-b-connector-instead-of-micro-ab

Because your tablet will not accept a micro-A plug, you will have to use an illegal (but available) micro-B-to-micro-B cable to attach to that host.

Doug D.

  • Member
  • ***
  • Posts: 16
Re: USB Micro connectors and software interfacing
« Reply #4 on: February 25, 2018, 02:14:19 pm »
Thanks--I'm surprised this isn't more widely known.  Would putting a (full-size) Type-A USB hub between the Micro-B OTG tablet and the Micro-B device work?  If so, is there any reason I couldn't use two Type-A to Micro-B cables to connect them through a powered hub?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Micro connectors and software interfacing
« Reply #5 on: February 25, 2018, 09:18:01 pm »
Embedded hosts (like the tablet) may, but are not required to, support hubs. Again you can check by trying it out with a flash drive.

But the hub will have a series-B or micro-B receptacle on the upstream side so you would still need a B-to-B cable to connect to the tablet.


Doug D.

  • Member
  • ***
  • Posts: 16
Re: USB Micro connectors and software interfacing
« Reply #6 on: February 26, 2018, 09:24:20 am »
Yes, I forgot that hubs still need a -B receptacle to connect upstream; that -A receptacle devices connected to a hub don't talk to each other.

How about putting a micro-AB receptacle on the device?  I was able to find (just) a few micro-A to micro-B cables made in the UK and on Ebay.  Although it goes against the convention that any device with an AB connector must function as an OTG device, are there practical issues with putting a micro-AB receptacle on my device, and using one of these cables to connect to the micro-B receptacle on my OTG host tablet?

Regarding micro-B to micro-B cables, I saw a single comment from someone claiming that "serious damage to the USB controller is possible if you plug two ends of a USB A-toA cable to two USB ports on a host device".  But I can't see why this would be true.  The ~5VDC VBUS and ground potentials should be the same at two USB ports on the same host, and the D+ and D- lines use pull-up and pull-down resistors that should limit the current.  And as you mention in your wonderful book, "At any speed, the components that connect to a USB cable must be able to withstand the shorting of any line to any other line or the cable shield without component damage."

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Micro connectors and software interfacing
« Reply #7 on: February 26, 2018, 11:30:41 am »
Micro-AB receptacles allowed only on OTG devices isn't a convention, it's a USB-IF requirement, if you need to care about such things.

In a micro-B plug, the ID pin has 100k resistance to ground. If you are using a micro-AB plug on a USB device (not OTG), you should provide that resistance on the device to emulate a micro-B so the tablet doesn't think it's attaching to an OTG host.

The specs also allow using a "captive cable" on a device, which can be a vendor-specific connector or hard-wiring of the cable to the device.

USB cables and cables are designed to be damage-proof when used as specified. I can think of no reason to connect two ends of an (illegal) A-to-A cable to one host.




Doug D.

  • Member
  • ***
  • Posts: 16
Re: USB Micro connectors and software interfacing
« Reply #8 on: February 26, 2018, 09:28:02 pm »
No, I'm not bound by USB-IF requirements.

When you say to pull the ID pin low with 100K at the device, you mean if I was using a micro-B to micro-B cable, right?  If I were to plug the "micro-A" end of a micro-A to micro-B cable into my device's micro-AB receptacle, then the ID pin would already be shorted to ground inside this plug, wouldn't it?

I used to think there was a separate ID wire going through the cable, and I couldn't understand how one end could be shorted, while the other end was left floating!  But now I understand that the ID pins are isolated, and their resistance to ground is what tells the connected host or device whether it should act as a host or a device.  Incidentally, I happened to see this Engineering Change Notice that increases the "floating" ID pin resistance from >100K Ohms to >1M Ohms:

"Specification Changes:
In Section 4.2 after Table 4-2 change:
The ID pin on a Micro-A plug shall be connected to the GND pin. The ID pin on a Micro-B plug is not
connected or is connected to ground by a resistance of greater than Rb_PLUG_ID (100kΩ MIN).
To:
The ID pin on a Micro-A plug shall be connected to the GND pin. The ID pin on a Micro-B plug is not
connected or is connected to ground by a resistance of greater than Rb_PLUG_ID (1M Ω MIN)."

I'm designing with a PIC microcontroller with USB OTG capability.  It can operate either as an embedded OTG host, or as a device.  I see that it has an internal pull-up resistor on the ID pin--if the ID pin isn't shorted by a connected micro-A plug, then it will go high and tell the PIC to be a host.  But I don't see anything to pull it low, so I will take your advice and pull it down.  Thank you so much for this warning.

What would happen if I simply shorted the ID signal to ground on my USB device?

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Micro connectors and software interfacing
« Reply #9 on: February 27, 2018, 10:41:22 am »
1M, correct.

The resistance on the ID pin tells the device that it is the B-device (until negotiation changes it). Exactly how that is implemented varies with the device architecture as specified in the data sheet.

I was assuming your device was a device only, not OTG.

If your device has a micro-AB, it should be able to function as a host or device. If it has only the device function, it should use a micro-B (if you want to be compliant).

If the cable has two micro-B plugs with the ID pins wired differently, you will need to keep track of which plug goes where.


Doug D.

  • Member
  • ***
  • Posts: 16
Re: USB Micro connectors and software interfacing
« Reply #10 on: February 27, 2018, 12:06:39 pm »
My hardware design can only take power from VBUS (or from batteries, if at higher voltage).  It can't provide power to VBUS, so I'd need a 5V USB power injector for it to be an OTG host.  I would like to modify the firmware to do this in the future, but for now it will just be a USB device-only.  I won't want to have to change the hardware.

I meant shorting the ID signal on my OTG device, not the ID pin of a micro-B plug.  If I am able to add the host capability later, then I could simply stop populating the shorting jumper on my board.

Until then, it seems I have a choice--either to use legal micro-B receptacles and illegal micro-B to micro-B cables, or to use "illegal" micro-AB receptacles and legal micro-A to micro-B cables.  I think the legal micro-A to micro-B cables are more available.

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: USB Micro connectors and software interfacing
« Reply #11 on: February 27, 2018, 09:03:17 pm »
No perfect choice.

Doug D.

  • Member
  • ***
  • Posts: 16
Re: USB Micro connectors and software interfacing
« Reply #12 on: February 28, 2018, 03:45:19 pm »
Thank you very much for your help Jan!

I may have a few more questions for you when I get to the Android and Windows programming stage ;-)

Doug