logo elektroda
logo elektroda
X
logo elektroda

ESP32 with RC522 RFID and W5500 Ethernet on Shared SPI Bus: Wiring, Pinout, and Stability Tips

User question

esp32 rc522 and w5500

Artificial Intelligence Response

Direct answer to the question

  • Yes—an ESP32 can run an RC522 RFID reader and a W5500 Ethernet module together. Use SPI correctly, give each device its own chip‑select (CS), and mind power, reset, and boot‑strapping pins.
  • For maximum robustness: put W5500 on VSPI and RC522 on HSPI (separate SPI buses). For simpler wiring: share VSPI and keep SPI speed modest (4–8 MHz).

Key points

  • Unique CS for each device; optional but recommended hardware reset pins for both.
  • Solid 3.3 V rail and short SPI wiring.
  • Avoid ESP32 strapping pins for CS/INT/RST where possible (notably GPIO0, 2, 4, 5, 12, 15).

Detailed problem analysis

Electrical interfaces

  • Bus topology:
    • Shared SPI: SCK/MOSI/MISO common; W5500_CS and RC522_CS on different GPIOs. Simple, uses fewer pins; requires that both devices release MISO when deselected and that the SPI clock be within the slowest device’s limits (RC522 typically ≤10 MHz).
    • Dual SPI (recommended): W5500 on VSPI, RC522 on HSPI. Eliminates contention and works around common RC522 clone issue where MISO is not tri‑stated when CS is high.
  • Logic levels:
    • ESP32 is 3.3 V logic. RC522 I/Os are 3.3 V only. Many W5500 boards accept 5 V input but level‑shift to 3.3 V internally—verify your module. When in doubt, power both modules from 3.3 V.
  • Power budget:
    • ESP32 typically 80–240 mA peaks.
    • W5500 ~120–180 mA depending on link/activity.
    • RC522 ~15–30 mA.
    • Use a stable 5 V→3.3 V regulator (≥500 mA headroom). Add bulk caps near loads (e.g., 47–100 µF electrolytic per module) and 100 nF decouplers at each VCC pin.
  • Resets and boot:
    • Tie each module’s RST to an ESP32 GPIO so firmware can enforce a clean startup. The W5500 in particular benefits from a hardware reset on warm reboot.
    • Be careful with strapping pins: GPIO12 (MTDI) changes internal LDO; GPIO0/2/15 affect boot mode; GPIO5 and GPIO4 are also strapping pins. They can be used post‑boot, but ensure their power‑on states won’t block boot.
  • Signal integrity:
    • Keep SPI wires short (<10–15 cm) and use a ground return next to each high‑speed signal (twisted pair or ribbon with GND between signals).
    • Start with SPI clock 4–8 MHz when sharing; increase only after validating both devices.
  • EMI and RF:
    • Keep the RC522 antenna away from the W5500 magnetics/transformer and Ethernet cable to avoid read‑range degradation.
    • Avoid large ground copper directly under the RC522 antenna loop.

Practical pin plans 1) Robust (separate buses)

  • VSPI (default): SCK GPIO18, MOSI GPIO23, MISO GPIO19 → W5500
    • W5500_CS: GPIO5 (or 27/32/33)
    • W5500_RST: GPIO26 (example)
    • W5500_INT: GPIO33 (optional)
  • HSPI: SCK GPIO14, MOSI GPIO13, MISO GPIO12 → RC522
    • RC522_CS (SDA/SS): GPIO15 (or 21/22/27/32/33)
    • RC522_RST: GPIO27 (example)

2) Simple (shared VSPI)

  • SCK GPIO18, MOSI GPIO23, MISO GPIO19 shared
    • W5500_CS: GPIO15
    • W5500_RST: GPIO26 (optional but recommended)
    • RC522_CS: GPIO5
    • RC522_RST: GPIO22 Note: If Ethernet breaks when RC522 is connected, you’ve likely hit an RC522 MISO tri‑state issue—move RC522 to HSPI or insert a small series resistor (e.g., 220–1 kΩ) in RC522 MISO and/or ensure RC522 driver never accesses device while W5500 is active.

SPI modes and speeds

  • Both devices operate in SPI mode 0. RC522 is often limited to around 10 MHz; W5500 can run faster, but the shared bus must respect the RC522 limit.

Bring‑up sequence (recommended) 1) Power and Ethernet only → confirm link, DHCP/static IP. 2) Add RC522 on shared or HSPI → verify tag reads. 3) Stress test: sustained Ethernet traffic while scanning tags.

Current information and trends

  • ESPHome has native support for W5500 via the ethernet: component and supports MFRC522 via the rc522_spi platform. Earlier community posts suggested custom components for W5500; that is now outdated—use the built‑in ethernet: type: W5500.
  • Many low‑cost RC522 boards still exhibit MISO bus‑hold when deselected. The dual‑bus approach remains a common field workaround for reliability.
  • Trend: Designers moving to ESP32 variants with integrated Ethernet MAC+PHY where feasible, or to SPI Ethernet with DMA‑friendly wiring and proper resets for deterministic networking.

Supporting explanations and details

  • Why separate buses improve reliability: If any slave keeps driving MISO while deselected, it corrupts frames to other slaves. Independent SPI peripherals on ESP32 give you separate MISO lines, fully isolating the devices.
  • Reset importance for W5500: If the ESP32 reboots but the W5500 stays powered, its internal state may not match the driver’s expectations. A controlled RST_low (≥1 ms) then RST_high with a short delay ensures a clean start.

Ethical and legal aspects

  • RFID tags may contain personal data. Follow local privacy laws (e.g., consent, data minimization).
  • Do not clone or store UIDs for unauthorized access control systems.
  • Ensure Ethernet‑connected devices are updated and secured to prevent network misuse.

Practical guidelines

ESPHome (robust, separate buses) YAML example

esphome:
name: access-node
platform: ESP32
board: esp32dev
logger:
api:
ota:
# W5500 on VSPI
ethernet:
type: W5500
clk_pin: GPIO18
mosi_pin: GPIO23
miso_pin: GPIO19
cs_pin: GPIO5
reset_pin: GPIO26 # strongly recommended
interrupt_pin: GPIO33 # optional
# manual_ip: # optional
# static_ip: 192.168.1.50
# gateway: 192.168.1.1
# subnet: 255.255.255.0
# RC522 on HSPI
spi:
- id: rfid_spi
clk_pin: GPIO14
mosi_pin: GPIO13
miso_pin: GPIO12
rc522_spi:
spi_id: rfid_spi
cs_pin: GPIO15
reset_pin: GPIO27
on_tag:
then:
- logger.log:
format: "Tag: %s"
args: [ 'x.c_str()' ]
- homeassistant.tag_scanned: !lambda 'return x;'
# Optional: expose last UID as a text sensor
text_sensor:
- platform: template
name: "Last RFID Tag"
update_interval: never

Arduino (shared bus) minimal sketch outline

#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>
// VSPI pins (ESP32 devkits)
constexpr uint8_t PIN_SCK = 18, PIN_MISO = 19, PIN_MOSI = 23;
constexpr uint8_t W5500_CS = 15, W5500_RST = 26;
constexpr uint8_t RC522_CS = 5, RC522_RST = 22;
MFRC522 rfid(RC522_CS, RC522_RST);
byte mac[] = {0xDE,0xAD,0xBE,0xEF,0xFE,0xED};
void setup() {
Serial.begin(115200);
SPI.begin(PIN_SCK, PIN_MISO, PIN_MOSI);
pinMode(W5500_CS, OUTPUT); digitalWrite(W5500_CS, HIGH);
pinMode(RC522_CS, OUTPUT); digitalWrite(RC522_CS, HIGH);
// Reset W5500
pinMode(W5500_RST, OUTPUT); digitalWrite(W5500_RST, LOW);
delay(5); digitalWrite(W5500_RST, HIGH); delay(50);
Ethernet.init(W5500_CS);
Ethernet.begin(mac); // or with static IP
rfid.PCD_Init(); // initializes via shared SPI
}
void loop() {
if (rfid.PICC_IsNewCardPresent() && rfid.PICC_ReadCardSerial()) {
Serial.print("UID: ");
for (byte i=0; i<rfid.uid.size; i++) { Serial.printf("%02X ", rfid.uid.uidByte[i]); }
Serial.println();
rfid.PICC_HaltA();
}
}

Troubleshooting checklist

  • Ethernet fails unless RC522 unplugged → RC522 MISO not tri‑stating; move RC522 to HSPI or add series resistor on RC522 MISO and ensure correct CS handling.
  • No IP via Ethernet → verify RST timing, CS pin, cabling, and link LEDs; try static IP; ensure adequate 3.3 V.
  • RC522 short read range → increase distance from Ethernet magnetics, retune orientation, ensure stable 3.3 V.

Possible disclaimers or additional notes

  • Some ESP32 boards reroute default SPI pins; verify your board’s pinout.
  • Cheap RC522 modules vary widely in quality; antenna and matching affect read range significantly.
  • Long SPI cables are not supported; for remote RC522 consider I2C/UART readers or RS‑485 gateways.

Suggestions for further research

  • Evaluate PN532 (NFC) if you need better range and protocol support (ISO14443A/B, peer‑to‑peer).
  • Consider ESP32 with native Ethernet MAC + external PHY (e.g., LAN8720) for designs where SPI Ethernet bandwidth limits matter.
  • Look at secure tag schemes (MIFARE DESFire EV1/EV2) and how to implement mutual authentication rather than using raw UIDs.

Brief summary

  • The ESP32 can reliably host both a W5500 and an RC522. For best stability, place W5500 on VSPI and RC522 on HSPI; otherwise share VSPI with distinct CS lines and a conservative SPI clock.
  • Pay attention to power integrity, resets, and avoidance of strapping pins. If you run into interference or bus contention, move to the dual‑bus wiring and add proper resets and decoupling.

If you tell me your exact ESP32 board and preferred framework (ESPHome vs Arduino), I can tailor the pinout and provide a ready‑to‑flash configuration.

Ask additional question

Wait...(2min)
Disclaimer: The responses provided by artificial intelligence (language model) may be inaccurate and misleading. Elektroda is not responsible for the accuracy, reliability, or completeness of the presented information. All responses should be verified by the user.