Andrea Corrado
/
RFID-RC522
Added extra RFID readers
Fork of RFID-RC522 by
main.cpp@3:654723104cc9, 2018-06-22 (annotated)
- Committer:
- andcor02
- Date:
- Fri Jun 22 09:41:42 2018 +0000
- Revision:
- 3:654723104cc9
- Parent:
- 2:a0c7513fb634
- Child:
- 4:320ce84c8f43
Added extra RFID readers
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 3:654723104cc9 | 1 | |
andcor02 | 3:654723104cc9 | 2 | |
kirchnet | 2:a0c7513fb634 | 3 | //Test of cheap 13.56 Mhz RFID-RC522 module from eBay |
kirchnet | 2:a0c7513fb634 | 4 | //This code is based on Martin Olejar's MFRC522 library. Minimal changes |
kirchnet | 2:a0c7513fb634 | 5 | //Adapted for Nucleo STM32 F401RE. Should work on other Nucleos too |
kirchnet | 2:a0c7513fb634 | 6 | |
kirchnet | 2:a0c7513fb634 | 7 | //Connect as follows: |
kirchnet | 2:a0c7513fb634 | 8 | //RFID pins -> Nucleo header CN5 (Arduino-compatible header) |
kirchnet | 2:a0c7513fb634 | 9 | //---------------------------------------- |
kirchnet | 2:a0c7513fb634 | 10 | //RFID IRQ=pin5 -> Not used. Leave open |
kirchnet | 2:a0c7513fb634 | 11 | //RFID MISO=pin4 -> Nucleo SPI_MISO=PA_6=D12 |
kirchnet | 2:a0c7513fb634 | 12 | //RFID MOSI=pin3 -> Nucleo SPI_MOSI=PA_7=D11 |
kirchnet | 2:a0c7513fb634 | 13 | //RFID SCK=pin2 -> Nucleo SPI_SCK =PA_5=D13 |
kirchnet | 2:a0c7513fb634 | 14 | //RFID SDA=pin1 -> Nucleo SPI_CS =PB_6=D10 |
kirchnet | 2:a0c7513fb634 | 15 | //RFID RST=pin7 -> Nucleo =PA_9=D8 |
andcor02 | 3:654723104cc9 | 16 | //3.3V and Gnd to the respective pins |
andcor02 | 3:654723104cc9 | 17 | |
kirchnet | 2:a0c7513fb634 | 18 | #include "mbed.h" |
kirchnet | 2:a0c7513fb634 | 19 | #include "MFRC522.h" |
kirchnet | 2:a0c7513fb634 | 20 | |
kirchnet | 2:a0c7513fb634 | 21 | DigitalOut LedGreen(LED1); |
kirchnet | 2:a0c7513fb634 | 22 | |
kirchnet | 2:a0c7513fb634 | 23 | //Serial connection to PC for output |
andcor02 | 3:654723104cc9 | 24 | Serial pc(USBTX, USBRX); |
kirchnet | 2:a0c7513fb634 | 25 | |
kirchnet | 2:a0c7513fb634 | 26 | |
andcor02 | 3:654723104cc9 | 27 | //MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, MF_RESET); |
andcor02 | 3:654723104cc9 | 28 | MFRC522 RfChip (PTD2, PTD3, PTD1, PTD0, PTC4); |
andcor02 | 3:654723104cc9 | 29 | //MFRC522 RfChip2 (PTD2, PTD3, PTD1, PTC3, PTC2); //Adding extra sensors if needed |
andcor02 | 3:654723104cc9 | 30 | //MFRC522 RfChip3 (PTD2, PTD3, PTD1, PTA2, PTB23); |
kirchnet | 2:a0c7513fb634 | 31 | |
andcor02 | 3:654723104cc9 | 32 | int main(void) |
andcor02 | 3:654723104cc9 | 33 | { |
andcor02 | 3:654723104cc9 | 34 | pc.printf("starting...\n"); |
kirchnet | 2:a0c7513fb634 | 35 | |
andcor02 | 3:654723104cc9 | 36 | // Init. RC522 Chip |
andcor02 | 3:654723104cc9 | 37 | RfChip.PCD_Init(); |
andcor02 | 3:654723104cc9 | 38 | // RfChip2.PCD_Init(); |
andcor02 | 3:654723104cc9 | 39 | // RfChip3.PCD_Init(); |
kirchnet | 2:a0c7513fb634 | 40 | |
andcor02 | 3:654723104cc9 | 41 | while (true) { |
andcor02 | 3:654723104cc9 | 42 | LedGreen = 1; |
andcor02 | 3:654723104cc9 | 43 | |
andcor02 | 3:654723104cc9 | 44 | if ( RfChip.PICC_IsNewCardPresent()) { |
andcor02 | 3:654723104cc9 | 45 | if (RfChip.PICC_ReadCardSerial()) { |
andcor02 | 3:654723104cc9 | 46 | |
andcor02 | 3:654723104cc9 | 47 | LedGreen = 0; |
kirchnet | 2:a0c7513fb634 | 48 | |
andcor02 | 3:654723104cc9 | 49 | pc.printf("Card Reader 1: "); |
andcor02 | 3:654723104cc9 | 50 | for (uint8_t i = 0; i < RfChip.uid.size; i++) { |
andcor02 | 3:654723104cc9 | 51 | pc.printf(" %X02", RfChip.uid.uidByte[i]); |
andcor02 | 3:654723104cc9 | 52 | } |
andcor02 | 3:654723104cc9 | 53 | pc.printf("\n\r"); |
andcor02 | 3:654723104cc9 | 54 | } |
andcor02 | 3:654723104cc9 | 55 | } |
kirchnet | 2:a0c7513fb634 | 56 | |
andcor02 | 3:654723104cc9 | 57 | /* if ( RfChip2.PICC_IsNewCardPresent()) { |
andcor02 | 3:654723104cc9 | 58 | if (RfChip2.PICC_ReadCardSerial()) { |
andcor02 | 3:654723104cc9 | 59 | |
andcor02 | 3:654723104cc9 | 60 | LedGreen = 0; |
kirchnet | 2:a0c7513fb634 | 61 | |
andcor02 | 3:654723104cc9 | 62 | pc.printf("Card Reader 2: "); |
andcor02 | 3:654723104cc9 | 63 | for (uint8_t i = 0; i < RfChip2.uid.size; i++) { |
andcor02 | 3:654723104cc9 | 64 | pc.printf(" %X02", RfChip2.uid.uidByte[i]); |
andcor02 | 3:654723104cc9 | 65 | } |
andcor02 | 3:654723104cc9 | 66 | pc.printf("\n\r"); |
andcor02 | 3:654723104cc9 | 67 | } |
andcor02 | 3:654723104cc9 | 68 | } |
andcor02 | 3:654723104cc9 | 69 | |
andcor02 | 3:654723104cc9 | 70 | if ( RfChip3.PICC_IsNewCardPresent()) { |
andcor02 | 3:654723104cc9 | 71 | if (RfChip3.PICC_ReadCardSerial()) { |
andcor02 | 3:654723104cc9 | 72 | |
andcor02 | 3:654723104cc9 | 73 | LedGreen = 0; |
andcor02 | 3:654723104cc9 | 74 | |
andcor02 | 3:654723104cc9 | 75 | pc.printf("Card Reader 3: "); |
andcor02 | 3:654723104cc9 | 76 | for (uint8_t i = 0; i < RfChip3.uid.size; i++) { |
andcor02 | 3:654723104cc9 | 77 | pc.printf(" %X02", RfChip3.uid.uidByte[i]); |
andcor02 | 3:654723104cc9 | 78 | } |
andcor02 | 3:654723104cc9 | 79 | pc.printf("\n\r"); |
andcor02 | 3:654723104cc9 | 80 | } |
andcor02 | 3:654723104cc9 | 81 | }*/ |
andcor02 | 3:654723104cc9 | 82 | |
kirchnet | 2:a0c7513fb634 | 83 | } |
andcor02 | 3:654723104cc9 | 84 | } |