读取NFC标签不能与Arduino Uno + PN532 itead模块一起使用

时间:2015-08-18 14:32:47

标签: arduino nfc arduino-uno

我正在努力用Arduino Uno和PN532模块读取NFC标签(然后在其上书写)。我在我的Arduino中使用了itead PN532 NFC模块(http://wiki.iteadstudio.com/ITEAD_PN532_NFC_MODULE)。 我想使用I2C通信。所以我把我的端口链接起来了:

  • IRQ(NFC模块)到A2(Arduino Uno)
  • RST(NFC模块)到A3(Arduino Uno)
  • SDA(NFC模块)到A4(Arduino Uno)
  • SCL(NFC模块)到A5(Arduino Uno)
  • GND(NFC模块)至GND(Arduino Uno)
  • 5V(NFC模块)至5V(Arduino Uno)

然后我使用USB将我的Arduino链接到我的笔记本电脑。我已经下载了Adafruit_PN532_master库,用于我的盾牌。然后我尝试使用此代码读取NFC标签,但它无法正常工作。

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_PN532.h>


// If using the breakout with SPI, define the pins for SPI communication.
#define PN532_SCK  (13)
#define PN532_MOSI (11)
#define PN532_SS   (10)
#define PN532_MISO (12)


#define PN532_IRQ   (2)
#define PN532_RESET (3)  // Not connected by default on the NFC Shield

Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET);
boolean val(true);

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

  nfc.begin();

  uint32_t versiondata = nfc.getFirmwareVersion();
  if (! versiondata) {
    Serial.print("Didn't find PN53x board");
    while (1); 
  }
  // 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);

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

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


void loop(void) {
  uint8_t 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], (uint8_t*) &uidLength);
  Serial.println(success);

  if (success) {
    // Display some basic information about the card
    Serial.println("Found an ISO14443A card");
    Serial.print("  UID Length: "); Serial.print(uidLength, DEC); Serial.println(" bytes");
    Serial.print("  UID Value: ");
    nfc.PrintHex(uid, uidLength);

    if (uidLength == 4)
    {
      // We probably have a Mifare Classic card ... 
      uint32_t cardid = uid[0];
      cardid <<= 8;
      cardid |= uid[1];
      cardid <<= 8;
      cardid |= uid[2];  
      cardid <<= 8;
      cardid |= uid[3]; 
      Serial.print("Seems to be a Mifare Classic card #");
      Serial.println(cardid);
    }
    Serial.println("");
    val = false;
  }
  delay(1000);
}

由于我有Arduino显示器 &#34;你好!找到芯片PN532。固件版本1.6。等待ISO14443A卡...&#34; 没有别的。我的NFC标签已经过盾牌,所以我不明白为什么它无法读取它。它似乎检测到标签存在。但它无法读懂它。我觉得这个函数有问题:readPassiveTargetID(PN532_MIFARE_ISO14443A,&amp; uid [0],&amp; uidLength)但我不明白为什么。

即使我在Adafruit_PN532库中运行示例,它也会向我显示相同的输出,因为它无法读取标记。

我可能遗漏了一些东西......如果您有任何想法,可以帮助我吗?

非常感谢!!

0 个答案:

没有答案