![](/media/cache/profiles/ndu.jpg.50x50_q85.jpg)
rc522 project
Fork of RFID-RC522 by
Diff: main.cpp
- Revision:
- 5:5ec7ea8ccd90
- Parent:
- 4:320ce84c8f43
--- a/main.cpp Fri Jun 22 09:59:36 2018 +0000 +++ b/main.cpp Thu Sep 20 11:21:00 2018 +0000 @@ -12,75 +12,61 @@ //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 +//RFID RST=pin7 -> Nucleo =PA_9=D9 //3.3V and Gnd to the respective pins #include "mbed.h" #include "MFRC522.h" -DigitalOut LedGreen(LED2); +#define VERSION 1 //Serial connection to PC for output Serial pc(USBTX, USBRX); +DigitalIn userButton(USER_BUTTON); -//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); + + int main(void) { + pc.baud(115200); pc.printf("starting...\n"); - - // Init. RC522 Chip - RfChip.PCD_Init(); -// RfChip2.PCD_Init(); -// RfChip3.PCD_Init(); - - while (true) { - LedGreen = 1; - - if ( RfChip.PICC_IsNewCardPresent()) { - if (RfChip.PICC_ReadCardSerial()) { - - LedGreen = 0; - - pc.printf("Card Reader 1: "); - for (uint8_t i = 0; i < RfChip.uid.size; i++) { - pc.printf(" %X02", RfChip.uid.uidByte[i]); + + while(1){ + + if(userButton == 0){ + printf(">>> start reading <<<\n"); + + MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, D8); + + /** a test for static asserts */ + MBED_STATIC_ASSERT(VERSION < 5, "Version to high"); + + RfChip.PCD_Init(); + + while (userButton == 0) { + + if ( RfChip.PICC_IsNewCardPresent()) { + if (RfChip.PICC_ReadCardSerial()) { + + 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"); + + printf("PICC Type: %s \n", + RfChip.PICC_GetTypeName(RfChip.PICC_GetType(RfChip.uid.sak))); + } } - pc.printf("\n\r"); - wait_ms(200); } + + printf(">>> end reading <<<\n"); } - + + //MBED_ASSERT(userButton == 1); + } + -/* if ( RfChip2.PICC_IsNewCardPresent()) { - if (RfChip2.PICC_ReadCardSerial()) { - - LedGreen = 0; - - 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"); - } - }*/ - - } }