我正在开发一个用于从MIFARE标签读取和写入数据的应用程序。我买了一个可以使用NFC技术读取和写入MIFARE标签操作的设备。
NFC屏蔽
我一直在使用MIFARE ultralight标签,但在尝试验证特定内存地址时遇到了问题。由于这个原因,我不能开始阅读。这是我的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和Seeedstudio NFC Shield v1.0和MIFARE超轻标签制作的。在写作操作过程中也遇到了同样的问题。
我该如何解决这个问题?
我遇到了同样的问题,并编辑了米费尔经典示例以读取米费尔超轻卡片。这是我的代码:https://gist.github.com/SamDecrock/bd1ec55f083a71ecee95
输出应该是这样的:
Looking for PN532...
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
Found an ISO14443A card
UID Length: 7 bytes
UID Value: 4 13 74 72 83 1E 81
Page 0 04 13 74 EB ..t.
Page 1 72 83 1E 81 r...
Page 2 6E 48 00 00 nH..
Page 3 E1 11 06 00 ....
Page 4 00 00 00 00 ....
Page 5 00 00 00 00 ....
Page 6 00 00 00 00 ....
Page 7 00 00 00 00 ....
Page 8 00 00 00 00 ....
Page 9 00 00 00 00 ....
Page 10 00 00 00 00 ....
Page 11 00 00 00 00 ....
Page 12 00 00 00 00 ....
Page 13 00 00 00 00 ....
Page 14 00 00 00 00 ....
Page 15 00 00 00 00 ....
Send a character to run the mem dumper again!
如您所见,第0页和第1页包含UID;-)
MIFARE Ultralight与MIFARE Classic 1K并不相同。MIFARE Ultralight不支持(或不需要)身份验证。您可以直接开始阅读,无需使用身份验证。
使用PN532库和NDEF库,您可以读取/写入mi,经典标签和读取mi,超轻标签。