FRA221:A / Mbed 2 deprecated Lost-Found_BOX

Dependencies:   NOKIA_5110 mbed

Fork of Lost-Found_BOX by Tanut Choksatchawathi

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 //Test of cheap 13.56 Mhz RFID-RC522 module from eBay
00002 //This code is based on Martin Olejar's MFRC522 library. Minimal changes
00003 //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too
00004 
00005 //Connect as follows:
00006 //RFID pins        ->  Nucleo header CN5 (Arduino-compatible header)
00007 //----------------------------------------
00008 //RFID IRQ=pin5    ->   Not used. Leave open
00009 //RFID MISO=pin4   ->   Nucleo SPI_MISO=PA_6=D12
00010 //RFID MOSI=pin3   ->   Nucleo SPI_MOSI=PA_7=D11
00011 //RFID SCK=pin2    ->   Nucleo SPI_SCK =PA_5=D13
00012 //RFID SDA=pin1    ->   Nucleo SPI_CS  =PB_6=D10
00013 //RFID RST=pin7    ->   Nucleo         =PA_9=D8
00014 //3.3V and Gnd to the respective pins                              
00015                               
00016 #include "mbed.h"
00017 #include "MFRC522.h"
00018 #include "NOKIA_5110.h"
00019 // Nucleo Pin for MFRC522 reset (pick another D pin if you need D8)
00020 #define MF_RESET    D8
00021 
00022 DigitalOut LedGreen(LED1);
00023 DigitalOut spi_address[2] = {SPI_CS,PA_9};
00024 //Serial connection to PC for output
00025 Serial pc(SERIAL_TX, SERIAL_RX);
00026 PwmOut speaker(D3);
00027 MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET);
00028 
00029 
00030     
00031     
00032 int main(void) {
00033         
00034         LcdPins myPins;   
00035 //    myPins.sce  = PB_6;   
00036     myPins.sce  = PB_4; //D5
00037     myPins.rst  = PB_10; //D6
00038     myPins.dc   = PA_8; //D7
00039     myPins.mosi = PA_7; //SPI_MOSI;
00040     myPins.miso = NC;
00041     myPins.sclk = PA_5; //SPI_SCK;    
00042       NokiaLcd myLcd( myPins );
00043  
00044     myLcd.InitLcd();                // LCD is reset and DDRAM is cleared
00045     myLcd.DrawString("Hello");   
00046     myLcd.stop();
00047   //RfChip.start();
00048   pc.printf("starting...\n");
00049 
00050   // Init. RC522 Chip
00051   RfChip.PCD_Init();
00052   pc.printf("Begin RFID!\n");
00053   while (true) {
00054     LedGreen = 1;
00055     // Look for new cards
00056     if ( ! RfChip.PICC_IsNewCardPresent())
00057     {
00058       wait_ms(500);
00059       continue;
00060     }
00061 
00062     // Select one of the cards
00063     if ( ! RfChip.PICC_ReadCardSerial())
00064     {
00065       wait_ms(500);
00066       continue;
00067     }
00068 
00069     LedGreen = 0;
00070 
00071     // Print Card UID
00072     pc.printf("Card UID: ");
00073     for (uint8_t i = 0; i < RfChip.uid.size; i++)
00074     {
00075       pc.printf(" %X02", RfChip.uid.uidByte[i]);
00076     }
00077     pc.printf("\n\r");
00078 
00079     // Print Card type
00080     uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
00081     pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
00082     wait_ms(1000);
00083     
00084   }
00085   
00086 }