Public Documentation
  • Introduction
  • Getting started
    • Introduction
    • 1. Welcome Page
    • 2. Introduction (Beginner's Guide)
  • Portal Tools
    • Blocko
      • Ůvod do blocka
      • Flip-flop
      • REST-API bloček
    • Grid
      • Úvod do GRID
      • Základní Tlačítko (základy GRID)
      • vylepšený Přepínač (stylování a pokročilé možnosti GRID)
      • text generátor button (messeage type, two elements one widget)
      • graf (pokročilé funkce GRID)
      • Slider (User class v GRIDu)
      • Styly a jejich použití
  • Cloud
    • Cloud
    • Instancies
    • Rest-Api
  • General
    • What we plan
  • Hardware a programování
    • Úvod
      • Nahrání prvního programu
    • Konektivita
      • Specifikace zdroje internetu
      • GSM
      • 6LowPAN
      • Komunikace s portálem
      • Přepínání mezi servery
    • Hardware
      • Základní jednotky
        • IODAG3E
          • Rozhraní a periférie
          • Konektor X a Y
          • Napájení
          • Připojení zdroje k VBAT
          • Paměti
          • Technické specifikace
          • Schémata
        • IODAG3L
      • Rozšiřující moduly
        • GSM shield
        • LED shield
        • Relay shield
        • RFID shield
        • Ultrasonic shield
        • Meteo shield
        • Movement shield
        • PIR shield
        • RGB Displej shield
        • Serial shield
      • Ostatní
        • DevKitG3
          • Schéma
        • TK3G
          • Schéma
        • ZPPG3
          • Schéma
        • WEXP
    • Programování HW
      • Architektura FW
        • Aktualizace FW
        • Autobackup
      • Struktura programu
      • Byzance API
        • Vstupy a výstupy do Portálu
        • Callback Busy
        • Odložený restart
        • Callbacky připojení
        • Uživatelská makra
      • MBED API
        • Vstupy a výstupy
        • Komunikační rozhraní
        • Časování
        • RTOS
      • Knihovny
        • DHT
        • DS1820
        • Dali
        • EdgeStruct
        • I2CWrapper
        • Knock
        • MFRC522
        • MFRC522::MIFARE_Key
        • MPU9150
        • ms5637
        • OneWire
        • PCA9536
        • RGB_matrix
        • RollerDrive
        • SHT21
        • ST7565
        • Servo
        • TCA6424A
        • TLC59116
        • TripleSevenSeg
        • MFRC522::Uid
        • WS2812
        • WakeUp
      • Offline programování
        • Vlastní IDE
        • Upload kódu z GUI
        • Upload kódu z konzole
        • Upload kódu Drag&drop
    • Tutoriály
      • Datum a čas (RTC)
      • Komunikace po sériové lince (UART) s PC
        • Konfigurace sériové linky v PC
        • Programování sériové linky
      • Základní tutoriály
        • Digital Read
        • Analog Read/Write
        • PWM Fade
        • Timer/Ticker
        • State Change Detection
        • Ovládání LED modulu
        • BusOut
        • HC-SR04 Senzor
      • Pokročilé
    • Správa a diagnostika
      • Zdroj restartu
      • LED modul
      • Identifikace zařízení
      • Monitoring parametrů
      • Vytížení zařízení
      • Webové rozhraní
        • Základní přehled
        • Správce firmware
        • Vlákna
        • Definované vstupy
        • Konfigurace MQTT
        • Nastavení
      • Bootloader
        • Režimy bootloaderu
        • Command mód
        • Další vlastnosti bootloaderu
      • Webová konzole
      • Konfigurace zařízení
        • Confighash
      • Omezení konfigurace
        • Konfigurace
        • Binárky
        • Omezení MQTT
        • Lowpan
    • Knowledge base
      • Náhodná čísla
      • Watchdog
      • Paměť RAM
Powered by GitBook
On this page
  • Classes
  • Public Types
  • Public Attributes
  • Public Static Attributes
  • Public Functions
  • Detailed Description
  • Public Types Documentation
  • enum PCD_Register
  • enum PCD_Command
  • enum PCD_RxGain
  • enum PICC_Command
  • enum MIFARE_Misc
  • enum PICC_Type
  • enum StatusCode
  • Public Attributes Documentation
  • variable uid
  • Public Static Attributes Documentation
  • variable FIFO_SIZE
  • Public Functions Documentation
  • function MFRC522
  • function MFRC522
  • function ~MFRC522
  • function PCD_Init
  • function PCD_Reset
  • function PCD_AntennaOn
  • function PCD_WriteRegister
  • function PCD_WriteRegister
  • function PCD_ReadRegister
  • function PCD_ReadRegister
  • function PCD_SetRegisterBits
  • function PCD_ClrRegisterBits
  • function PCD_CalculateCRC
  • function PCD_TransceiveData
  • function PCD_CommunicateWithPICC
  • function PICC_RequestA
  • function PICC_WakeupA
  • function PICC_REQA_or_WUPA
  • function PICC_Select
  • function PICC_HaltA
  • function PCD_Authenticate
  • function PCD_StopCrypto1
  • function MIFARE_Read
  • function MIFARE_Write
  • function MIFARE_UltralightWrite
  • function MIFARE_Decrement
  • function MIFARE_Increment
  • function MIFARE_Restore
  • function MIFARE_Transfer
  • function PCD_MIFARE_Transceive
  • function PICC_GetType
  • function PICC_GetTypeName
  • function GetStatusCodeName
  • function MIFARE_SetAccessBits
  • function PICC_IsNewCardPresent
  • function PICC_ReadCardSerial
  1. Hardware a programování
  2. Programování HW
  3. Knihovny

MFRC522

Classes

Type

Name

struct

struct

Public Types

Type

Name

enum

enum

enum

enum

enum

enum

enum

Public Attributes

Type

Name

Public Static Attributes

Type

Name

static const uint8_t

Public Functions

Type

Name

int

int

int

int

int

uint8_t

void

void

void

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

void

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

uint8_t

char *

char *

void

bool

bool

Detailed Description

#include "mbed.h"
#include "MFRC522.h"

//KL25Z Pins for MFRC522 SPI interface
#define SPI_MOSI    PTC6
#define SPI_MISO    PTC7
#define SPI_SCLK    PTC5
#define SPI_CS      PTC4
// KL25Z Pin for MFRC522 reset
#define MF_RESET    PTC3
// KL25Z Pins for Debug UART port
#define UART_RX     PTA1
#define UART_TX     PTA2

DigitalOut LedRed   (LED_RED);
DigitalOut LedGreen (LED_GREEN);

Serial     DebugUART(UART_TX, UART_RX);
MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);

int main(void) {
  // Set debug UART speed
  DebugUART.baud(115200);

  // Init. RC522 Chip
  RfChip.PCD_Init();

  while (true) {
    LedRed   = 1;
    LedGreen = 1;

    // Look for new cards
    if ( ! RfChip.PICC_IsNewCardPresent())
    {
      wait_ms(500);
      continue;
    }

    LedRed   = 0;

    // Select one of the cards
    if ( ! RfChip.PICC_ReadCardSerial())
    {
      wait_ms(500);
      continue;
    }

    LedRed   = 1;
    LedGreen = 0;

    // Print Card UID
    printf("Card UID: ");
    for (uint8_t i = 0; i < RfChip.uid.size; i++)
    {
      printf(" %X02", RfChip.uid.uidByte[i]);
    }
    printf("\n\r");

    // Print Card type
    uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
    printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
    wait_ms(1000);
  }
}

Public Types Documentation

enum MFRC522::PCD_Register {
    CommandReg = 0x01,
    ComIEnReg = 0x02,
    DivIEnReg = 0x03,
    ComIrqReg = 0x04,
    DivIrqReg = 0x05,
    ErrorReg = 0x06,
    Status1Reg = 0x07,
    Status2Reg = 0x08,
    FIFODataReg = 0x09,
    FIFOLevelReg = 0x0A,
    WaterLevelReg = 0x0B,
    ControlReg = 0x0C,
    BitFramingReg = 0x0D,
    CollReg = 0x0E,
    ModeReg = 0x11,
    TxModeReg = 0x12,
    RxModeReg = 0x13,
    TxControlReg = 0x14,
    TxASKReg = 0x15,
    TxSelReg = 0x16,
    RxSelReg = 0x17,
    RxThresholdReg = 0x18,
    DemodReg = 0x19,
    MfTxReg = 0x1C,
    MfRxReg = 0x1D,
    SerialSpeedReg = 0x1F,
    CRCResultRegH = 0x21,
    CRCResultRegL = 0x22,
    ModWidthReg = 0x24,
    RFCfgReg = 0x26,
    GsNReg = 0x27,
    CWGsPReg = 0x28,
    ModGsPReg = 0x29,
    TModeReg = 0x2A,
    TPrescalerReg = 0x2B,
    TReloadRegH = 0x2C,
    TReloadRegL = 0x2D,
    TCntValueRegH = 0x2E,
    TCntValueRegL = 0x2F,
    TestSel1Reg = 0x31,
    TestSel2Reg = 0x32,
    TestPinEnReg = 0x33,
    TestPinValueReg = 0x34,
    TestBusReg = 0x35,
    AutoTestReg = 0x36,
    VersionReg = 0x37,
    AnalogTestReg = 0x38,
    TestDAC1Reg = 0x39,
    TestDAC2Reg = 0x3A,
    TestADCReg = 0x3B,
};
enum MFRC522::PCD_Command {
    PCD_Idle = 0x00,
    PCD_Mem = 0x01,
    PCD_GenerateRandomID = 0x02,
    PCD_CalcCRC = 0x03,
    PCD_Transmit = 0x04,
    PCD_NoCmdChange = 0x07,
    PCD_Receive = 0x08,
    PCD_Transceive = 0x0C,
    PCD_MFAuthent = 0x0E,
    PCD_SoftReset = 0x0F,
};
enum MFRC522::PCD_RxGain {
    RxGain_18dB = 0x00 << 4,
    RxGain_23dB = 0x01 << 4,
    RxGain_18dB_2 = 0x02 << 4,
    RxGain_23dB_2 = 0x03 << 4,
    RxGain_33dB = 0x04 << 4,
    RxGain_38dB = 0x05 << 4,
    RxGain_43dB = 0x06 << 4,
    RxGain_48dB = 0x07 << 4,
    RxGain_min = 0x00 << 4,
    RxGain_avg = 0x04 << 4,
    RxGain_max = 0x07 << 4,
};
enum MFRC522::PICC_Command {
    PICC_CMD_REQA = 0x26,
    PICC_CMD_WUPA = 0x52,
    PICC_CMD_CT = 0x88,
    PICC_CMD_SEL_CL1 = 0x93,
    PICC_CMD_SEL_CL2 = 0x95,
    PICC_CMD_SEL_CL3 = 0x97,
    PICC_CMD_HLTA = 0x50,
    PICC_CMD_MF_AUTH_KEY_A = 0x60,
    PICC_CMD_MF_AUTH_KEY_B = 0x61,
    PICC_CMD_MF_READ = 0x30,
    PICC_CMD_MF_WRITE = 0xA0,
    PICC_CMD_MF_DECREMENT = 0xC0,
    PICC_CMD_MF_INCREMENT = 0xC1,
    PICC_CMD_MF_RESTORE = 0xC2,
    PICC_CMD_MF_TRANSFER = 0xB0,
    PICC_CMD_UL_WRITE = 0xA2,
};
enum MFRC522::MIFARE_Misc {
    MF_ACK = 0xA,
    MF_KEY_SIZE = 6,
};
enum MFRC522::PICC_Type {
    PICC_TYPE_UNKNOWN = 0,
    PICC_TYPE_ISO_14443_4 = 1,
    PICC_TYPE_ISO_18092 = 2,
    PICC_TYPE_MIFARE_MINI = 3,
    PICC_TYPE_MIFARE_1K = 4,
    PICC_TYPE_MIFARE_4K = 5,
    PICC_TYPE_MIFARE_UL = 6,
    PICC_TYPE_MIFARE_PLUS = 7,
    PICC_TYPE_TNP3XXX = 8,
    PICC_TYPE_NOT_COMPLETE = 255,
};
enum MFRC522::StatusCode {
    STATUS_OK = 1,
    STATUS_ERROR = 2,
    STATUS_COLLISION = 3,
    STATUS_TIMEOUT = 4,
    STATUS_NO_ROOM = 5,
    STATUS_INTERNAL_ERROR = 6,
    STATUS_INVALID = 7,
    STATUS_CRC_WRONG = 8,
    STATUS_MIFARE_NACK = 9,
};

Public Attributes Documentation

Uid MFRC522::uid;

Public Static Attributes Documentation

const uint8_t MFRC522::FIFO_SIZE;

Public Functions Documentation

MFRC522::MFRC522 (
    PinName sda,
    PinName scl,
    uint32_t frequency = 400000
)

Parameters:

  • sda I2C sda pin

  • scl I2C scl pin

Constructor. Prepares the output pins.

MFRC522::MFRC522 (
    PinName sda,
    PinName scl,
    PinName reset
)

Parameters:

  • sda I2C sda pin

  • scl I2C scl pin

  • reset Reset pin

Constructor. Prepares the output pins.

MFRC522::~MFRC522 ()
int MFRC522::PCD_Init (
    void 
)
int MFRC522::PCD_Reset (
    void 
)
int MFRC522::PCD_AntennaOn (
    void 
)

Turns the antenna on by enabling pins TX1 and TX2. After a reset these pins disabled.

int MFRC522::PCD_WriteRegister (
    uint8_t reg,
    uint8_t value
)

Parameters:

  • reg The register to write to. One of the PCD_Register enums.

  • value The value to write.

int MFRC522::PCD_WriteRegister (
    uint8_t reg,
    uint8_t count,
    uint8_t * values
)

Parameters:

  • reg The register to write to. One of the PCD_Register enums.

  • count The number of bytes to write to the register

  • values The values to write. Byte array.

uint8_t MFRC522::PCD_ReadRegister (
    uint8_t reg
)

Parameters:

  • reg The register to read from. One of the PCD_Register enums.

Returns:

Register value

void MFRC522::PCD_ReadRegister (
    uint8_t reg,
    uint8_t count,
    uint8_t * values,
    uint8_t rxAlign = 0
)

Parameters:

  • reg The register to read from. One of the PCD_Register enums.

  • count The number of bytes to read.

  • values Byte array to store the values in.

  • rxAlign Only bit positions rxAlign..7 in values[0] are updated.

void MFRC522::PCD_SetRegisterBits (
    uint8_t reg,
    uint8_t mask
)

Sets the bits given in mask in register reg.

Parameters:

  • reg The register to update. One of the PCD_Register enums.

  • mask The bits to set.

Sets the bits given in mask in register reg.

void MFRC522::PCD_ClrRegisterBits (
    uint8_t reg,
    uint8_t mask
)

Clears the bits given in mask from register reg.

Parameters:

  • reg The register to update. One of the PCD_Register enums.

  • mask The bits to clear.

Clears the bits given in mask from register reg.

uint8_t MFRC522::PCD_CalculateCRC (
    uint8_t * data,
    uint8_t length,
    uint8_t * result
)

Parameters:

  • data Pointer to the data to transfer to the FIFO for CRC calculation.

  • length The number of bytes to transfer.

  • result Pointer to result buffer. Result is written to result[0..1], low byte first.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PCD_TransceiveData (
    uint8_t * sendData,
    uint8_t sendLen,
    uint8_t * backData,
    uint8_t * backLen,
    uint8_t * validBits = NULL,
    uint8_t rxAlign = 0,
    bool checkCRC = false
)

Executes the Transceive command. CRC validation can only be done if backData and backLen are specified.

Parameters:

  • sendData Pointer to the data to transfer to the FIFO.

  • sendLen Number of bytes to transfer to the FIFO.

  • backData NULL or pointer to buffer if data should be read back after executing the command.

  • backLen Max number of bytes to write to *backData. Out: The number of bytes returned.

  • validBits The number of valid bits in the last byte. 0 for 8 valid bits. Default NULL.

  • rxAlign Defines the bit position in backData[0] for the first bit received. Default 0.

  • checkCRC True => The last two bytes of the response is assumed to be a CRC_A that must be validated.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

Executes the Transceive command. CRC validation can only be done if backData and backLen are specified.

uint8_t MFRC522::PCD_CommunicateWithPICC (
    uint8_t command,
    uint8_t waitIRq,
    uint8_t * sendData,
    uint8_t sendLen,
    uint8_t * backData = NULL,
    uint8_t * backLen = NULL,
    uint8_t * validBits = NULL,
    uint8_t rxAlign = 0,
    bool checkCRC = false
)

Parameters:

  • command The command to execute. One of the PCD_Command enums.

  • waitIRq The bits in the ComIrqReg register that signals successful completion of the command.

  • sendData Pointer to the data to transfer to the FIFO.

  • sendLen Number of bytes to transfer to the FIFO.

  • backData NULL or pointer to buffer if data should be read back after executing the command.

  • backLen In: Max number of bytes to write to *backData. Out: The number of bytes returned.

  • validBits In/Out: The number of valid bits in the last byte. 0 for 8 valid bits.

  • rxAlign In: Defines the bit position in backData[0] for the first bit received. Default 0.

  • checkCRC In: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PICC_RequestA (
    uint8_t * bufferATQA,
    uint8_t * bufferSize
)

Transmits a REQuest command, Type A. Invites PICCs in state IDLE to go to READY and prepare for anticollision or selection. 7 bit frame. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.

Parameters:

  • bufferATQA The buffer to store the ATQA (Answer to request) in

  • bufferSize Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PICC_WakeupA (
    uint8_t * bufferATQA,
    uint8_t * bufferSize
)

Transmits a Wake-UP command, Type A. Invites PICCs in state IDLE and HALT to go to READY(*) and prepare for anticollision or selection. 7 bit frame. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.

Parameters:

  • bufferATQA The buffer to store the ATQA (Answer to request) in

  • bufferSize Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

Transmits a Wake-UP command, Type A. Invites PICCs in state IDLE and HALT to go to READY(*) and prepare for anticollision or selection. 7 bit frame. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.

uint8_t MFRC522::PICC_REQA_or_WUPA (
    uint8_t command,
    uint8_t * bufferATQA,
    uint8_t * bufferSize
)

Transmits REQA or WUPA commands. Beware: When two PICCs are in the field at the same time I often get STATUS_TIMEOUT - probably due do bad antenna design.

Parameters:

  • command The command to send - PICC_CMD_REQA or PICC_CMD_WUPA

  • bufferATQA The buffer to store the ATQA (Answer to request) in

  • bufferSize Buffer size, at least two bytes. Also number of bytes returned if STATUS_OK.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PICC_Select (
    Uid * uid,
    uint8_t validBits = 0
)
  • The chosen PICC is in state ACTIVE(*) and all other PICCs have returned to state IDLE/HALT. (Figure 7 of the ISO/IEC 14443-3 draft.)

  • The UID size and value of the chosen PICC is returned in *uid along with the SAK.

A PICC UID consists of 4, 7 or 10 bytes. Only 4 bytes can be specified in a SELECT command, so for the longer UIDs two or three iterations are used: UID size Number of UID bytes Cascade levels Example of PICC ======== =================== ============== =============== single 4 1 MIFARE Classic double 7 2 MIFARE Ultralight triple 10 3 Not currently in use?

Parameters:

  • validBits The number of known UID bits supplied in *uid. Normally 0. If set you must also supply uid->size.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PICC_HaltA (
    void 
)

Instructs a PICC in state ACTIVE(*) to go to state HALT.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PCD_Authenticate (
    uint8_t command,
    uint8_t blockAddr,
    MIFARE_Key * key,
    Uid * uid
)

Parameters:

  • command PICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B

  • blockAddr The block number. See numbering in the comments in the .h file.

  • key Pointer to the Crypteo1 key to use (6 bytes)

Returns:

STATUS_OK on success, STATUS_??? otherwise. Probably STATUS_TIMEOUT if you supply the wrong key.

void MFRC522::PCD_StopCrypto1 (
    void 
)

Used to exit the PCD from its authenticated state. Remember to call this function after communicating with an authenticated PICC - otherwise no new communications can start.

uint8_t MFRC522::MIFARE_Read (
    uint8_t blockAddr,
    uint8_t * buffer,
    uint8_t * bufferSize
)

Reads 16 bytes (+ 2 bytes CRC_A) from the active PICC. For MIFARE Classic the sector containing the block must be authenticated before calling this function. For MIFARE Ultralight only addresses 00h to 0Fh are decoded. The MF0ICU1 returns a NAK for higher addresses. The MF0ICU1 responds to the READ command by sending 16 bytes starting from the page address defined by the command argument. For example; if blockAddr is 03h then pages 03h, 04h, 05h, 06h are returned. A roll-back is implemented: If blockAddr is 0Eh, then the contents of pages 0Eh, 0Fh, 00h and 01h are returned. The buffer must be at least 18 bytes because a CRC_A is also returned. Checks the CRC_A before returning STATUS_OK.

Parameters:

  • blockAddr MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.

  • buffer The buffer to store the data in

  • bufferSize Buffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::MIFARE_Write (
    uint8_t blockAddr,
    uint8_t * buffer,
    uint8_t bufferSize
)

Writes 16 bytes to the active PICC. For MIFARE Classic the sector containing the block must be authenticated before calling this function. For MIFARE Ultralight the opretaion is called "COMPATIBILITY WRITE". Even though 16 bytes are transferred to the Ultralight PICC, only the least significant 4 bytes (bytes 0 to 3) are written to the specified address. It is recommended to set the remaining bytes 04h to 0Fh to all logic 0.

Parameters:

  • blockAddr MIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to.

  • buffer The 16 bytes to write to the PICC

  • bufferSize Buffer size, must be at least 16 bytes. Exactly 16 bytes are written.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::MIFARE_UltralightWrite (
    uint8_t page,
    uint8_t * buffer,
    uint8_t bufferSize
)

Writes a 4 byte page to the active MIFARE Ultralight PICC.

Parameters:

  • page The page (2-15) to write to.

  • buffer The 4 bytes to write to the PICC

  • bufferSize Buffer size, must be at least 4 bytes. Exactly 4 bytes are written.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::MIFARE_Decrement (
    uint8_t blockAddr,
    uint32_t delta
)

Parameters:

  • blockAddr The block (0-0xff) number.

  • delta This number is subtracted from the value of block blockAddr.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::MIFARE_Increment (
    uint8_t blockAddr,
    uint32_t delta
)

Parameters:

  • blockAddr The block (0-0xff) number.

  • delta This number is added to the value of block blockAddr.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::MIFARE_Restore (
    uint8_t blockAddr
)

Parameters:

  • blockAddr The block (0-0xff) number.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

MIFARE Restore copies the value of the addressed block into a volatile memory.

uint8_t MFRC522::MIFARE_Transfer (
    uint8_t blockAddr
)

MIFARE Transfer writes the value stored in the volatile memory into one MIFARE Classic block. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001].

Parameters:

  • blockAddr The block (0-0xff) number.

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PCD_MIFARE_Transceive (
    uint8_t * sendData,
    uint8_t sendLen,
    bool acceptTimeout = false
)

Wrapper for MIFARE protocol communication. Adds CRC_A, executes the Transceive command and checks that the response is MF_ACK or a timeout.

Parameters:

  • sendData Pointer to the data to transfer to the FIFO. Do NOT include the CRC_A.

  • sendLen Number of bytes in sendData.

  • acceptTimeout True => A timeout is also success

Returns:

STATUS_OK on success, STATUS_??? otherwise.

uint8_t MFRC522::PICC_GetType (
    uint8_t sak
)

Translates the SAK (Select Acknowledge) to a PICC type.

Parameters:

Returns:

PICC_Type

char * MFRC522::PICC_GetTypeName (
    uint8_t type
)

Returns a string pointer to the PICC type name.

Parameters:

  • type One of the PICC_Type enums.

Returns:

A string pointer to the PICC type name.

char * MFRC522::GetStatusCodeName (
    uint8_t code
)

Returns a string pointer to a status code name.

Parameters:

  • code One of the StatusCode enums.

Returns:

A string pointer to a status code name.

void MFRC522::MIFARE_SetAccessBits (
    uint8_t * accessBitBuffer,
    uint8_t g0,
    uint8_t g1,
    uint8_t g2,
    uint8_t g3
)

Calculates the bit pattern needed for the specified access bits. In the [C1 C2 C3] tupples C1 is MSB (=4) and C3 is LSB (=1).

Parameters:

  • accessBitBuffer Pointer to byte 6, 7 and 8 in the sector trailer. Bytes [0..2] will be set.

  • g0 Access bits [C1 C2 C3] for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39)

  • g1 Access bits [C1 C2 C3] for block 1 (for sectors 0-31) or blocks 5-9 (for sectors 32-39)

  • g2 Access bits [C1 C2 C3] for block 2 (for sectors 0-31) or blocks 10-14 (for sectors 32-39)

  • g3 Access bits [C1 C2 C3] for the sector trailer, block 3 (for sectors 0-31) or block 15 (for sectors 32-39)

bool MFRC522::PICC_IsNewCardPresent (
    void 
)

Returns true if a PICC responds to PICC_CMD_REQA. Only "new" cards in state IDLE are invited. Sleeping cards in state HALT are ignored.

Returns:

bool

bool MFRC522::PICC_ReadCardSerial (
    void 
)

Returns:

bool

The documentation for this class was generated from the following file: D:/w/hw-libs/\_libs\_/libraries/MFRC522.h

PreviousKnockNextMFRC522::MIFARE_Key

Last updated 6 years ago

{ CommandReg = 0x01, ComIEnReg = 0x02, DivIEnReg = 0x03, ComIrqReg = 0x04, DivIrqReg = 0x05, ErrorReg = 0x06, Status1Reg = 0x07, Status2Reg = 0x08, FIFODataReg = 0x09, FIFOLevelReg = 0x0A, WaterLevelReg = 0x0B, ControlReg = 0x0C, BitFramingReg = 0x0D, CollReg = 0x0E, ModeReg = 0x11, TxModeReg = 0x12, RxModeReg = 0x13, TxControlReg = 0x14, TxASKReg = 0x15, TxSelReg = 0x16, RxSelReg = 0x17, RxThresholdReg = 0x18, DemodReg = 0x19, MfTxReg = 0x1C, MfRxReg = 0x1D, SerialSpeedReg = 0x1F, CRCResultRegH = 0x21, CRCResultRegL = 0x22, ModWidthReg = 0x24, RFCfgReg = 0x26, GsNReg = 0x27, CWGsPReg = 0x28, ModGsPReg = 0x29, TModeReg = 0x2A, TPrescalerReg = 0x2B, TReloadRegH = 0x2C, TReloadRegL = 0x2D, TCntValueRegH = 0x2E, TCntValueRegL = 0x2F, TestSel1Reg = 0x31, TestSel2Reg = 0x32, TestPinEnReg = 0x33, TestPinValueReg = 0x34, TestBusReg = 0x35, AutoTestReg = 0x36, VersionReg = 0x37, AnalogTestReg = 0x38, TestDAC1Reg = 0x39, TestDAC2Reg = 0x3A, TestADCReg = 0x3B }

{ PCD_Idle = 0x00, PCD_Mem = 0x01, PCD_GenerateRandomID = 0x02, PCD_CalcCRC = 0x03, PCD_Transmit = 0x04, PCD_NoCmdChange = 0x07, PCD_Receive = 0x08, PCD_Transceive = 0x0C, PCD_MFAuthent = 0x0E, PCD_SoftReset = 0x0F }

{ RxGain_18dB = 0x00 << 4, RxGain_23dB = 0x01 << 4, RxGain_18dB_2 = 0x02 << 4, RxGain_23dB_2 = 0x03 << 4, RxGain_33dB = 0x04 << 4, RxGain_38dB = 0x05 << 4, RxGain_43dB = 0x06 << 4, RxGain_48dB = 0x07 << 4, RxGain_min = 0x00 << 4, RxGain_avg = 0x04 << 4, RxGain_max = 0x07 << 4 }

{ PICC_CMD_REQA = 0x26, PICC_CMD_WUPA = 0x52, PICC_CMD_CT = 0x88, PICC_CMD_SEL_CL1 = 0x93, PICC_CMD_SEL_CL2 = 0x95, PICC_CMD_SEL_CL3 = 0x97, PICC_CMD_HLTA = 0x50, PICC_CMD_MF_AUTH_KEY_A = 0x60, PICC_CMD_MF_AUTH_KEY_B = 0x61, PICC_CMD_MF_READ = 0x30, PICC_CMD_MF_WRITE = 0xA0, PICC_CMD_MF_DECREMENT = 0xC0, PICC_CMD_MF_INCREMENT = 0xC1, PICC_CMD_MF_RESTORE = 0xC2, PICC_CMD_MF_TRANSFER = 0xB0, PICC_CMD_UL_WRITE = 0xA2 }

{ MF_ACK = 0xA, MF_KEY_SIZE = 6 }

{ PICC_TYPE_UNKNOWN = 0, PICC_TYPE_ISO_14443_4 = 1, PICC_TYPE_ISO_18092 = 2, PICC_TYPE_MIFARE_MINI = 3, PICC_TYPE_MIFARE_1K = 4, PICC_TYPE_MIFARE_4K = 5, PICC_TYPE_MIFARE_UL = 6, PICC_TYPE_MIFARE_PLUS = 7, PICC_TYPE_TNP3XXX = 8, PICC_TYPE_NOT_COMPLETE = 255 }

{ STATUS_OK = 1, STATUS_ERROR = 2, STATUS_COLLISION = 3, STATUS_TIMEOUT = 4, STATUS_NO_ROOM = 5, STATUS_INTERNAL_ERROR = 6, STATUS_INVALID = 7, STATUS_CRC_WRONG = 8, STATUS_MIFARE_NACK = 9 }

(PinName sda, PinName scl, uint32_t frequency = 400000)

(PinName sda, PinName scl, PinName reset)

()

(void)

(void)

(void)

(uint8_t reg, uint8_t value)

(uint8_t reg, uint8_t count, uint8_t * values)

(uint8_t reg)

(uint8_t reg, uint8_t count, uint8_t * values, uint8_t rxAlign = 0)

(uint8_t reg, uint8_t mask)

(uint8_t reg, uint8_t mask)

(uint8_t * data, uint8_t length, uint8_t * result)

(uint8_t * sendData, uint8_t sendLen, uint8_t * backData, uint8_t * backLen, uint8_t * validBits = NULL, uint8_t rxAlign = 0, bool checkCRC = false)

(uint8_t command, uint8_t waitIRq, uint8_t * sendData, uint8_t sendLen, uint8_t * backData = NULL, uint8_t * backLen = NULL, uint8_t * validBits = NULL, uint8_t rxAlign = 0, bool checkCRC = false)

(uint8_t * bufferATQA, uint8_t * bufferSize)

(uint8_t * bufferATQA, uint8_t * bufferSize)

(uint8_t command, uint8_t * bufferATQA, uint8_t * bufferSize)

( * uid, uint8_t validBits = 0)

(void)

(uint8_t command, uint8_t blockAddr, * key, * uid)

(void)

(uint8_t blockAddr, uint8_t * buffer, uint8_t * bufferSize)

(uint8_t blockAddr, uint8_t * buffer, uint8_t bufferSize)

(uint8_t page, uint8_t * buffer, uint8_t bufferSize)

(uint8_t blockAddr, uint32_t delta)

(uint8_t blockAddr, uint32_t delta)

(uint8_t blockAddr)

(uint8_t blockAddr)

(uint8_t * sendData, uint8_t sendLen, bool acceptTimeout = false)

(uint8_t sak)

(uint8_t type)

(uint8_t code)

(uint8_t * accessBitBuffer, uint8_t g0, uint8_t g1, uint8_t g2, uint8_t g3)

(void)

(void)

example

enum

registers (described in chapter 9 of the datasheet). When using SPI all addresses areed one bit left in the "SPI address byte" (section 8.1.2.3)

enum

enum

enum

enum

enum

enum

variable

variable

function

constructor

function

constructor

function

destructor Destructor.

function

Initializes the chip.

function

Performs a soft reset on the chip and waits for it to be ready again.

function

function

Writes a byte to the specified register in the chip. The interface is described in the datasheet section 8.1.2.

Writes a byte to the specified register in the chip. The interface is described in the datasheet section 8.1.2.

function

Writes a number of bytes to the specified register in the chip. The interface is described in the datasheet section 8.1.2.

Writes a number of bytes to the specified register in the chip. The interface is described in the datasheet section 8.1.2.

function

Reads a byte from the specified register in the chip. The interface is described in the datasheet section 8.1.2.

Reads a byte from the specified register in the chip. The interface is described in the datasheet section 8.1.2.

function

Reads a number of bytes from the specified register in the chip. The interface is described in the datasheet section 8.1.2.

Reads a number of bytes from the specified register in the chip. The interface is described in the datasheet section 8.1.2.

function

function

function

Use the CRC coprocessor in the to calculate a CRC_A.

Use the CRC coprocessor in the to calculate a CRC_A.

function

function

Transfers data to the FIFO, executes a commend, waits for completion and transfers data back from the FIFO. CRC validation can only be done if backData and backLen are specified.

Transfers data to the FIFO, executes a commend, waits for completion and transfers data back from the FIFO. CRC validation can only be done if backData and backLen are specified.

function

function

function

function

Transmits SELECT/ANTICOLLISION commands to select a single PICC. Before calling this function the PICCs must be placed in the READY(*) state by calling or . On success:

uid Pointer to struct. Normally output, but can also be used to supply a known UID.

function

function

Executes the MFAuthent command. This command manages MIFARE authentication to enable a secure communication to any MIFARE Mini, MIFARE 1K and MIFARE 4K card. The authentication is described in the datasheet section 10.3.1.9 and section 10.1. For use with MIFARE Classic PICCs. The PICC must be selected - ie in state ACTIVE(*) - before calling this function. Remember to call after communicating with the authenticated PICC - otherwise no new communications can start. All keys are set to FFFFFFFFFFFFh at chip delivery.

uid Pointer to struct. The first 4 bytes of the UID is used.

function

function

function

function

function

MIFARE Decrement subtracts the delta from the value of the addressed block, and stores the result in a volatile memory. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001]. Use to store the result in a block.

function

MIFARE Increment adds the delta to the value of the addressed block, and stores the result in a volatile memory. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001]. Use to store the result in a block.

function

MIFARE Restore copies the value of the addressed block into a volatile memory. For MIFARE Classic only. The sector containing the block must be authenticated before calling this function. Only for blocks in "value block" mode, ie with access bits [C1 C2 C3] = [110] or [001]. Use to store the result in a block.

function

function

function

sak The SAK byte returned from .

function

function

function

function

function

Simple wrapper around PICC_Select. Returns true if a UID could be read. Remember to call , or first. The read UID is available in the class variable uid.

MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
MFRC522
Uid
Uid
PCD_Register
PCD_Command
PCD_RxGain
PICC_Command
MIFARE_Misc
PICC_Type
StatusCode
uid
FIFO_SIZE
MFRC522
MFRC522
~MFRC522
PCD_Init
PCD_Reset
PCD_AntennaOn
PCD_WriteRegister
PCD_WriteRegister
PCD_ReadRegister
PCD_ReadRegister
PCD_SetRegisterBits
PCD_ClrRegisterBits
PCD_CalculateCRC
PCD_TransceiveData
PCD_CommunicateWithPICC
PICC_RequestA
PICC_WakeupA
PICC_REQA_or_WUPA
PICC_Select
PICC_RequestA()
PICC_WakeupA()
PICC_HaltA
PCD_Authenticate
MFRC522
MFRC522
http://www.nxp.com/documents/data_sheet/MF1S503x.pdf
PCD_StopCrypto1()
PCD_StopCrypto1
MIFARE_Read
MIFARE_Write
MIFARE_UltralightWrite
MIFARE_Decrement
MIFARE_Transfer()
MIFARE_Increment
MIFARE_Transfer()
MIFARE_Restore
MIFARE_Transfer()
MIFARE_Transfer
PCD_MIFARE_Transceive
PICC_GetType
PICC_Select()
PICC_GetTypeName
GetStatusCodeName
MIFARE_SetAccessBits
PICC_IsNewCardPresent
PICC_ReadCardSerial
PICC_IsNewCardPresent()
PICC_RequestA()
PICC_WakeupA()
MIFARE_Key
Uid
Uid
PCD_Register
PCD_Command
PCD_RxGain
PICC_Command
MIFARE_Misc
PICC_Type
StatusCode
uid
FIFO_SIZE
MFRC522
MFRC522
~MFRC522
PCD_Init
PCD_Reset
PCD_AntennaOn
PCD_WriteRegister
PCD_WriteRegister
PCD_ReadRegister
PCD_ReadRegister
PCD_SetRegisterBits
PCD_ClrRegisterBits
PCD_CalculateCRC
PCD_TransceiveData
PCD_CommunicateWithPICC
PICC_RequestA
PICC_WakeupA
PICC_REQA_or_WUPA
Uid
PICC_Select
PICC_HaltA
MIFARE_Key
Uid
PCD_Authenticate
PCD_StopCrypto1
MIFARE_Read
MIFARE_Write
MIFARE_UltralightWrite
MIFARE_Decrement
MIFARE_Increment
MIFARE_Restore
MIFARE_Transfer
PCD_MIFARE_Transceive
PICC_GetType
PICC_GetTypeName
GetStatusCodeName
MIFARE_SetAccessBits
PICC_IsNewCardPresent
PICC_ReadCardSerial