NMEA 2000 iPad Adapter
Reorganize schematic into readable functional blocks without changing connectivity
Verify schematic image and ERC after cleanup
Regenerate and provide schematic PDF
Waiting for input
U1)ISO1050 TXD is pulled recessive by R5 and is not connected to an ESP32 TX GPIO.Table
| Function | ESP32-S3 pin/net | Schematic connection | Direction | Notes |
|---|---|---|---|---|
| CAN RX | GPIO18 / CAN_RXD | U2:RXD -> U1:IO18 | Input | Receives isolated CAN transceiver output |
| CAN TX placeholder | GPIO17 / not connected | No fitted schematic path to U2:TXD | Output unused | Required by TWAI driver config; not connected to bus hardware |
| USB D- | GPIO19 / USB_D_N | J1/D2 -> U1:IO19 | USB | Native USB programming/debug |
| USB D+ | GPIO20 / USB_D_P | J1/D2 -> U1:IO20 | USB | Native USB programming/debug |
| BOOT | GPIO0 / ESP_BOOT | Pull-up R4, button S2 to GND | Input | Hold BOOT while resetting for bootloader if needed |
| EN / reset | ESP_EN | Pull-up R3, RC cap C4, button S1 to GND | Input | Reset/enable |
| CAN TXD hardware default | CAN_TXD_RECESSIVE | U2:TXD pulled to 3V3 by R5 | Fixed high | Hardware listen-only default |
platformio.iniIni
[env:nmea2000_listener] platform = espressif32 board = esp32-s3-devkitc-1 framework = arduino monitor_speed = 115200 board_build.mcu = esp32s3 board_build.flash_mode = dio lib_deps =
src/main.cpp)Cpp
#include <Arduino.h> #include <WiFi.h> #include <WebServer.h> #include "driver/twai.h" // Schematic-grounded pins #define CAN_RX_PIN 18 // U1 IO18 <- U2 RXD, net CAN_RXD #define CAN_TX_UNUSED_PIN 17 // Not connected to U2 TXD in Rev A // Wi-Fi AP shown to the iPad static const char *AP_SSID = "N2K-Listener"; static const char *AP_PASS = "nmea2000"; // change before field use WebServer server(80); struct CanSnapshot { uint32_t id = 0; uint8_t dlc = 0; uint8_t data[8] = {0}; uint32_t count = 0; uint32_t lastMs = 0; }; volatile uint32_t rxCount = 0; CanSnapshot lastFrame; static uint8_t n2kPriority(uint32_t id) { return (id >> 26) & 0x7; } static uint32_t n2kPgn(uint32_t id) { uint8_t pf = (id >> 16) & 0xFF; uint8_t ps = (id >> 8) & 0xFF; uint8_t dp = (id >> 24) & 0x01; uint8_t edp = (id >> 25) & 0x01; if (pf < 240) return ((uint32_t)edp << 17) | ((uint32_t)dp << 16) | ((uint32_t)pf << 8); return ((uint32_t)edp << 17) | ((uint32_t)dp << 16) | ((uint32_t)pf << 8) | ps; } static uint8_t n2kSource(uint32_t id) { return id & 0xFF; } String frameJson() { noInterrupts(); CanSnapshot f = lastFrame; uint32_t count = rxCount; interrupts(); char buf[384]; char dataHex[3 * 8 + 1] = {0}; for (uint8_t i = 0; i < f.dlc && i < 8; i++) { char b[4]; snprintf(b, sizeof(b), "%02X%s", f.data[i], (i + 1 < f.dlc) ? " " : ""); strncat(dataHex, b, sizeof(dataHex) - strlen(dataHex) - 1); } snprintf(buf, sizeof(buf), "{\"rxCount\":%lu,\"lastMs\":%lu,\"id\":\"0x%08lX\",\"pgn\":%lu,\"priority\":%u,\"source\":%u,\"dlc\":%u,\"data\":\"%s\"}", (unsigned long)count, (unsigned long)f.lastMs, (unsigned long)f.id, (unsigned long)n2kPgn(f.id), n2kPriority(f.id), n2kSource(f.id), f.dlc, dataHex); return String(buf); } void handleRoot() { server.send(200, "text/html", R"HTML( <!doctype html><html><head><meta name="viewport" content="width=device-width,initial-scale=1"> <title>NMEA 2000 Listener</title> <style>body{font-family:-apple-system,BlinkMacSystemFont,sans-serif;margin:24px;background:#101820;color:#eef}pre{font-size:18px;background:#172635;padding:16px;border-radius:8px}</style> </head><body><h1>NMEA 2000 Wi-Fi Listener</h1><p>Hardware RX-only prototype. No CAN transmit path fitted.</p><pre id="out">Waiting...</pre> <script>async function tick(){try{let r=await fetch('/api/frame');out.textContent=JSON.stringify(await r.json(),null,2);}catch(e){out.textContent=e;}setTimeout(tick,500)}tick();</script> </body></html>)HTML"); } void handleFrameApi() { server.send(200, "application/json", frameJson()); } void initTwaiListenOnly() { twai_general_config_t g_config = TWAI_GENERAL_CONFIG_DEFAULT((gpio_num_t)CAN_TX_UNUSED_PIN, (gpio_num_t)CAN_RX_PIN, TWAI_MODE_LISTEN_ONLY); twai_timing_config_t t_config = TWAI_TIMING_CONFIG_250KBITS(); twai_filter_config_t f_config = TWAI_FILTER_CONFIG_ACCEPT_ALL(); esp_err_t err = twai_driver_install(&g_config, &t_config, &f_config); if (err != ESP_OK) { Serial.printf("TWAI driver install failed: %d\n", err); return; } err = twai_start(); if (err != ESP_OK) { Serial.printf("TWAI start failed: %d\n", err); return; } Serial.println("TWAI listen-only started at 250 kbit/s"); } void pollCan() { twai_message_t msg; while (twai_receive(&msg, 0) == ESP_OK) { if (!(msg.flags & TWAI_MSG_FLAG_EXTD)) continue; // NMEA 2000 uses 29-bit extended IDs noInterrupts(); lastFrame.id = msg.identifier; lastFrame.dlc = msg.data_length_code; for (uint8_t i = 0; i < lastFrame.dlc && i < 8; i++) lastFrame.data[i] = msg.data[i]; lastFrame.count++; lastFrame.lastMs = millis(); rxCount = lastFrame.count; interrupts(); } } void setup() { Serial.begin(115200); delay(1000); Serial.println("NMEA 2000 Wi-Fi Listener booting"); Serial.println("Safety: CAN TXD is hardware-held recessive and not connected to MCU TX in Rev A."); initTwaiListenOnly(); WiFi.mode(WIFI_AP); WiFi.softAP(AP_SSID, AP_PASS); Serial.printf("Wi-Fi AP %s started, IP %s\n", AP_SSID, WiFi.softAPIP().toString().c_str()); server.on("/", handleRoot); server.on("/api/frame", handleFrameApi); server.begin(); } void loop() { pollCan(); server.handleClient(); }
J1.BOOT (S2 / ESP_BOOT), tap reset (S1 / ESP_EN), then release BOOT.pio runpio run -t uploadpio device monitorN2K-Listener, open http://192.168.4.1/.TWAI_MODE_LISTEN_ONLY; do not change to normal mode for Rev A.CAN_TX_UNUSED_PIN is intentionally not connected to U2:TXD.Platform & Toolchain
Pin Mapping
`platformio.ini`
Complete Firmware Source (`src/main.cpp`)
Build & Flash
Firmware Safety Notes