Hi,
I bought the PN532 NFC RFID modul (Uart) and try to get work it with a Mifare DESFire EV1, using Arduino mega 2560.
When I use a Mifare Classic card (4 byte UID) it works well.
However, when using a Mifare DESFire EV1 card (7 byte UID), only every second read cycle of the target ID is successful.
I use the following code:
#include <PN532_HSU.h>
#include <PN532.h>
PN532_HSU pn532hsu(Serial1);
PN532 nfc(pn532hsu);
void setup() {
-
Serial.begin(115200);*
-
Serial.println("Hello!");*
-
nfc.begin();*
-
uint32_t versiondata = nfc.getFirmwareVersion();*
-
do{*
-
if (! versiondata) {*
-
Serial.println("Didn't find PN53x board");*
-
delay(3000);*
-
versiondata = nfc.getFirmwareVersion();*
-
}*
-
}while(!versiondata); *
-
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);*
-
nfc.SAMConfig();*
-
Serial.println("Waiting for an ISO14443A Card ...");*
}
void loop() { -
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)*
-
success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);*
-
if (success) {*
-
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);*
-
Serial.println("");*
-
if (uidLength == 4)*
-
{*
-
Serial.println("Seems to be a Mifare Classic card (4 byte UID)");*
-
}*
-
if (uidLength == 7)*
-
{*
-
Serial.println("Seems to be a Mifare Ultralight tag (7 byte UID)");*
-
}*
-
}*
else
{
Serial.println("...Wait for NFC Card...");
}
delay(1000);
}
The output with a classic Mifare card is as expected:
Hello!
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
...Wait for NFC Card...
...Wait for NFC Card...
Found an ISO14443A card
UID Length: 4 bytes
UID Value: 60 5D 5C 74
Seems to be a Mifare Classic card (4 byte UID)
Found an ISO14443A card
UID Length: 4 bytes
UID Value: 60 5D 5C 74
Seems to be a Mifare Classic card (4 byte UID)
Found an ISO14443A card
UID Length: 4 bytes
UID Value: 60 5D 5C 74
Seems to be a Mifare Classic card (4 byte UID)
The output with a Mifare DESFire card however shows that only every second read cycle is successful:
Hello!
Found chip PN532
Firmware ver. 1.6
Waiting for an ISO14443A Card ...
...Wait for NFC Card...
...Wait for NFC Card...
Found an ISO14443A card
UID Length: 7 bytes
UID Value: 04 25 8A C2 22 33 80
Seems to be a Mifare Ultralight tag (7 byte UID)
...Wait for NFC Card...
Found an ISO14443A card
UID Length: 7 bytes
UID Value: 04 25 8A C2 22 33 80
Seems to be a Mifare Ultralight tag (7 byte UID)
...Wait for NFC Card...
Does anybody know what the problem could be?
Thanks,
Mike