UART Input Protection Circuit¶
Overview¶
This circuit conditions the two off-board serial inputs — NMEA0183 and Victron VE.Direct — before they reach the ESP32, using the two channels of an HCPL2531 optocoupler. The ESP32 pin never connects to boat wiring: it sees only the optocoupler's output transistor. A wiring accident on a data cable sacrifices, at worst, an inexpensive optocoupler instead of the processor.
What the stage provides:
- Input tolerance. The LED plus its 806 Ω series resistor accept roughly 2.5–30 V of drive without damage. 12 V accidentally landed on a signal pin pushes about 13 mA through the LED — harmless.
- Reverse and negative-transient protection. A 1N4148 diode on each channel clamps negative swings, protecting the optocoupler LED from reverse bias.
- Noise immunity. It takes more than a volt of forward drive and real current to light the LED, so induced noise that would flip a bare CMOS input does nothing.
- Level shifting. Any talker from about 2.5 V to well above 5 V drives the same input; the ESP32 side is always clean 3.3 V logic.
What the stage does not provide: galvanic isolation. The optocoupler LED cathodes return to board ground, so the input side and the ESP32 side share one ground, and the HCPL2531's internal 2500 V barrier is not used as a system isolation barrier. The external device and the regulator must share a ground — on a boat they normally already do, through the battery negative bus. Grounding rules and wiring options are on the two interface pages: NMEA0183 and Victron VE.Direct.
The stage also inverts: a high level at the connector lights the LED, which pulls the ESP32-side line low. The firmware accounts for this — the VE.Direct UART is configured with inverted receive polarity, and the NMEA0183 channel works out to normal polarity because an NMEA talker's A leg idles low.
Circuit Description¶
Key Components¶
| Designator | Part | Function |
|---|---|---|
| U13 | HCPL2531SDVM | Dual-channel digital optocoupler (2500 VRMS internal barrier, ≤ 1 MBaud) |
| D13 (channel 1), D12 (channel 2) | 1N4148W (SOD-123, 75 V/300 mA) | Series protection — prevents reverse-bias of the optocoupler LEDs if the input swings negative |
| R61 (channel 1), R64 (channel 2) | 0.806 kΩ ±1 % | LED current-limit resistor (~2.6 mA at 3.3 V input, ~4.7 mA at 5 V input) |
| R63 (channel 1), R62 (channel 2) | 13 kΩ ±1 % | Output-side pull-ups to 3V3 on UART_RX1_ISOL / UART_RX2_ISOL |
| C68 (input side), C69 (output side) | 1 µF each | Local supply decoupling for the HCPL2531 VCC pin |
Signal Flow¶
- UART_RX1 (Victron VE.Direct) and UART_RX2 (NMEA0183) are the incoming serial data signals from the off-board connectors.
- Protection diodes D13 (ch 1) and D12 (ch 2) clamp any negative input swing to a Vf of ~0.7 V, preventing reverse-bias of the optocoupler LEDs.
- Current-limit resistors R61 (ch 1) and R64 (ch 2) set forward LED current to a safe value across the expected input range.
- The LED drives the HCPL2531's output transistor. The LED cathodes return to board ground, so the loop closes through the external device's ground connection (normally the boat's DC negative bus — see the interface pages for wiring).
- Output-side pull-ups R63 (ch 1) and R62 (ch 2) hold UART_RX1_ISOL and UART_RX2_ISOL HIGH when the LED is dark; a lit LED pulls the line LOW. This is the inversion described above.
- UART_RX1_ISOL → ESP32 GPIO7 (Victron VE.Direct receive, inverted polarity in the UART driver)
- UART_RX2_ISOL → ESP32 GPIO6 (NMEA0183 receive, normal polarity)
Technical Specifications¶
HCPL2531SDVM Optocoupler¶
- Internal barrier rating: 2500 V RMS (component rating; not used as a system isolation barrier here — see Overview)
- Data Rate: Up to 1 MBaud
- Input Forward Current: 1.6 mA (typical threshold)
- Supply Voltage (VCC): 2.7 V to 5.5 V
- Package: SOIC-8
Input Characteristics¶
- Logic High: Typically 3.3 V or 5 V
- Logic Low: 0 V (board ground)
- Maximum Input Voltage: Limited by the series resistor and diode protection
Output Characteristics¶
- Supply Voltage (VCC): 3.3 V
- Logic High: 2.8 V typical (VCC − 0.5 V with pull-up to 3.3 V)
- Logic Low: 0.4 V maximum
- Output Drive: Open collector with 13 kΩ pull-up to 3.3 V
Power Analysis¶
Input Side Power Consumption¶
Per Channel (LED lit):
- Forward voltage of optocoupler LED: ~1.2 V
- Input voltage: 3.3 V (assuming 3.3 V talker logic)
- Current through 0.8 kΩ resistor: (3.3 V − 1.2 V) / 800 Ω = 2.625 mA
- Power per channel: 3.3 V × 2.625 mA = 8.66 mW
Both Channels Active:
- Total input current: 2 × 2.625 mA = 5.25 mA
- Total input power: 2 × 8.66 mW = 17.32 mW
Output Side Power Consumption¶
Per Channel:
- VCC supply: 3.3 V (confirmed)
- Quiescent current (HCPL2531): ~0.5 mA per channel
- Pull-up current (logic low): 3.3 V / 13 kΩ = 0.254 mA
- Pull-up current (logic high): ~0 mA (output transistor off)
Both Channels:
- Quiescent current: 2 × 0.5 mA = 1.0 mA
- Pull-up current (worst case, both low): 2 × 0.254 mA = 0.508 mA
- Total output current: 1.0 mA + 0.508 mA = 1.508 mA
- Output power: 3.3 V × 1.508 mA = 4.98 mW
Total Power Consumption¶
Maximum Power Draw: 17.32 mW + 4.98 mW = 22.3 mW
Equivalent Current at 12 V: 22.3 mW / 12 V = 1.86 mA
Power Draw Summary¶
- At 3.3 V: 6.76 mA total
- At 5 V: 4.46 mA total
- At 12 V equivalent: 1.86 mA total
- Idle note: a connected VE.Direct device idles with its TX line high, which keeps that channel's LED lit continuously (~2.6 mA). The NMEA0183 channel idles dark.
Protocol Configuration¶
Baud rates, data formats, connector pins, and wiring instructions live on the interface pages — NMEA0183 and Victron VE.Direct. This page is only the shared input stage.
Bill of Materials¶
| Reference | Part Number | Description | Package | Quantity |
|---|---|---|---|---|
| U13 | HCPL2531SDVM | Dual digital optocoupler | SOIC-8 | 1 |
| D13, D12 | 1N4148W | Fast-switching protection diodes (LED reverse-bias clamp) | SOD-123 | 2 |
| R61, R64 | 0.806 kΩ ±1 % | LED current-limit resistors | 0603 | 2 |
| R63, R62 | 13 kΩ ±1 % | Output-side pull-up resistors to 3V3 | 0603 | 2 |
Conclusion¶
This input stage gives both serial ports a rugged, high-tolerance front end at ~22 mW: the ESP32 never touches boat wiring, miswires burn a cheap replaceable part instead of the processor, and any talker level from 2.5 V up drives it cleanly. It is a protection and level-shift stage with a shared ground, not an isolation barrier — the distinction matters for grounding, and the interface pages state the wiring rules that follow from it.