Individální projekty MPOA

Mikroprocesory s architekturou ARM

Uživatelské nástroje

Nástroje pro tento web


gpoa2019:nfc-reader-rc522

Rozdíly

Zde můžete vidět rozdíly mezi vybranou verzí a aktuální verzí dané stránky.

Odkaz na výstup diff

Následující verze
Předchozí verze
gpoa2019:nfc-reader-rc522 [2019/05/01 20:42]
Hana Vrtělková vytvořeno
gpoa2019:nfc-reader-rc522 [2019/05/01 23:09] (aktuální)
Hana Vrtělková source code
Řádek 1: Řádek 1:
 ====== NFC card reader with RC522 ======= ====== NFC card reader with RC522 =======
 Vypracoval: Hana Vrtělková Vypracoval: Hana Vrtělková
 +----
  
 ===== Assignment ===== ===== Assignment =====
Řádek 31: Řádek 32:
  
 ===== Software part ===== ===== Software part =====
 +The application was created in Arduino API using SPI and MFRC522 libraries.
 +
 +==== Initialization ====
 +Using implemented function Serial.begin(9600) to initialize serial communication with the PC with given baud rate 9600. SPI.begin() is function from SPI library which initialize the communication via SPI bus. Then the function PCD_Init which initialize the MFRC522 so we can transmit information.
 +
 +<code c>
 +void setup() {
 +  // put your setup code here, to run once:
 +  Serial.begin(9600); ​  // Initialize serial communications with the PC
 +  while (!Serial); ​   // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
 +  SPI.begin(); ​     // Init SPI bus
 +  mfrc522.PCD_Init(); ​  // Init MFRC522
 +  Serial.println(F("​Scan PICC to see UID, SAK, type, and data blocks..."​));​
 +}
 +</​code>​
 +
 +==== Reading ====
 +Reading of the card's content is done using another function of the library MFRC522. Function PICC_DumpDetailsToSerial is used for writing basic information such as card uid, SAK and PICC type. Then depending on the PICC type the authorization is made via KeyA.
 +
 +<code c>
 +  MFRC522::​MIFARE_Key key;
 +  mfrc522.PICC_DumpDetailsToSerial(&​(mfrc522.uid));​
 +  MFRC522::​PICC_Type piccType;
 +  piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);​
 +  switch (piccType) {
 +    case MFRC522::​PICC_TYPE_MIFARE_MINI:​
 +    case MFRC522::​PICC_TYPE_MIFARE_1K:​
 +    case MFRC522::​PICC_TYPE_MIFARE_4K:​
 +      // All keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
 +      for (byte i = 0; i < 6; i++) {
 +        key.keyByte[i] = 0xFF;
 +      }
 +      mfrc522.PICC_DumpMifareClassicToSerial(&​(mfrc522.uid),​ piccType, &key);
 +      break;
 +      ​
 +    case MFRC522::​PICC_TYPE_MIFARE_UL:​
 +      mfrc522.PICC_DumpMifareUltralightToSerial();​
 +      break;
 +      ​
 +    case MFRC522::​PICC_TYPE_ISO_14443_4:​
 +    case MFRC522::​PICC_TYPE_MIFARE_DESFIRE:​
 +    case MFRC522::​PICC_TYPE_ISO_18092:​
 +    case MFRC522::​PICC_TYPE_MIFARE_PLUS:​
 +    case MFRC522::​PICC_TYPE_TNP3XXX:​
 +      Serial.println(F("​Dumping memory contents not implemented for that PICC type."​));​
 +      break;
 +      ​
 +    case MFRC522::​PICC_TYPE_UNKNOWN:​
 +    case MFRC522::​PICC_TYPE_NOT_COMPLETE:​
 +    default:
 +      break; // No memory dump here
 +  }
 +</​code>​
 +
 +===== Principle =====
 +First of all it is necessary to initialize the communication vai SPI so we can send command from board to the RFID reader. It also includes defining the clock frequency so the communication can be synchronised. Than it is necessary to initialize the MFRC522 reader which is done by sending command to the adresses defined in hexadecimal values. For example to define RX and TX mode which defines reception/​transmission data rate and framing, and you also turn on the antenna.
 +
 +When the reader functions the way it should we can use it to transmit commands to the card. 
 +
 +==== Communication principle of the card ====
 +First is request standard/​all. After Power on resetthe card answers to a request REQA or wakeup WUPA command with the answer to the request code.
 +
 +In anticollision loop the identifier of the card is readed. But this part can be omitted.
 +
 +Select part. With this command the reader selects one card for authentification. The card returns Select AcKnowledgement (SAK) code which determines the type of selected card.
 +
 +Three pass authentification. After the selection the reader specifies the memory location of the following memory access and uses the coresponding key to three pass authentification procedure.
 +
 +After succesfull authenticication can be performed memory operations such as read block, write block.
 +
 +=== Example of commands ===
 +^Command ​                           ^ISO/IEC 14443       ​^Command code (hexadecimal) ​         ^
 +| Request ​                          | REQA               | 26h (7 bit)                        |
 +| Wake-up ​                          | WUPA               | 52h (7bit) ​                        |
 +| Select CL1                        | Select CL1         | 93h 70h                            |
 +| Authetification with key A        | -                  | 60h                                |
 +
 +===== Source code =====
 +Libraries not included (SPI library implemented in Arduino API, MFRC522 library can be downloaded on internet).\\
 +[[https://​drive.google.com/​open?​id=1QvRs6nWOJhlTx936un_5Fq0XPvoUjxam]]
 +
 +===== Summary =====
 +Initial idea was to write the application in pure C. Unfortunatelly inicialization of the communication vai SPI and initialization of the MFRC522 and right framing of the commands for authentification was quite complicated and time-consuming. The realization was made in Arduino API using build in library for SPI and downloaded library for MFRC522 which simplified the application.\\
 +Application can not write any information into the card.
 +
 +===== Short video =====
 +{{https://​youtu.be/​fw8XuA8u60U}}
 +
 +===== References =====
 +MFRC522 library:\\
 +[[https://​www.arduinolibraries.info/​libraries/​mfrc522]]
 +
 +Data sheets:\\
 +[[https://​www.nxp.com/​docs/​en/​data-sheet/​MF1S50YYX_V1.pdf?​fbclid=IwAR1lF3yzJMDJ8S5kAtc6kM9QkILn4_KPIstq8xaJ7dioMutrpV0eTIXd9zI]]\\
 +[[https://​www.nxp.com/​docs/​en/​data-sheet/​MFRC522.pdf]]
 +
 +Images for scheme:\\
 +[[https://​www.amazon.com/​SmartProjects-Mega-Arduino-MEGA-Board/​dp/​B004A7H3DG]]\\
 +[[https://​www.makerfabs.com/​index.php?​route=product/​product&​product_id=66]]
gpoa2019/nfc-reader-rc522.1556736124.txt.gz · Poslední úprava: 2019/05/01 20:42 autor: Hana Vrtělková