Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
00001 //Connect as follows: 00002 //RFID pins -> Nucleo header CN5 (Arduino-compatible header) 00003 //---------------------------------------- 00004 //RFID IRQ=pin5 -> Not used. Leave open 00005 //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 00006 //RFID MOSI=pin3 -> Nucleo SPI_MOSI=PA_7=D11 00007 //RFID SCK=pin2 -> Nucleo SPI_SCK =PA_5=D13 00008 //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 00009 //RFID RST=pin7 -> Nucleo =PA_9=D8 00010 //3.3V and Gnd to the respective pins 00011 00012 #include "mbed.h" 00013 #include "MFRC522.h" 00014 00015 // Nucleo Pin for MFRC522 reset (pick another D pin if you need D8) 00016 #define MF_RESET p8 00017 00018 DigitalOut LedGreen(p24); 00019 00020 //Serial connection to PC for output 00021 Serial pc(p9, p10); 00022 00023 MFRC522 RfChip (p11, p12, p13, p14, MF_RESET); 00024 00025 int main(void) { 00026 pc.baud(9600); 00027 00028 pc.printf("starting...\n"); 00029 00030 wait(1); 00031 00032 // Init. RC522 Chip 00033 RfChip.PCD_Init(); 00034 00035 while (true) { 00036 LedGreen = 1; 00037 00038 // Look for new cards 00039 if ( ! RfChip.PICC_IsNewCardPresent()) 00040 { 00041 wait_ms(500); 00042 continue; 00043 } 00044 00045 // Select one of the cards 00046 if ( ! RfChip.PICC_ReadCardSerial()) 00047 { 00048 wait_ms(500); 00049 continue; 00050 } 00051 00052 LedGreen = 0; 00053 00054 // Print Card UID 00055 pc.printf("Card UID: "); 00056 for (uint8_t i = 0; i < RfChip.uid.size; i++) 00057 { 00058 pc.printf(" %X02", RfChip.uid.uidByte[i]); 00059 } 00060 pc.printf("\n\r"); 00061 00062 // Print Card type 00063 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); 00064 pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); 00065 wait_ms(1000); 00066 } 00067 }
Generated on Thu Jul 21 2022 16:05:53 by
1.7.2