從 MDI 引腳到 RJ45:嵌入式開發者應瞭解的以太網端口硬件
From MDI Pins to RJ45: The Ethernet Port Hardware Every Embedded Developer Should Know
文章梳理以太網 PHY 的 MDI 引腳至 RJ45 插座之間的硬件組成,並説明如何按鏈路症狀排查連線故障。文中比較電壓模式與電流模式 PHY 的終端接法,指出 1000BASE-T 需要四組線對,並介紹讀取 BMSR 兩次及檢查寄存器 10 的方法。文章亦涵蓋磁性器件、保護電路、接地,以及分立式、集成磁性器件和無變壓器三種端口方案。
If the Ethernet link on your board will not come up, drops at random, or settles at 100 Mbps on a Gigabit design, the cause usually sits in the few centimetres between the PHY's MDI pins and the RJ45 jack. That stretch holds the PHY, a termination and center-tap network, the magnetics (an isolation transformer with a common-mode choke) and the connector, with protection and grounding around them. Knowing what each part does lets you read PHY registers as evidence instead of guessing. Drafted with AI assistance; facts checked against the cited datasheets and standards.
What sits between the PHY and the cable
| Part | Job | Typical mistake |
|---|---|---|
| PHY | Drives and receives differential signals on its MDI pins | Termination that does not match its drive type |
| Termination and center taps | Bias and decouple the PHY-side windings | Voltage-mode and current-mode schemes mixed up |
| Magnetics (often labelled TD on schematics) | 1:1 galvanic isolation plus common-mode rejection | Two-channel part on a Gigabit port |
| RJ45 | Four contact pairs for the four twisted pairs | Pair order swapped between jack and transformer |
Why the PHY type decides the wiring
Ethernet PHYs drive the line in one of two ways. A voltage-mode PHY terminates on-die, so its MDI lines run straight to the transformer and each PHY-side center tap is decoupled to ground with a capacitor, typically 100 nF. A current-mode PHY needs an external 49.9 Ω resistor from each MDI line to a bias supply, and the center taps are tied to that supply too.
The two schemes are not interchangeable. Reusing a reference schematic from a different PHY family is an easy way to end up with a weak link or none at all, so check the datasheet of the exact PHY you placed.
Two pairs or four
10BASE-T and 100BASE-TX use only pairs 1/2 and 3/6. 1000BASE-T (IEEE 802.3 Clause 40) transmits and receives on all four pairs at once, and so does 10GBASE-T. A Gigabit port therefore needs a four-channel transformer.
It also explains a confusing symptom. A fault on pair 4/5 or 7/8 does not have to kill the link. Many Gigabit PHYs offer a vendor-specific downshift feature: after repeated failed attempts at 1000 Mbps they stop advertising it and link at 100 Mbps on the two good pairs. On the bench that looks like a slow-network bug.
Reading the evidence from firmware
The Clause 22 management registers are the same on every compliant PHY, so you can check the analog side without vendor tools:
/* IEEE 802.3 Clause 22 registers */
#define MII_BMSR 0x01 /* basic mode status */
#define BMSR_LSTATUS (1u << 2) /* link status, latches low */
#define BMSR_ANEGDONE (1u << 5) /* auto-negotiation complete */
#define MII_STAT1000 0x0A /* 1000BASE-T status */
uint16_t bmsr = mdio_read(phy, MII_BMSR); /* returns and clears any latched link-down */
bmsr = mdio_read(phy, MII_BMSR); /* current state */
bool link_up = bmsr & BMSR_LSTATUS;
bool aneg_ok = bmsr & BMSR_ANEGDONE;
uint16_t stat1000 = mdio_read(phy, MII_STAT1000);
Register 10 also reports local and remote receiver status, whether the link partner can do 1000BASE-T, and an idle error count. A practical reading of the results:
- Auto-negotiation never completes: compare the termination scheme with the PHY type, then check transformer orientation and pair mapping.
- The partner reports 1000BASE-T ability but you settle at 100 Mbps: suspect pairs 4/5 and 7/8 (cable, jack or transformer channels) and check whether downshift is enabled.
- The idle error count keeps climbing at 1000 Mbps: look at layout and magnetics before blaming the driver.
- The link drops during ESD testing or after a surge: look at protection, not firmware.
Protection and grounding on the schematic
- Bob Smith termination: on the cable side, each center tap (plus the unused pairs on a 10/100 port) goes through 75 Ω to a shared node, and that node reaches chassis ground via a 1 nF high-voltage capacitor. It handles common-mode termination only; it is not surge protection.
- TVS diodes on the PHY side clamp whatever transient energy couples through the transformer.
- A gas discharge tube (GDT) from the cable-side center taps to protective earth diverts surge current.
- Chassis ground and circuit ground are separate nets. The RJ45 shell goes to chassis ground, and how the two nets meet is a system-level decision.
Three ways to build the port
- Discrete jack plus separate transformer: the most freedom to place protection parts.
- RJ45 with integrated magnetics: smaller footprint and shorter traces; the transformer and the Bob Smith network live inside the jack.
- Transformerless, capacitor-coupled: DC-blocking capacitors and a common-mode choke instead of an isolation transformer. Isolation has to be proven by testing, and it is generally not the choice for a standard 100 m cable run.
Next time a link misbehaves, read BMSR twice and check register 10 before you touch the driver. Those few bits usually tell you which part of this short stretch of circuit to put a probe on.
Sources: IEEE 802.3 Clause 22 (MII management registers) and Clause 40 (1000BASE-T); termination schemes per the PHY vendor's datasheet and reference design.
來源:DEV Community · dev.to