PN532 NFC RFID modul with MIFARE DESFire EV1

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

Hello, I got similar problem... (PN532, Mega 2560, Desfire). But my one does not read Desfire at all :frowning: - even according to properties, PN532 should support this tag type.

What is the version of your library? ( I suppose you are using GitHub - Seeed-Studio/PN532: NFC library using PN532 to read/write card and communicate with android). Problem could be also an antenna (smaller antenna in desfire cards).

There could be also time-out problem - desfire cards are read a little bit longer.

Could anyone read/write Mifare DESFire EV1 with Arduino + PN532 with success?

Just this week I finished the mega project: My libraray is the FIRST Desfire library that has ever been written for the Arduino family. It uses the PN532 board from Adafruit.

The code has only been tested compiling for Teensy 3.2, but it should also work on other Arduino boards.

My code contains all you need to communicate with a Desfire EV1 card. I implemented 2K3DES, 3K3DES and AES encryption.

You find it in my article on Codeproject: DIY electronic RFID Door Lock with Battery Backup