From 27e16c3d1b2a7ff299b9a18e756c6e496f95b9f9 Mon Sep 17 00:00:00 2001 From: ManuelW77 Date: Thu, 20 Aug 2026 09:35:38 +0200 Subject: [PATCH] fix(nfc): pulse PN532 RSTPDN before begin() Adafruit_PN532::begin() drives the reset line too briefly for some modules to reliably leave powerdown (~1ms LOW/2ms HIGH internally), which then makes getFirmwareVersion() return 0 right after begin() and startNfc() report "Kann kein RFID Board finden". Add an explicit 50ms/200ms reset pulse before begin(), shared via pulsePn532Reset() so startNfc() and the interface recovery path in ntag2xx_WriteNDEF() don't duplicate the timing. Adopts the fix from PR #24 (credit: rsantamaria01), refactored into a shared helper per review feedback (duplicate pulse code flagged by the automated Copilot review on that PR). Co-Authored-By: Raul Santamaria --- src/nfc.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/nfc.cpp b/src/nfc.cpp index b0e5c98..015ab0f 100644 --- a/src/nfc.cpp +++ b/src/nfc.cpp @@ -13,6 +13,17 @@ //Adafruit_PN532 nfc(PN532_SCK, PN532_MISO, PN532_MOSI, PN532_SS); Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); +// Adafruit_PN532::begin() toggles RSTPDN too briefly (~1ms/2ms) for some PN532 +// modules to reliably leave powerdown, which then makes getFirmwareVersion() +// return 0 right after begin(). Pulse it explicitly with more margin first. +static void pulsePn532Reset() { + pinMode(PN532_RESET, OUTPUT); + digitalWrite(PN532_RESET, LOW); + delay(50); + digitalWrite(PN532_RESET, HIGH); + delay(200); +} + TaskHandle_t RfidReaderTask; // AsyncWebServerRequest* volatile activeNfcWriteRequest = nullptr; // Removed SemaphoreHandle_t nfcRequestMutex = NULL; @@ -561,6 +572,7 @@ uint8_t ntag2xx_WriteNDEF(const char *payload) { Serial.println("1. Neuinitialisierung des PN532..."); // Reinitialize the PN532 + pulsePn532Reset(); nfc.begin(); vTaskDelay(pdMS_TO_TICKS(500)); // Give it time to initialize @@ -2335,6 +2347,7 @@ void scanRfidTask(void * parameter) { void startNfc() { nfcRequestMutex = xSemaphoreCreateMutex(); oledShowProgressBar(4, NUM_SETUP_STEPS, DISPLAY_BOOT_TEXT, tr(STR_NFC_INIT)); + pulsePn532Reset(); nfc.begin(); // Beginne Kommunikation mit RFID Leser delay(1000);