PN532-RFID-NFC-FAQ

De MCHobby - Wiki
Sauter à la navigation Sauter à la recherche


MCHobby investit du temps et de l'argent dans la réalisation de traduction et/ou documentation. C'est un travail long et fastidieux réalisé dans l'esprit Open-Source... donc gratuit et librement accessible.
SI vous aimez nos traductions et documentations ALORS aidez nous à en produire plus en achetant vos produits chez MCHobby.

Puis-je avoir plusieurs shield sur un Arduino?

Non, la bibliothèque I2C peut uniquement utiliser une adresse par bus I2C et cette adresse n'est pas adjustable! Par conséquent, seul un shield NFC peut être utilisé par Arduino!

Puis-je lire et écrire des tags Mifare avec le PN532 et la bibliothèque Adafruit?

Absolument! La bibliothèque Adafruit inclus les fonctions d'authentification (authenticate), lecture et écriture de bloc individuel sur les cartes Mifare Classic.

Il faut s'authentifier avec la clé appropriée avant de lire ou écrire un block, et une fois authentifié auprès d'un bloc, vous pouvez lire et écrire le contenu)!

Par exemple, les fonctions clés dans la bibliothèque I2C d'Adafruit (bibliothèque développée pour le shield NFC d'Adafruit puisqu'il fonctionne en I2C par défaut) sont:

uint8_t mifareclassic_AuthenticateBlock (uint8_t * uid, uint8_t uidLen,
                                         uint32_t blockNumber, uint8_t keyNumber,
                                         uint8_t * keyData);
uint8_t mifareclassic_ReadDataBlock (uint8_t blockNumber, uint8_t * data);
uint8_t mifareclassic_WriteDataBlock (uint8_t blockNumber, uint8_t * data);

C'est tout ce dont vous avez besoin pour commencer à lire et écrire vos données... et vous pouvez vérifier vos données en utilisant l'une des nombreuses applications Android qui sont capable de fonctionner avec les cartes Mifare (une recherche sur "nfc" vous proposera plein d'application).

Quel est le niveau de support NDEF est inclus dans la bibliothèque?

Pour l'instant, toutes les fonctionnalités NDEF restent incomplètes et expérimental. Seul un code de test de base à été écrit pour formater une carte destinée à recevoir des messages NDEF de sorte que de nombreux téléphone Android supportant NFC soient capable de les interpréter. Ce programme de formatage est une façon simple mais très efficace pour réaliser une démonstration de faisabilité (proof of concept).

Adafruit voudrait améliorer le support NDEF dans le future pour les tags Mifare, il y a quelques planifications prévue sur ces tâches mais pour le moment, Adafruit propose de stocker du contenu texte pure et faire des lectures/écritures en suivant le standard original de Mifare Classic. Vous pouvez lire et écrire des blocs Mifare Classic et Mifare Ultralight depuis un Android, et vous n'avez pas besoin d'utiliser de format standard NDEF plus compliqué pour échanger des données dans les deux sens via une carte Mifare Classic ou Ultralight.

Est ce que le PN532 supporte la communication 'peer to peer' autorisant le dialogue avec mon smartphone?

Oui, le PN532 supporte la communication 'peer to peer' mais le support logiciel de cette fonctionnalité logiciel n'est pas implémenté dans la bibliothèque Adafruit.

La communication 'Peer to peer' avec Android est possible, par exemple, mais l'implémentation logiciel côté PN532 est vraiment compliquée. Vous aurez besoin de passer au travers de nombreux couches logicielles pour communiquer avec un Android (de sorte qu'il puisse le comprendre) -- cela nécessite le développement d'une stack/pile NDEF au complet pour les messages ainsi que des piles SNEP et LLCP, etc. -- l'étendue de ce type de développement va bien au delà de ce que peut offrir Adafruit pour la gamme de prix auquel est offert le matériel PN532.

Toutes les spécifications matérielles nécessaires pour réaliser cette implémentation 'peer to peer' est offert/supporté par le shield PN532 et le breakout board PN532 d'Adafruit. Cependant, produire/développer la pile logiciel n'est pas une opération triviale et augmenterait dramatiquement le prix des cartes PN532 si Adafruit devait réaliser une telle implémentation.

Adafruit à concentré ses ressources pour produire un matériel de référence fiable, éprouvé, mise au point ainsi qu'un block logiciel permettant à tout un chacun de débuter. Il reste cependant de nombreux points (trous) à combler pour couvrir toutes les fonctionnalitées prévue par NFC (et réalisable avec cette carte de développement). La combinaison matériel et logiciel proposée avec les cartes PN532 d'Adafruit restant dans un rapport qualité/prix très avantageux.

Pour un exemple de communication avec un téléphone via NFC, nous vous proposons de consulter "Talking With Your Arduino via NFC on Blackberry" qui utilise un shield NFC Adafruit. Les couches logicielles nécessaire pour une communication P2P basée sur NFC pour les périphériques Blackberry sont visiblement moins complexes que pour un Android.

Does the PN532 support tag emulation?

Oui mais dans la réalité, cela est impossible , car cela nécessaire un 'secure element' exterbe qu'il est vraiment difficile de se fournir (sous contrôle d'exportation et NDA--Non Disclosure Agreement--- chez quelques rares fabriquants).

Can the PN532 read Tag-It tags from TI?

No. The PN532 is designed to be used with ISO14443 tags, with Mifare Classic probably the most common general-purpose tag type in use. For more information on supported tags see http://www.libnfc.org/documentation/hardware/tags/iso14443 or search for information on the common Mifare tag family based on ISO1443A.

Can I set a delay calling readPassiveTargetID()?

Note: This question only applies to the I2C Library. The SPI library doesn't handle the timing the same way.

readPassiveTargetID() intentionally waits around in a blocking delay until a card enters the magnetic field. The reason for this blocking delay is to ensure a well-understood command/response flow. Once the magnetic field is activated and a read request is sent via readPassiveTargetID, you can keep sending new commands to the PN532, but the moment a card or tag enters the field, the PN532 will send a response to the initial read request, even if it's in the middle of some other response or activity. To avoid having to debug this in SW, a blocking delay was implemented to keep the command/response pattern as clear as possible.

As a workaround to this blocking-delay limitation, setPassiveActivationRetries(maxRetries) was added to the latest NFC libraries to allow you to set a specific timeout after read requests.

By default, the PN532 will wait forever for a card to enter the field. By specifying a fixed number of retries via MxRtyPassiveActivation (see UM section 7.3.1 describing the RFConfiguration register, specifically CfgItem 5) the PN532 will abort the read request after specified number of attempts, and you can safely send new commands without worrying about mixing up response frames. To wait forever, set MxRtyPassiveActivation to 0xFF. To timeout after a fixed number of retries, set MxRtyPassiveActivation to anything less than 0xFF.

Example Sketch:

#include <Wire.h>
#include <Adafruit_NFCShield_I2C.h>

#define IRQ   (2)
#define RESET (3)  // Not connected by default on the NFC Shield

Adafruit_NFCShield_I2C nfc(IRQ, RESET);

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); // 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);
  
  // Set the max number of retry attempts to read from a card
  // This prevents us from waiting forever for a card, which is
  // the default behaviour of the PN532.
  nfc.setPassiveActivationRetries(0xFF);
  
  // configure board to read RFID tags
  nfc.SAMConfig();
    
  Serial.println("Waiting for an ISO14443A card");
}

void loop(void) {
  boolean 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], &uidLength);
  
  if (success) {
    Serial.println("Found a card!");
    Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
    Serial.print("UID Value: ");
    for (uint8_t i=0; i < uidLength; i++) 
    {
      Serial.print(" 0x");Serial.print(uid[i], HEX); 
    }
    Serial.println("");
    // Wait 1 second before continuing
    delay(1000);
  }
  else
  {
    // PN532 probably timed out waiting for a card
    Serial.println("Timed out waiting for a card");
  }
}

Hey wait ... isn't there something funny with the SVDD pin?

Indeed, good eye! Unfortunately, both v1.0 and v1.3 of the breakout boards have a problem on the schematic. SVDD is connected directly to VDD, but should be left floating since it is used to power secure modules. This has no effect on the functionality of the boards, but does cause some extra current to be drawn. It will be fixed on the next revision of the board, but if you require the use of the secure modules (rare), you can simply cut the trace to the left of C22, which is the cap connected to SVDD (just follow the trace straight up from pin 37).

Are there any special requirements to use the PN532 Breakout with the Due?

While the libraries do not officially support the Due yet, some customers have been able to get them working with some minor changes to the library.

We recommend using the I2C libraries with both the shield and the breakout boards since the I2C library represents the latest code from Adafruit, and the shield version should work without too much effort.

There is one caveat combining the breakout, I2C and the Due, though: The Due includes pullup resistors for I2C0 (SCL0 and SDA1), but there are no pullups resistors on SCL1 and SDA1. SCL1/SDA1 are the pins used as replacements for the Uno I2C pins (the pins used on standard shields), so you will need to add two 1.5K pullups on SCL1 and SDA1 to use the breakout board with I2C1 and the Due. Simply solder two 1.5K resistors, one from SCL1 to 3V3 and another from SDA1 to 3.3V, and then connect the board the same way you would with an Uno.

This issue only applies to the PN532 Breakout board since the PN532 shield includes I2C pullup resistors right on board.


Source: PN532 RFID/NFC Breakout and Shield créé par LadyAda pour AdaFruit Industries. Crédit [www.adafruit.com AdaFruit Industries]

Traduit par Meurisse D. pour MCHobby.be

Traduit avec l'autorisation d'AdaFruit Industries - Translated with the permission from Adafruit Industries - www.adafruit.com

Toute référence, mention ou extrait de cette traduction doit être explicitement accompagné du texte suivant : «  Traduction par MCHobby (www.MCHobby.be) - Vente de kit et composants » avec un lien vers la source (donc cette page) et ce quelque soit le média utilisé.

L'utilisation commercial de la traduction (texte) et/ou réalisation, même partielle, pourrait être soumis à redevance. Dans tous les cas de figures, vous devez également obtenir l'accord du(des) détenteur initial des droits. Celui de MC Hobby s'arrêtant au travail de traduction proprement dit.