Andrea Corrado / Mbed OS RFID-RC522

Fork of RFID-RC522 by Thomas Kirchner

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 
00002 
00003 //Test of cheap 13.56 Mhz RFID-RC522 module from eBay
00004 //This code is based on Martin Olejar's MFRC522 library. Minimal changes
00005 //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too
00006 
00007 //Connect as follows:
00008 //RFID pins        ->  Nucleo header CN5 (Arduino-compatible header)
00009 //----------------------------------------
00010 //RFID IRQ=pin5    ->   Not used. Leave open
00011 //RFID MISO=pin4   ->   Nucleo SPI_MISO=PA_6=D12
00012 //RFID MOSI=pin3   ->   Nucleo SPI_MOSI=PA_7=D11
00013 //RFID SCK=pin2    ->   Nucleo SPI_SCK =PA_5=D13
00014 //RFID SDA=pin1    ->   Nucleo SPI_CS  =PB_6=D10
00015 //RFID RST=pin7    ->   Nucleo         =PA_9=D8
00016 //3.3V and Gnd to the respective pins
00017 
00018 #include "mbed.h"
00019 #include "MFRC522.h"
00020 
00021 DigitalOut LedGreen(LED2);
00022 
00023 //Serial connection to PC for output
00024 Serial pc(USBTX, USBRX);
00025 
00026 
00027 //MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
00028 MFRC522    RfChip   (PTD2, PTD3, PTD1, PTD0, PTC4);
00029 //MFRC522    RfChip2   (PTD2, PTD3, PTD1, PTC3, PTC2); //Adding extra sensors if needed
00030 //MFRC522    RfChip3   (PTD2, PTD3, PTD1, PTA2, PTB23);
00031 
00032 int main(void)
00033 {
00034     pc.printf("starting...\n");
00035 
00036     // Init. RC522 Chip
00037     RfChip.PCD_Init();
00038 //    RfChip2.PCD_Init();
00039 //    RfChip3.PCD_Init();
00040 
00041     while (true) {
00042         LedGreen = 1;
00043 
00044         if ( RfChip.PICC_IsNewCardPresent()) {
00045             if (RfChip.PICC_ReadCardSerial()) {
00046 
00047                 LedGreen = 0;
00048 
00049                 pc.printf("Card Reader 1: ");
00050                 for (uint8_t i = 0; i < RfChip.uid.size; i++) {
00051                     pc.printf(" %X02", RfChip.uid.uidByte[i]);
00052                 }
00053                 pc.printf("\n\r");
00054                 wait_ms(200);
00055             }
00056         }
00057         
00058 
00059 /*      if ( RfChip2.PICC_IsNewCardPresent()) {
00060             if (RfChip2.PICC_ReadCardSerial()) {
00061 
00062                         LedGreen = 0;
00063 
00064                         pc.printf("Card Reader 2: ");
00065                         for (uint8_t i = 0; i < RfChip2.uid.size; i++) {
00066                             pc.printf(" %X02", RfChip2.uid.uidByte[i]);
00067                         }
00068                         pc.printf("\n\r");
00069                     }
00070                 }
00071 
00072                 if ( RfChip3.PICC_IsNewCardPresent()) {
00073                     if (RfChip3.PICC_ReadCardSerial()) {
00074 
00075                         LedGreen = 0;
00076 
00077                         pc.printf("Card Reader 3: ");
00078                         for (uint8_t i = 0; i < RfChip3.uid.size; i++) {
00079                             pc.printf(" %X02", RfChip3.uid.uidByte[i]);
00080                         }
00081                         pc.printf("\n\r");
00082                     }
00083                 }*/
00084 
00085     }
00086 }