E2PRO2 / Mbed 2 deprecated RFID-demo-team2

Dependencies:   mbed

Revision:
3:2507fc42675c
Parent:
2:a0c7513fb634
Child:
4:60f9b48d9eb6
--- a/main.cpp	Fri Jun 06 03:04:48 2014 +0000
+++ b/main.cpp	Tue Apr 30 14:18:34 2019 +0000
@@ -1,33 +1,50 @@
-//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
+/*
+ * File       : main.cpp
+ * License    : MIT License
+ * Version    : 0.9
+ * Author     : Janus Bo Andersen (JA67494)
+ * Last edit  : Janus
+ * Created on : 27 Apr 2019
+ * Last change: 30 Apr 2019
+ * Description: Demo program for Mifare RC-522 RFID reader/writer chip.
+ *            : Communicates with RFID reader, transmits card numbers to terminal
+ *            : and toggles a digital pin upon reading a card.
+ * Structure  : Uses SPI protocol to communicate with the RFID
+ *            : Uses U(S)ART to communicate with connected computer/terminal.
+ * Adapted for: STM32 Nucleo L432KC, but can be adapted for NXP KL25Z.
+ */
 
-//Connect as follows:
-//RFID pins        ->  Nucleo header CN5 (Arduino-compatible header)
-//----------------------------------------
-//RFID IRQ=pin5    ->   Not used. Leave open
-//RFID MISO=pin4   ->   Nucleo SPI_MISO=PA_6=D12
-//RFID MOSI=pin3   ->   Nucleo SPI_MOSI=PA_7=D11
-//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                              
-                              
+/*Connect as follows:
+  (should be connected to board standard pins)
+  RFID pins          ->   Nucleo header CN5 (Arduino-compatible header)
+  ----------------------------------------
+  RFID IRQ  = pin5   ->   Not used. Leave open
+  RFID MISO = pin4   ->   Nucleo SPI_MISO = PA_6 = D12
+  RFID MOSI = pin3   ->   Nucleo SPI_MOSI = PA_7 = D11
+  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
+
+Power supply MUST BE 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)
+// Nucleo Pin for MFRC522 reset
 #define MF_RESET    D8
 
-DigitalOut LedGreen(LED1);
+DigitalOut LedGreen(LED1); //for showing active signal on dev board
+DigitalOut LedPower(A2); //for toggling MOSFET
 
 //Serial connection to PC for output
 Serial pc(SERIAL_TX, SERIAL_RX);
 
-MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
+//RFID object instantiated using board standard pins (find in your library)
+MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
 
 int main(void) {
   pc.printf("starting...\n");
+  LedPower = 0;
 
   // Init. RC522 Chip
   RfChip.PCD_Init();
@@ -42,16 +59,19 @@
       continue;
     }
 
-    // Select one of the cards
+    // Select one of the cards (avoiding collisions of multiple cards)
     if ( ! RfChip.PICC_ReadCardSerial())
     {
       wait_ms(500);
       continue;
     }
 
-    LedGreen = 0;
+    LedGreen = 0; //blink off
 
-    // Print Card UID
+    //Toggle signal to the MOSFET
+    
+    LedPower = !LedPower;    
+    // Print Card UID to serial interface
     pc.printf("Card UID: ");
     for (uint8_t i = 0; i < RfChip.uid.size; i++)
     {