198

USB specifies 4 pins:

1.   VBUS   +5V
2.   D-     Data-
3.   D+     Data+
4.   GND    Ground

Why is this not 3? Could the Data and Power not share a common ground? Am I correct in understanding that D- is the ground for D+?

RoyC
  • 8,418
  • 6
  • 25
  • 40
Mark Harrison
  • 10,419
  • 27
  • 68
  • 95
  • 10
    Just so you know: There are single-wire protocols where even +5V and data is the same. It won't be fast and interference-safe, but for some applications, less wires is a true net win. Others, like USB and Ethernet, add wires to get more power and data across. – Macke Sep 27 '11 at 12:34
  • 16
    Wow, this is a surprisingly popular question! – Rocketmagnet Apr 11 '12 at 11:56

8 Answers8

309

No, D- is not ground. Data is sent over a differential line, which means that D- is a mirror image of D+, so both Data lines carry the signal. The receiver subtracts D- from D+. If some noise signal would be picked up by both wires, the subtraction will cancel it.

enter image description here

So differential signalling helps suppressing noise. So does the type of wiring, namely twisted pair. If the wires ran just parallel they would form a (narrow) loop which could pick up magnetic interference. But thanks to the twists the orientation of the wires with respect to the field changes continuously. An induced current will be cancelled by a current with the opposite sign half a twist further.
Suppose you have a disturbance working vertically on the twisted wire. You could regard each half twist as a small loop picking up the disturbance. Then it's easy to see that the next tiny loop sees the opposite field (upside down, so to speak), so that cancels the first field. This happens for each pair of half twists.
A similar balancing effect occurs for capacitance to ground. In a straight pair one conductor shows a higher capacitance to ground than the other, while in a twisted pair each wire will show the same capacitance.

enter image description here

edit
Cables with several twisted pairs like cat5 have a different twist length for each pair to minimize crosstalk.

stevenvh
  • 145,145
  • 21
  • 455
  • 667
  • How did you do that diagram? Which drawing package? – pjc50 Sep 26 '11 at 12:59
  • 6
    @pjc50 - Actually, I picked it up from [Wikipedia](http://en.wikipedia.org/wiki/Differential_signaling), but if I had to draw it myself I'd use Adobe Illustrator. – stevenvh Sep 26 '11 at 13:06
  • 17
    @pjc50 or Inkscape, which is the most popular (and really valid) free software alternative – clabacchio Feb 24 '12 at 09:51
  • @pjc50 - Illustrator for the first one :-) – stevenvh Sep 12 '12 at 15:14
  • 2
    Well, I'm new in electronics. I want to ask you, if the noise was only on the D+, how it could be cancelled? So, I'm saying, is there a situation which the noise is only on the D+ or D-? – Enes Unal Sep 17 '12 at 08:59
  • 6
    @Enes - That will be negligible due to the symmetry of the wiring: if you take an arbitrary length of wire you can't tell on sight which is `D+` and which is `D-` (apart from the color coding, of course). That means both `D+` and `D-` will be exposed to the disturbance in the same way. And when the noise is the same on both subtracting will cancel it almost completely. – stevenvh Sep 17 '12 at 09:08
  • @pjc50: You can use PSTricks or TikZ. – kiss my armpit Oct 27 '12 at 10:33
  • 4
    @EnesUnal An interesting point about twisted pair cable is that neither wire is permanently closer to the noise or interference than the other wire. Ref : http://www.techtionary.com/members/slides/u/unbalun.swf – C-- Jan 01 '13 at 06:44
  • This setup also lets you substitute power from a separate power supply into the line without any risk to the data lines. E.g. a powered USB hub can pass through data and replace GND/+5V, and not worry about having to maintain the same ground potential as the source device or create ground loops. – Jason C Jul 17 '14 at 15:30
  • So why not just run ground + a single data wire in a twisted configuration? Would that not cancel the noise on the data wire (relative to ground) just as well? – Thomas Jan 26 '17 at 09:09
  • @Thomas: No, it wouldn't. Any time you use the same pin as both return current and voltage ground reference you potentially have problems. Look up a four wire ohmmeter and consider how the concept applies to USB. – Ben Voigt Mar 11 '17 at 21:43
61

It's a differential (or balanced) signal, rather than a single ended (unbalanced) signal.

This means the receiver "measures" the voltage between them, rather than between one and ground.
Say D+ is at 2V, and D- is at 1V. Now say the wire picks up some external noise (RF, mains hum, etc) It is very likely that both cables will pick up the same noise signal since they are twisted together and of the same impedance.
Say we pick up 50mV of noise. So now D+ has 2050mV on it, and D- has 1050mV - the difference between them is still 1V (1000mV) though, and this is what the receiver will "see".
If this had been done with a single ended cable, then D+ (no D-) would be at 1050mV, and ground would still be at 0V, so the receiver would see 1050mV.

This is an bit of an over simplification (but gets the basic concept across) - the ground could also pick up some noise (or have it present to start with), but due to the mismatched impedance between it and the signal the amount of noise picked up on each line will be different and this difference will be seen at the receiving end. Also it may be present initially (e.g. ground loop) which is a big problem for single ended systems.
Matching the impedances of the lines in a balanced connection is very important for good common mode rejection (i.e. rejection of the signal common to both signals) as it only works if both lines pick up exactly the same amount of noise. The signals do not have to be symmetrical. However the noise is created, as long as it affects both signals equally then the common mode rejection will be very good.

Oli Glaser
  • 54,990
  • 3
  • 76
  • 147
38

Actually, that was tried once: The Apple Desktop Bus (ADB) was used to connect keyboards and mice to Apple Macintosh computers from about 1986 until Apple ditched it for USB in 1997 with the iMac.

It had four wires: 5V, ground, data, and power-switch. The power-switch line was just for the power button on the keyboard, which connected the line to ground, and told the power supply to start up the machine. It had to be its own wire so it still worked even if the 5V line was off.

Other than that, the data line carried everything... very slowly. The bus never really progressed beyond being a desktop device bus because it not only had a single-ended signal, but it had length limits (you get reflections off the end of the bus, since it's not terminated at each end).

So Intel decided to use differential signaling for USB. If you want a good idea of what differential signaling buys you, compare the performance in noise of the single-ended RS-232 bus to the differential RS-422 bus. RS-422 can be driven over a longer cable with less source voltage at a given bit error rate.

Why is this? The long version takes a day's lecture in electromagnetics class. The short version is that a noise signal will induce the same voltage in both wires of a differential pair, so the comparator at the receiver end cancels it out (it rejects common-mode voltage very well). A single-ended line has no comparable guarantee, since there's no guarantee that the ground line and signal line will pick up the same noise signal; grounds might even be connected via chassis ground and the return current will take completely different routes.

Mike DeSimone
  • 4,705
  • 17
  • 22
  • You say RS-422 can be driven longer than RS=232 for a given bit error rate; do long RS-232 cables start to pick up random errors? I would have expected that while there might be some lengths, right on the borderline of usability, where a given message might have a 99% chance of passing through uncorrupted, there wouldn't be much difference between the length where a complex message could pass through with 99% or better chance of success, and the length where it would have a 99% chance of failure. Is the fall-off at all gradual? – supercat Sep 26 '11 at 15:50
  • 4
    Long RS-232 lines have a big problem that RS-422 does not: Since "ground" is referenced to demodulate the signal, the cumulative error in this "ground" wreaks havoc on the receiver. It gets even worse when the receiver and driver aren't on the same ground (plugged into different power circuits, for example), or when currents other than the signal's return current are on that ground line. Any voltage drop on the ground line, for whatever reason, reduces your noise margin, until it's just gone. Basically, "ground" is a convenient fiction that fails for long cables. – Mike DeSimone Sep 26 '11 at 17:01
  • The fall-off is not really that gradual, since in most cases noise is much less than the margin between VOH/VOL and VIH/VIL. What happens is that, at a certain (long length), you start picking up noticeable errors, just as the noise strength starts to equal the receiver threshold (i.e. the voltage needed to bump a `0` to a `1` or vice versa), then as the cable gets longer you get a lot more errors, until it's completely gone. It's not like radio's r^-2 spreading loss. (Back on topic, in ADB's case, the ground wire carries both signal and power return current.) – Mike DeSimone Sep 26 '11 at 17:06
  • Is the problem more typically that the noise strength increases, or is the problem more typically that the signal either gets too weak to reach the detection threshold consistently on rising and falling edges? I've certainly seen the latter problem more than noise at high speeds; does noise become the predominant problem at lower speeds (with the longer cable lengths lower speeds would allow)? As for ADB, I think it was designed to save people from having separate wires plug into their PC for the mouse and the keyboard. Too bad modern PC designers don't consider such things. – supercat Sep 26 '11 at 20:04
  • I'm assuming a constant level of noise. A varying level of noise can be a significant problem, but I figure you're going to not route your wires over motors and such. I was just talking about *signal* loss leading to a decrease in SNR, and more importantly the fact that "ground" isn't. I wasn't considering signal speed, just levels; the problems caused by speed are related to edge times and cable termination, which is out of the scope of this question since you can terminate a single-ended signal (50 and 75 ohms are common). ADB was too simple; you couldn't plug a modem or drive into it. – Mike DeSimone Sep 27 '11 at 14:24
  • From what I can tell, ADB was designed to reduce the clutter of cables between the keyboard and the computer. It's actually better than USB in that regard, since one can plug an ADB cable into either end of a keyboard, and plug a mouse into the other. ADB wasn't designed to be a general-purpose hook-everything-up-here connector. Incidentally, it's worth noting that while ADB was single-ended, all legacy Macintoshes included RS-422 ports rather than RS-232 ports. – supercat Sep 27 '11 at 15:20
  • 2
    In practice, ADB was not that reliable when you had multiple devices. I had a joystick, throttle, keyboard, and mouse, and if you didn't get them in the right order, they would randomly not work. The joystick and throttle were the culprits; they had a lot of cable length built in, and it added up. And, yes, the Mac did not have RS-232 (it's why I used 422 at all), but one trick with RS-422 is that you can convert it to single-ended RS-423 with the cable (TX- becomes TX; TX+ not connected, RX+ to GND, RX- becomes RX), and RS-423 is compatible with RS-232 over short distances. – Mike DeSimone Sep 27 '11 at 15:54
  • @DeSimone macs had a differential serial port, it had 2 of them, printer and modem... – Grady Player Mar 09 '13 at 23:29
  • @GradyPlayer The ADB bus and the serial ports were two entirely different things. The Mac serial ports were differential RS-422, which could be creatively rewired to be RS-232 compatible, but unlike USB or ADB they did not have power. (Though there were some devices that used the transmit pair as a parasitic power source; the load couldn't be more than 100 ohms.) Further, unlike USB and ADB, the serial port consisted of two *unidirectional* pairs. However, the AppleTalk and PhoneNet networks used external boxes to convert this to bidirectional RS-485 for low-speed (230 kbps) networking. – Mike DeSimone Mar 10 '13 at 03:02
  • @Mike DeSimone, sorry I misread your comment. They were of course very different. When I read your comment I though you were saying they had no serial port rather than no RS232 port. – Grady Player Mar 10 '13 at 04:04
14

Actually a lot of USB has 5 lines, not 4. (The 5th line is for negotiating who is master in OTG applications. Note this is limited to mini and micro USB connectors.)

As others have already pointed out, the D+ and D- lines are a differential pair. Since a receiver can ignore the common mode voltage, a differential pair provides better noise immunity than a single ended signal. Logically, the D+ and D- lines are a single signal.

Olin Lathrop
  • 310,974
  • 36
  • 428
  • 915
  • 2
    @Kortuk: On mini and micro USB there is a 5th "ID" pin for USB On-the-Go, where either device can act as a host. https://secure.wikimedia.org/wikipedia/en/wiki/USB#Physical_appearance – endolith Sep 26 '11 at 15:50
  • 4
    The fifth pin isn't for negotiation as such - it's fixed in the connector and doesn't reach the other end. The idea was to indicate to OTG devices when they need to take the host role by plugging the A end in. There's also a protocol to switch roles, but that's much higher level. – Yann Vernier May 11 '13 at 07:01
11

I can't say definitively that this is the only consideration that went into it, but that's not for grounding, it's for EMI cancellation. The data +/- wires are twisted pair carrying differential signals.

It's just like you'd find in a typical household phone cord or network cable.

Nicholas Knight
  • 233
  • 1
  • 2
  • 6
9

The D+ D- differential data transmission mechanism is adopted to reduce the noise affected, hence the bandwidth of the transmission can be highly increased.

Like USB there are several other transmission protocol which uses differential physical layer. Some examples are RS485, Ethernet...

Saneesh A T
  • 1,152
  • 1
  • 13
  • 17
7

But, even with differential data, there are times when single-ended signaling is used in the USB: The end-of-packet is signaled with a single-ended-zero (SE0), namely, both D+ and D- in low state. This state last the time of 2 bits. if SE0 last for more than 10ms it means a bus reset.

This single-ended signaling makes the USB quite sensitive to electromagnetic interference, like those I found recently when a hair dryer motor was causing a lot of disconnects in a nearby USB peripheral. And no common-mode filters can be effectively used because these can degrade the SE0 signal... Another well conceived standard...

Jesus Arias
  • 71
  • 1
  • 1
  • Using single-ended signalling for a few conditions that don't require precise timing (e.g. using it for bus reset seems like a perfectly fine idea). Using a two-bit-time SE0 seems a bit quick, though; what are receivers supposed to do if they see a one-bit-time SE0? Having the transmitter send a three-bit-time SE0 and the receiver look for at least two would seem much better. – supercat Nov 15 '12 at 16:15
3

Beyond Logic has an overview of the essential points of the electrical portion of the USB spec here (also in PDF format here):

... USB uses a differential transmission pair for data. This is encoded using NRZI and is bit stuffed to ensure adequate transitions in the data stream.

...

The receiver defines a differential ‘1’ as D+ 200mV greater than D- and a differential ‘0’ as D+ 200mV less than D-. The polarity of the signal is inverted depending on the speed of the bus.

Kevin Vermeer
  • 19,989
  • 8
  • 57
  • 102
Prasanth
  • 169
  • 4
  • 2
    We appreciate links as an extra, but if the links die your answer becomes useless. Could you give a summary here? – stevenvh Sep 26 '11 at 10:51
  • 2
    This is a much better answer due to the added summary - Thank you for doing that - but you also need to be careful to avoid plagarism. The content in your first paragraph is copyrighted. – Kevin Vermeer Sep 26 '11 at 11:43
  • @KevinVermeer: Quotations are not plagiarism *or* copyright violation. – endolith Sep 26 '11 at 14:14
  • 2
    @endolith - With attribution, they're not plagarism or copyright violation. I've edited the answer to demonstrate better attribution. Previously, no one would have known that the paragraph was mostly a quotation. Now it's obvious. When making a quotation, use the block quote features. – Kevin Vermeer Sep 26 '11 at 14:48
  • @endolith: Attribution protects against plagiarism but attributed quotes CAN still be copyright violations. – Ben Voigt Mar 11 '17 at 21:45