rc522 project

Dependencies:   RC522

Fork of RFID-RC522 by Andrea Corrado

Committer:
duchonic
Date:
Thu Sep 20 11:21:00 2018 +0000
Revision:
5:5ec7ea8ccd90
Parent:
4:320ce84c8f43
first

Who changed what in which revision?

UserRevisionLine numberNew 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
duchonic 5:5ec7ea8ccd90 15 //RFID RST=pin7 -> Nucleo =PA_9=D9
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
duchonic 5:5ec7ea8ccd90 21 #define VERSION 1
kirchnet 2:a0c7513fb634 22
kirchnet 2:a0c7513fb634 23 //Serial connection to PC for output
andcor02 3:654723104cc9 24 Serial pc(USBTX, USBRX);
duchonic 5:5ec7ea8ccd90 25 DigitalIn userButton(USER_BUTTON);
kirchnet 2:a0c7513fb634 26
kirchnet 2:a0c7513fb634 27
duchonic 5:5ec7ea8ccd90 28
duchonic 5:5ec7ea8ccd90 29
kirchnet 2:a0c7513fb634 30
andcor02 3:654723104cc9 31 int main(void)
andcor02 3:654723104cc9 32 {
duchonic 5:5ec7ea8ccd90 33 pc.baud(115200);
andcor02 3:654723104cc9 34 pc.printf("starting...\n");
duchonic 5:5ec7ea8ccd90 35
duchonic 5:5ec7ea8ccd90 36 while(1){
duchonic 5:5ec7ea8ccd90 37
duchonic 5:5ec7ea8ccd90 38 if(userButton == 0){
duchonic 5:5ec7ea8ccd90 39 printf(">>> start reading <<<\n");
duchonic 5:5ec7ea8ccd90 40
duchonic 5:5ec7ea8ccd90 41 MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCK, SPI_CS, D8);
duchonic 5:5ec7ea8ccd90 42
duchonic 5:5ec7ea8ccd90 43 /** a test for static asserts */
duchonic 5:5ec7ea8ccd90 44 MBED_STATIC_ASSERT(VERSION < 5, "Version to high");
duchonic 5:5ec7ea8ccd90 45
duchonic 5:5ec7ea8ccd90 46 RfChip.PCD_Init();
duchonic 5:5ec7ea8ccd90 47
duchonic 5:5ec7ea8ccd90 48 while (userButton == 0) {
duchonic 5:5ec7ea8ccd90 49
duchonic 5:5ec7ea8ccd90 50 if ( RfChip.PICC_IsNewCardPresent()) {
duchonic 5:5ec7ea8ccd90 51 if (RfChip.PICC_ReadCardSerial()) {
duchonic 5:5ec7ea8ccd90 52
duchonic 5:5ec7ea8ccd90 53 pc.printf("Card Reader 1: ");
duchonic 5:5ec7ea8ccd90 54 for (uint8_t i = 0; i < RfChip.uid.size; i++) {
duchonic 5:5ec7ea8ccd90 55 pc.printf(" %X02", RfChip.uid.uidByte[i]);
duchonic 5:5ec7ea8ccd90 56 }
duchonic 5:5ec7ea8ccd90 57 pc.printf("\n");
duchonic 5:5ec7ea8ccd90 58
duchonic 5:5ec7ea8ccd90 59 printf("PICC Type: %s \n",
duchonic 5:5ec7ea8ccd90 60 RfChip.PICC_GetTypeName(RfChip.PICC_GetType(RfChip.uid.sak)));
duchonic 5:5ec7ea8ccd90 61 }
andcor02 3:654723104cc9 62 }
andcor02 3:654723104cc9 63 }
duchonic 5:5ec7ea8ccd90 64
duchonic 5:5ec7ea8ccd90 65 printf(">>> end reading <<<\n");
andcor02 3:654723104cc9 66 }
duchonic 5:5ec7ea8ccd90 67
duchonic 5:5ec7ea8ccd90 68 //MBED_ASSERT(userButton == 1);
duchonic 5:5ec7ea8ccd90 69 }
duchonic 5:5ec7ea8ccd90 70
kirchnet 2:a0c7513fb634 71
andcor02 3:654723104cc9 72 }