![](/media/cache/profiles/ndu.jpg.50x50_q85.jpg)
rc522 project
Fork of RFID-RC522 by
Diff: main.cpp
- Revision:
- 3:654723104cc9
- Parent:
- 2:a0c7513fb634
- Child:
- 4:320ce84c8f43
diff -r a0c7513fb634 -r 654723104cc9 main.cpp --- 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 +}