我正在开发一个用于从 mifare 标签读取和写入数据的应用程序。我买了一台可以使用 NFC 技术读写 mifare 标签操作的设备。 NFC Shield 我一直在使用 mifare 超轻标签,但在尝试验证特定内存地址时遇到问题。由于这个原因,我无法开始阅读。这是我的 Arduino 代码:
//This example reads a MIFARE memory block. It is tested with new MIFARE 1K cards.
//Uses default keys.
//Contributed by Seeed Technology Inc (www.seeedstudio.com)
#include <PN532.h>
#define SCK 52
#define MOSI 51
#define SS 10
#define MISO 50
PN532 nfc(SCK, MISO, MOSI, SS);
void setup(void) {
Serial.begin(9600);
Serial.println("Hello!");
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);
Serial.print("Supports "); Serial.println(versiondata & 0xFF, HEX);
// configure board to read RFID tags and cards
nfc.SAMConfig();
}
void loop(void) {
uint32_t id;
// look for MiFare type cards
id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);
if (id != 0) {
Serial.print("Read card #"); Serial.println(id);
uint8_t keys[]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
if(nfc.authenticateBlock(1, id ,0x08,KEY_A,keys)) { //authenticate block 0x08
Serial.print("giris tmm #");
//if authentication successful
uint8_t block[16];
//read memory block 0x08
if(nfc.readMemoryBlock(1,0x08,block)) {
Serial.print("Read tmm #");
//if read operation is successful
for(uint8_t i=0;i<16;i++) {
//print memory block
Serial.print(block[i],HEX);
Serial.print(" ");
}
Serial.println();
}
}
}
delay(500);
}
此阅读代码是为 Arduino Mega 2560 和 seedtudio NFC Shield v1.0 和 mifare 超轻标签制作的。在编写操作过程中也遇到了同样的问题。
我怎么解决这个问题 ?