USB power negotiation?

Is there any way to perform USB power negotiation with an Arduino? For example, request 200 mA and if that fails request 100 mA?

If that's not possible, I can think of a workaround if I can define USB_CONFIG_POWER in the sketch before it is compiled. Is that possible, or can USB_CONFIG_POWER only be set in the core files?

Power doesn't work like that, the powered device takes the current it needs, the power supply supplies it. If the power supply can't supply it then it takes action to limit the current, typically lowering the voltage or turning the output off altogether. You can't expect to have unvarying 5V and have the power supply change the current, the only control the power supply has over current is changing the voltage.

See Ohm's law - Wikipedia

I've moved this to general electronics.

Thanks for moving the topic. This may be related more to the USB core, though?

I see that I worded the question incorrectly-- is there a way to query the maximum power available from a USB host before enumeration so I can tailor the device power request and change the power consumption of my device?

Here's some more context: I'm making a battery-powered device that also enumerates as a USB device. I'd like to charge the battery from USB if the host will allow 200 mA, and not charge the battery (only power the device) if the host won't allow more than 100 mA (e.g. iOS). It was my understanding that this is possible with USB-C(?).

If this isn't possible, is there a way to set USB_CONFIG_POWER in my sketch instead of in the USB core? That way I could let my users select charging/not charging for the next time the device is powered up.

If you can suggest a better category I am happy to move the topic for you.

Ah, OK, I think you are now asking a very different question. I cannot answer the question as you have now phrased it, maybe someone else can.

All of the existing native USB Arduinos are USB 2.0 devices, so they could only negotiate power up to 500mA (using official USB specs. Various third parties (such as Apple) have implemented hardware indicators of higher power, but those are hardwired and not subject to negotiation.
Most chargers and hosts don't really care about the fact that USB devices are only supposed to draw 100mA unless they specifically negotiate higher power, and are safe to provide 500mA (or somewhat more) regardless.

The "USB Power Deliver Specification" that permits much higher power (up to 100W! (or more, with the latest spec. Terrifying!)) is a USB 3.1/USB-C thing. It uses a separate signal for the power negotiation phase, usually handed by a separate chip that is part of the device power supply (higher currents use higher voltages (100W is 5A @ 20V), so you don't want a host delivering that on the USB cord until AFTER the negotiation says it's OK...)

All USB, by spec, can supply either 500mA or 2A. All hosts allow the full 200mA that most boards take. This is a non issue.

I’m 90% sure iPhones will only supply 100 mA (one unit load) when in host mode, unless that’s changed very recently (older ones only supply 20 mA). The vast majority of my users are on iPhones, hence why it’s an issue for me.

USB works this way:
assume USB is a device (on MCU) and connected to host: the host will query the USB device. It is called "enumeration": the PC (host) queries the USB device descriptors.
So, the device (the MCU as device) has the setting how much it wants to get from host.

When the PC queries - the device sends it enumeration descriptors, including an entry for the current requested.

Max. is 500 mA (on regular USB, USB2).
When device descriptors tell host, the device wants to draw more current: the host might reject.
I think, you can configure USB on PC (as host), how much current they will provide (and when PC would deny to connect am USB device).

Even you use a powered USB hub: it can be still the issue that PC as host gets the USB device "enumeration" and sees more as 500 mA requested. Even hub could power - the host will not accept (host USB capability matters, PC has no clue if a powered hub is in between).

USB-C can provide more current: but if you have a USB-C to USB-A cable (not a native USB-C to USB-C) - the USB-A on host PC remains limited to max. 500 mA per USB port.

I think what I will do is only charge when connected to a “dumb” charger, i.e receiving 5V but not enumerated. It doesn’t sound like there’s a way to request 100 mA when connecting to some hosts and 200 when connecting to others.

Ah. An unusual use case! I know nothing about phones as hosts.

It doesn’t sound like there’s a way to request 100 mA when connecting to some hosts and 200 when connecting to others.

Huh. While the USB host requests all sorts of information from the Device, I don't recall seeing anywhere that the host PROVIDES any information TO the device.

You could probably request 200mA, and re-start enumeration if that is turned down?

I would argue this way: "iDevices do not allow to connect foreign external devices", esp. not with so much current requirements.

And:
A smart phone, like iDevicePhone, can limit the. max. external current possible to be drawn by external USB devices, e.g. just 100 mA (compared to typical 500 mA on a stationary laptop/PC).
iDevice manufacturer does not want (and does not "allow" you) to drain current from internal battery in such a way (obvious).

Story:
A friend of mine was running a company, providing (external) HW for digital TV reception (on iDevices). It was an external HDTV dongle (like an USB device), draining current from iDevices (internal battery).
He got a law suit: there claim was: "you are NOT allowed as uncertified third party accessory company to drain ANY current from iDevices".
So, even technically the iDevice manufacturer will potentially limit the current you can drain from iDevices - check if it is "legal" (potentially not, and the original designer of iDevices prohibits and limits the current you can request from external (USB) devices).

Mobile devices are a separate topic: potentially, they do not allow any external USB device to draw so much current (for sure, not 500 mA, I would not allow and not support as a phone manufacturer, the battery would die just because of "foreign HW connected").

I would think Apple would be okay with connecting external devices as they sell the adapter to allow it—I’m more than happy to limit consumption, though.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.