过去几天我一直在努力让Elechouse PN532 V3模块与ESP32通过I2C协同工作。 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克隆。
答案 0 :(得分: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毫秒)才能准备好通话。
祝你好运。
答案 1 :(得分:0)
sda和scl是21和22 还要确保将模式更改为I2C(PN532模块上的那些跳线): doc - page 3