RTFDS / Mbed 2 deprecated RFID-RC522Driver

Dependencies:   mbed

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 //RFID-RC522 
00002 //Bazirano na Martin Olejar's MFRC522 library.
00003 
00004 //Connect as follows:
00005 //RFID pins        ->  Nucleo header CN5 (Arduino-compatible header)
00006 //----------------------------------------
00007 //RFID IRQ=pin5    ->   Not used. Leave open
00008 //RFID MISO=pin4   ->   Nucleo SPI_MISO=PA_6=D12
00009 //RFID MOSI=pin3   ->   Nucleo SPI_MOSI=PA_7=D11
00010 //RFID SCK=pin2    ->   Nucleo SPI_SCK =PA_5=D13
00011 //RFID SDA=pin1    ->   Nucleo SPI_CS  =PB_6=D10
00012 //RFID RST=pin7    ->   Nucleo         =PA_9=D8
00013 //3.3V and Gnd to the respective pins                              
00014                               
00015 #include "mbed.h"
00016 #include "MFRC522.h"
00017 
00018 
00019 
00020 DigitalOut LedGreen(LED1);
00021 
00022 //Serial connection to PC for output
00023 Serial pc(USBTX, USBRX);
00024 
00025 MFRC522    RfChip   (p5,p6,p7,p8,p9);
00026 
00027 int main(void) {
00028   uint8_t test [4];
00029   pc.printf("starting...\n");
00030 
00031   // Init. RC522 Chip
00032   RfChip.PCD_Init();
00033 
00034   while (true) {
00035     LedGreen = 1;
00036 
00037     // Look for new cards
00038     if ( ! RfChip.PICC_IsNewCardPresent())
00039     {
00040       wait_ms(500);
00041       continue;
00042     }
00043     
00044     // Select one of the cards
00045     if ( ! RfChip.PICC_ReadCardSerial())
00046     {
00047       wait_ms(500);
00048       continue;
00049     }
00050 
00051     LedGreen = 0;
00052 
00053     // Print Card UID
00054     pc.printf("Card UID: ");
00055     for (uint8_t i = 0; i < RfChip.uid.size; i++)
00056     {
00057       pc.printf(" %0X02", RfChip.uid.uidByte[i]);
00058       
00059     }
00060     pc.printf("\n\r");
00061     if(RfChip.uid.uidByte[0]==23)
00062       {
00063         pc.printf("dobra\n");
00064       }
00065     else if(RfChip.uid.uidByte[0]!=23)
00066     {
00067         pc.printf("kriva\n");
00068     }
00069     wait_ms(1000);
00070   }
00071 }