Added extra RFID readers

Fork of RFID-RC522 by Thomas Kirchner

Files at this revision

API Documentation at this revision

Comitter:
andcor02
Date:
Fri Jun 22 09:41:42 2018 +0000
Parent:
2:a0c7513fb634
Child:
4:320ce84c8f43
Commit message:
Added extra RFID readers

Changed in this revision

MFRC522.cpp Show annotated file Show diff for this revision Revisions of this file
MFRC522.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show diff for this revision Revisions of this file
--- a/MFRC522.cpp	Fri Jun 06 03:04:48 2014 +0000
+++ b/MFRC522.cpp	Fri Jun 22 09:41:42 2018 +0000
@@ -55,7 +55,8 @@
 {
   /* Configure SPI bus */
   m_SPI.format(8, 0);
-  m_SPI.frequency(8000000);
+//  m_SPI.frequency(8000000);
+  m_SPI.frequency(1000000);
 
   /* Release SPI-CS pin */
   m_CS       = 1;
@@ -240,6 +241,16 @@
 /////////////////////////////////////////////////////////////////////////////////////
 // Functions for manipulating the MFRC522
 /////////////////////////////////////////////////////////////////////////////////////
+void MFRC522::PCD_Reset_On()
+{
+    m_RESET = 0;
+}
+
+void MFRC522::PCD_Reset_Off()
+{
+    m_RESET = 1;
+}
+
 
 /**
  * Initializes the MFRC522 chip.
--- a/MFRC522.h	Fri Jun 06 03:04:48 2014 +0000
+++ b/MFRC522.h	Fri Jun 22 09:41:42 2018 +0000
@@ -343,8 +343,15 @@
   // ************************************************************************************
   //@{
 
+    
+   void PCD_Reset_On (void);
+   
+   void PCD_Reset_Off (void);
+
   /**
   * Initializes the MFRC522 chip.
+  
+  
   */
   void    PCD_Init           (void);
 
--- a/main.cpp	Fri Jun 06 03:04:48 2014 +0000
+++ b/main.cpp	Fri Jun 22 09:41:42 2018 +0000
@@ -1,3 +1,5 @@
+
+
 //Test of cheap 13.56 Mhz RFID-RC522 module from eBay
 //This code is based on Martin Olejar's MFRC522 library. Minimal changes
 //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too
@@ -11,57 +13,72 @@
 //RFID SCK=pin2    ->   Nucleo SPI_SCK =PA_5=D13
 //RFID SDA=pin1    ->   Nucleo SPI_CS  =PB_6=D10
 //RFID RST=pin7    ->   Nucleo         =PA_9=D8
-//3.3V and Gnd to the respective pins                              
-                              
+//3.3V and Gnd to the respective pins
+
 #include "mbed.h"
 #include "MFRC522.h"
 
-// Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
-#define MF_RESET    D8
-
 DigitalOut LedGreen(LED1);
 
 //Serial connection to PC for output
-Serial pc(SERIAL_TX, SERIAL_RX);
+Serial pc(USBTX, USBRX);
 
-MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
 
-int main(void) {
-  pc.printf("starting...\n");
+//MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
+MFRC522    RfChip   (PTD2, PTD3, PTD1, PTD0, PTC4);
+//MFRC522    RfChip2   (PTD2, PTD3, PTD1, PTC3, PTC2); //Adding extra sensors if needed
+//MFRC522    RfChip3   (PTD2, PTD3, PTD1, PTA2, PTB23);
 
-  // Init. RC522 Chip
-  RfChip.PCD_Init();
+int main(void)
+{
+    pc.printf("starting...\n");
 
-  while (true) {
-    LedGreen = 1;
+    // Init. RC522 Chip
+    RfChip.PCD_Init();
+//    RfChip2.PCD_Init();
+//    RfChip3.PCD_Init();
 
-    // Look for new cards
-    if ( ! RfChip.PICC_IsNewCardPresent())
-    {
-      wait_ms(500);
-      continue;
-    }
+    while (true) {
+        LedGreen = 1;
+
+        if ( RfChip.PICC_IsNewCardPresent()) {
+            if (RfChip.PICC_ReadCardSerial()) {
+
+                LedGreen = 0;
 
-    // Select one of the cards
-    if ( ! RfChip.PICC_ReadCardSerial())
-    {
-      wait_ms(500);
-      continue;
-    }
+                pc.printf("Card Reader 1: ");
+                for (uint8_t i = 0; i < RfChip.uid.size; i++) {
+                    pc.printf(" %X02", RfChip.uid.uidByte[i]);
+                }
+                pc.printf("\n\r");
+            }
+        }
 
-    LedGreen = 0;
+/*      if ( RfChip2.PICC_IsNewCardPresent()) {
+            if (RfChip2.PICC_ReadCardSerial()) {
+
+                        LedGreen = 0;
 
-    // Print Card UID
-    pc.printf("Card UID: ");
-    for (uint8_t i = 0; i < RfChip.uid.size; i++)
-    {
-      pc.printf(" %X02", RfChip.uid.uidByte[i]);
+                        pc.printf("Card Reader 2: ");
+                        for (uint8_t i = 0; i < RfChip2.uid.size; i++) {
+                            pc.printf(" %X02", RfChip2.uid.uidByte[i]);
+                        }
+                        pc.printf("\n\r");
+                    }
+                }
+
+                if ( RfChip3.PICC_IsNewCardPresent()) {
+                    if (RfChip3.PICC_ReadCardSerial()) {
+
+                        LedGreen = 0;
+
+                        pc.printf("Card Reader 3: ");
+                        for (uint8_t i = 0; i < RfChip3.uid.size; i++) {
+                            pc.printf(" %X02", RfChip3.uid.uidByte[i]);
+                        }
+                        pc.printf("\n\r");
+                    }
+                }*/
+
     }
-    pc.printf("\n\r");
-
-    // Print Card type
-    uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
-    pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
-    wait_ms(1000);
-  }
-}
\ No newline at end of file
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-os.lib	Fri Jun 22 09:41:42 2018 +0000
@@ -0,0 +1,1 @@
+https://github.com/ARMmbed/mbed-os/#03196b244ee00fc748cd4dbfa83b26f3fc0f376b
--- a/mbed.bld	Fri Jun 06 03:04:48 2014 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/0b3ab51c8877
\ No newline at end of file