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 /** 00002 * MFRC522 example 00003 */* 00004 00005 #include "mbed.h" 00006 #include "MFRC522.h" 00007 00008 //KL25Z Pins for MFRC522 SPI interface 00009 #define SPI_MOSI PTC6 00010 #define SPI_MISO PTC7 00011 #define SPI_SCLK PTC5 00012 #define SPI_CS PTC4 00013 // KL25Z Pin for MFRC522 reset 00014 #define MF_RESET PTC3 00015 // KL25Z Pins for Debug UART port 00016 #define UART_RX PTA1 00017 #define UART_TX PTA2 00018 00019 DigitalOut LedRed (LED_RED); 00020 DigitalOut LedGreen (LED_GREEN); 00021 00022 Serial DebugUART(UART_TX, UART_RX); 00023 MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET); 00024 00025 int main(void) { 00026 // Set debug UART speed 00027 DebugUART.baud(115200); 00028 00029 // Init. RC522 Chip 00030 RfChip.PCD_Init(); 00031 00032 while (true) { 00033 LedRed = 1; 00034 LedGreen = 1; 00035 00036 // Look for new cards 00037 if ( ! RfChip.PICC_IsNewCardPresent()) 00038 { 00039 wait_ms(500); 00040 continue; 00041 } 00042 00043 LedRed = 0; 00044 00045 // Select one of the cards 00046 if ( ! RfChip.PICC_ReadCardSerial()) 00047 { 00048 wait_ms(500); 00049 continue; 00050 } 00051 00052 LedRed = 1; 00053 LedGreen = 0; 00054 00055 // Print Card UID 00056 printf("Card UID: "); 00057 for (uint8_t i = 0; i < RfChip.uid.size; i++) 00058 { 00059 printf(" %X02", RfChip.uid.uidByte[i]); 00060 } 00061 printf("\n\r"); 00062 00063 // Print Card type 00064 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); 00065 printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); 00066 wait_ms(1000); 00067 } 00068 } 00069
Generated on Thu Sep 15 2022 23:09:02 by
1.7.2