1

过去几天我一直在努力让 Elechouse PN532 V3 模块通过 I2C 与 ESP32 一起工作。PN532 模块本身适用于 Raspberry Pi。

这是电路(实际上并未使用 SparkFun ESP32 板,仅供参考) 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 克隆。

4

3 回答 3

0

我没有任何硬件来验证这一点,但来自 '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 毫秒)。

祝你好运。

于 2018-04-07T16:57:54.017 回答
0

我现在使用 M5STACK 灰色内核,常见问题是 I2C 总线会锁定在复位或重新编程。使用备用 I/O 引脚并连接到 PN532 复位引脚,在启动时保持此低电平,初始化 I2C 总线,然后在 100mS 问题解决后驱动复位高电平不再发生总线冲突。

于 2021-12-30T11:42:28.153 回答
0

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

于 2018-11-30T23:53:09.123 回答