【问题标题】:ESP32 failing to detect PN532 NFC moduleESP32 无法检测到 PN532 NFC 模块
【发布时间】:2018-09-12 01:52:16
【问题描述】:

过去几天我一直在努力让 Elechouse PN532 V3 模块通过 I2C 与 ESP32 一起工作。 PN532 模块本身可以很好地与 Raspberry Pi 配合使用。

这是电路(实际上并未使用 SparkFun ESP32 板,仅供参考)

这是我要运行的代码

#include <Wire.h>
#include <PN532_I2C.h>
#include <PN532.h>
#include <NfcAdapter.h>

PN532_I2C pn532i2c(Wire);
PN532 nfc(pn532i2c);

void setup(void) {
  Serial.begin(115200);
  Serial.println("Hello!");

  Wire.begin(18, 19);
  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); // halt
  }

  // Got ok data, print it out!
  Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); 
  Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); 
  Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  nfc.setPassiveActivationRetries(0xFF);

  // configure board to read RFID tags
  nfc.SAMConfig();

  Serial.println("Waiting for an ISO14443A card");
}

void loop(void) {
  boolean success;
  uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
  uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

  // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
  // 'uid' will be populated with the UID, and uidLength will indicate
  // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
  success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

  if (success) {
    Serial.println("Found a card!");
    Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("UID Value: ");
    for (uint8_t i=0; i < uidLength; i++) 
    {
      Serial.print(" 0x");Serial.print(uid[i], HEX); 
    }
    Serial.println("");
    // Wait 1 second before continuing
    delay(1000);
  }
  else
  {
    // PN532 probably timed out waiting for a card
    Serial.println("Timed out waiting for a card");
  }
}

最后是串行输出:Didn't find PN53X board
任何想法我做错了什么?

编辑:我使用 https://github.com/elechouse/PN532 的库和 ESP32 开发板是 Wemos Lolin32 Lite 克隆。

【问题讨论】:

  • 嘿,你能找出原因吗,因为我遇到了同样的问题?而且esp32没有内部引体向上吗?

标签: nfc i2c esp32


【解决方案1】:

我没有任何硬件来验证这一点,但来自 'PN532-PN532_HSU\NDEF\README.md'

For the Adafruit Shield using I2C 

    #include <Wire.h>
    #include <PN532_I2C.h>
    #include <PN532.h>
    #include <NfcAdapter.h>

    PN532_I2C pn532_i2c(Wire);
    NfcAdapter nfc = NfcAdapter(pn532_i2c);

尝试在您的代码中使用上述内容?我还建议您更深入地查看 PN532 I2C 示例。 PN532 I2C 库代码定义了一个“唤醒”功能:

void PN532_I2C::wakeup()
{
    delay(500); // wait for all ready to manipulate pn532
}

该评论让我相信该设备在准备好通话之前可能需要很长的延迟(500 毫秒)。

祝你好运。

【讨论】:

    【解决方案2】:

    sda 和 scl 分别是 21 和 22 还要确保将模式更改为 I2C(PN532 模块上的那些跳线): doc - page 3

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-07-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多