My Project
Classes | Public Types | Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Protected Attributes | List of all members
MFRC522 Class Reference
Collaboration diagram for MFRC522:
Collaboration graph
[legend]

Classes

struct  MIFARE_Key
 
struct  Uid
 

Public Types

enum  PCD_Register : byte {
  CommandReg = 0x01 << 1, ComIEnReg = 0x02 << 1, DivIEnReg = 0x03 << 1, ComIrqReg = 0x04 << 1,
  DivIrqReg = 0x05 << 1, ErrorReg = 0x06 << 1, Status1Reg = 0x07 << 1, Status2Reg = 0x08 << 1,
  FIFODataReg = 0x09 << 1, FIFOLevelReg = 0x0A << 1, WaterLevelReg = 0x0B << 1, ControlReg = 0x0C << 1,
  BitFramingReg = 0x0D << 1, CollReg = 0x0E << 1, ModeReg = 0x11 << 1, TxModeReg = 0x12 << 1,
  RxModeReg = 0x13 << 1, TxControlReg = 0x14 << 1, TxASKReg = 0x15 << 1, TxSelReg = 0x16 << 1,
  RxSelReg = 0x17 << 1, RxThresholdReg = 0x18 << 1, DemodReg = 0x19 << 1, MfTxReg = 0x1C << 1,
  MfRxReg = 0x1D << 1, SerialSpeedReg = 0x1F << 1, CRCResultRegH = 0x21 << 1, CRCResultRegL = 0x22 << 1,
  ModWidthReg = 0x24 << 1, RFCfgReg = 0x26 << 1, GsNReg = 0x27 << 1, CWGsPReg = 0x28 << 1,
  ModGsPReg = 0x29 << 1, TModeReg = 0x2A << 1, TPrescalerReg = 0x2B << 1, TReloadRegH = 0x2C << 1,
  TReloadRegL = 0x2D << 1, TCounterValueRegH = 0x2E << 1, TCounterValueRegL = 0x2F << 1, TestSel1Reg = 0x31 << 1,
  TestSel2Reg = 0x32 << 1, TestPinEnReg = 0x33 << 1, TestPinValueReg = 0x34 << 1, TestBusReg = 0x35 << 1,
  AutoTestReg = 0x36 << 1, VersionReg = 0x37 << 1, AnalogTestReg = 0x38 << 1, TestDAC1Reg = 0x39 << 1,
  TestDAC2Reg = 0x3A << 1, TestADCReg = 0x3B << 1
}
 
enum  PCD_Command : byte {
  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  PCD_RxGain : byte {
  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  PICC_Command : byte {
  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_RATS = 0xE0,
  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  MIFARE_Misc { MF_ACK = 0xA, MF_KEY_SIZE = 6 }
 
enum  PICC_Type : byte {
  PICC_TYPE_UNKNOWN, PICC_TYPE_ISO_14443_4, PICC_TYPE_ISO_18092, PICC_TYPE_MIFARE_MINI,
  PICC_TYPE_MIFARE_1K, PICC_TYPE_MIFARE_4K, PICC_TYPE_MIFARE_UL, PICC_TYPE_MIFARE_PLUS,
  PICC_TYPE_MIFARE_DESFIRE, PICC_TYPE_TNP3XXX, PICC_TYPE_NOT_COMPLETE = 0xff
}
 
enum  StatusCode : byte {
  STATUS_OK, STATUS_ERROR, STATUS_COLLISION, STATUS_TIMEOUT,
  STATUS_NO_ROOM, STATUS_INTERNAL_ERROR, STATUS_INVALID, STATUS_CRC_WRONG,
  STATUS_MIFARE_NACK = 0xff
}
 

Public Member Functions

void PCD_WriteRegister (PCD_Register reg, byte value)
 
void PCD_WriteRegister (PCD_Register reg, byte count, byte *values)
 
byte PCD_ReadRegister (PCD_Register reg)
 
void PCD_ReadRegister (PCD_Register reg, byte count, byte *values, byte rxAlign=0)
 
void PCD_SetRegisterBitMask (PCD_Register reg, byte mask)
 
void PCD_ClearRegisterBitMask (PCD_Register reg, byte mask)
 
StatusCode PCD_CalculateCRC (byte *data, byte length, byte *result)
 
void PCD_Init ()
 
void PCD_Init (byte chipSelectPin, byte resetPowerDownPin)
 
void PCD_Reset ()
 
void PCD_AntennaOn ()
 
void PCD_AntennaOff ()
 
byte PCD_GetAntennaGain ()
 
void PCD_SetAntennaGain (byte mask)
 
bool PCD_PerformSelfTest ()
 
StatusCode PCD_TransceiveData (byte *sendData, byte sendLen, byte *backData, byte *backLen, byte *validBits=nullptr, byte rxAlign=0, bool checkCRC=false)
 
StatusCode PCD_CommunicateWithPICC (byte command, byte waitIRq, byte *sendData, byte sendLen, byte *backData=nullptr, byte *backLen=nullptr, byte *validBits=nullptr, byte rxAlign=0, bool checkCRC=false)
 
StatusCode PICC_RequestA (byte *bufferATQA, byte *bufferSize)
 
StatusCode PICC_WakeupA (byte *bufferATQA, byte *bufferSize)
 
StatusCode PICC_REQA_or_WUPA (byte command, byte *bufferATQA, byte *bufferSize)
 
virtual StatusCode PICC_Select (Uid *uid, byte validBits=0)
 
StatusCode PICC_HaltA ()
 
StatusCode PCD_Authenticate (byte command, byte blockAddr, MIFARE_Key *key, Uid *uid)
 
void PCD_StopCrypto1 ()
 
StatusCode MIFARE_Read (byte blockAddr, byte *buffer, byte *bufferSize)
 
StatusCode MIFARE_Write (byte blockAddr, byte *buffer, byte bufferSize)
 
StatusCode MIFARE_Ultralight_Write (byte page, byte *buffer, byte bufferSize)
 
StatusCode MIFARE_Decrement (byte blockAddr, int32_t delta)
 
StatusCode MIFARE_Increment (byte blockAddr, int32_t delta)
 
StatusCode MIFARE_Restore (byte blockAddr)
 
StatusCode MIFARE_Transfer (byte blockAddr)
 
StatusCode MIFARE_GetValue (byte blockAddr, int32_t *value)
 
StatusCode MIFARE_SetValue (byte blockAddr, int32_t value)
 
StatusCode PCD_NTAG216_AUTH (byte *passWord, byte pACK[])
 
StatusCode PCD_MIFARE_Transceive (byte *sendData, byte sendLen, bool acceptTimeout=false)
 
void PCD_DumpVersionToSerial ()
 
void PICC_DumpToSerial (Uid *uid)
 
void PICC_DumpDetailsToSerial (Uid *uid)
 
void PICC_DumpMifareClassicToSerial (Uid *uid, PICC_Type piccType, MIFARE_Key *key)
 
void PICC_DumpMifareClassicSectorToSerial (Uid *uid, MIFARE_Key *key, byte sector)
 
void PICC_DumpMifareUltralightToSerial ()
 
void MIFARE_SetAccessBits (byte *accessBitBuffer, byte g0, byte g1, byte g2, byte g3)
 
virtual bool PICC_IsNewCardPresent ()
 
virtual bool PICC_ReadCardSerial ()
 

Static Public Member Functions

static PICC_Type PICC_GetType (byte sak)
 

Public Attributes

Uid uid
 

Static Public Attributes

static constexpr byte FIFO_SIZE = 64
 
static constexpr uint8_t UNUSED_PIN = UINT8_MAX
 

Protected Member Functions

StatusCode MIFARE_TwoStepHelper (byte command, byte blockAddr, int32_t data)
 

Protected Attributes

byte _chipSelectPin
 
byte _resetPowerDownPin
 
SPI m_spi
 

Member Function Documentation

◆ MIFARE_Decrement()

MFRC522::StatusCode MFRC522::MIFARE_Decrement ( byte  blockAddr,
int32_t  delta 
)

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 MIFARE_Transfer() to store the result in a block.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
blockAddrThe block (0-0xff) number.
deltaThis number is subtracted from the value of block blockAddr.

◆ MIFARE_GetValue()

MFRC522::StatusCode MFRC522::MIFARE_GetValue ( byte  blockAddr,
int32_t *  value 
)

Helper routine to read the current value from a Value Block.

Only for MIFARE Classic and only for blocks in "value block" mode, that is: with access bits [C1 C2 C3] = [110] or [001]. The sector containing the block must be authenticated before calling this function.

Parameters
[in]blockAddrThe block (0x00-0xff) number.
[out]valueCurrent value of the Value Block.
Returns
STATUS_OK on success, STATUS_??? otherwise.

◆ MIFARE_Increment()

MFRC522::StatusCode MFRC522::MIFARE_Increment ( byte  blockAddr,
int32_t  delta 
)

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 MIFARE_Transfer() to store the result in a block.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
blockAddrThe block (0-0xff) number.
deltaThis number is added to the value of block blockAddr.

◆ MIFARE_Read()

MFRC522::StatusCode MFRC522::MIFARE_Read ( byte  blockAddr,
byte *  buffer,
byte *  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.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
blockAddrMIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The first page to return data from.
bufferThe buffer to store the data in
bufferSizeBuffer size, at least 18 bytes. Also number of bytes returned if STATUS_OK.

◆ MIFARE_Restore()

MFRC522::StatusCode MFRC522::MIFARE_Restore ( byte  blockAddr)

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 MIFARE_Transfer() to store the result in a block.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
blockAddrThe block (0-0xff) number.

◆ MIFARE_SetAccessBits()

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

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

Parameters
accessBitBufferPointer to byte 6, 7 and 8 in the sector trailer. Bytes [0..2] will be set.
g0Access bits [C1 C2 C3] for block 0 (for sectors 0-31) or blocks 0-4 (for sectors 32-39)
g1Access bits C1 C2 C3] for block 1 (for sectors 0-31) or blocks 5-9 (for sectors 32-39)
g2Access bits C1 C2 C3] for block 2 (for sectors 0-31) or blocks 10-14 (for sectors 32-39)
g3Access bits C1 C2 C3] for the sector trailer, block 3 (for sectors 0-31) or block 15 (for sectors 32-39)

◆ MIFARE_SetValue()

MFRC522::StatusCode MFRC522::MIFARE_SetValue ( byte  blockAddr,
int32_t  value 
)

Helper routine to write a specific value into a Value Block.

Only for MIFARE Classic and only for blocks in "value block" mode, that is: with access bits [C1 C2 C3] = [110] or [001]. The sector containing the block must be authenticated before calling this function.

Parameters
[in]blockAddrThe block (0x00-0xff) number.
[in]valueNew value of the Value Block.
Returns
STATUS_OK on success, STATUS_??? otherwise.

◆ MIFARE_Transfer()

MFRC522::StatusCode MFRC522::MIFARE_Transfer ( byte  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].

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
blockAddrThe block (0-0xff) number.

◆ MIFARE_TwoStepHelper()

MFRC522::StatusCode MFRC522::MIFARE_TwoStepHelper ( byte  command,
byte  blockAddr,
int32_t  data 
)
protected

Helper function for the two-step MIFARE Classic protocol operations Decrement, Increment and Restore.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
commandThe command to use
blockAddrThe block (0-0xff) number.
dataThe data to transfer in step 2

◆ MIFARE_Ultralight_Write()

MFRC522::StatusCode MFRC522::MIFARE_Ultralight_Write ( byte  page,
byte *  buffer,
byte  bufferSize 
)

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

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
pageThe page (2-15) to write to.
bufferThe 4 bytes to write to the PICC
bufferSizeBuffer size, must be at least 4 bytes. Exactly 4 bytes are written.

◆ MIFARE_Write()

MFRC522::StatusCode MFRC522::MIFARE_Write ( byte  blockAddr,
byte *  buffer,
byte  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 operation 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.

  • Returns
    STATUS_OK on success, STATUS_??? otherwise.
Parameters
blockAddrMIFARE Classic: The block (0-0xff) number. MIFARE Ultralight: The page (2-15) to write to.
bufferThe 16 bytes to write to the PICC
bufferSizeBuffer size, must be at least 16 bytes. Exactly 16 bytes are written.

◆ PCD_AntennaOff()

void MFRC522::PCD_AntennaOff ( )

Turns the antenna off by disabling pins TX1 and TX2.

◆ PCD_AntennaOn()

void MFRC522::PCD_AntennaOn ( )

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

◆ PCD_Authenticate()

MFRC522::StatusCode MFRC522::PCD_Authenticate ( byte  command,
byte  blockAddr,
MIFARE_Key key,
Uid uid 
)

Executes the MFRC522 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 MFRC522 datasheet section 10.3.1.9 and http://www.nxp.com/documents/data_sheet/MF1S503x.pdf 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 PCD_StopCrypto1() after communicating with the authenticated PICC - otherwise no new communications can start.

All keys are set to FFFFFFFFFFFFh at chip delivery.

Returns
STATUS_OK on success, STATUS_??? otherwise. Probably STATUS_TIMEOUT if you supply the wrong key.
Parameters
commandPICC_CMD_MF_AUTH_KEY_A or PICC_CMD_MF_AUTH_KEY_B
blockAddrThe block number. See numbering in the comments in the .h file.
keyPointer to the Crypteo1 key to use (6 bytes)
uidPointer to Uid struct. The first 4 bytes of the UID is used.

◆ PCD_CalculateCRC()

MFRC522::StatusCode MFRC522::PCD_CalculateCRC ( byte *  data,
byte  length,
byte *  result 
)

Use the CRC coprocessor in the MFRC522 to calculate a CRC_A.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
dataIn: Pointer to the data to transfer to the FIFO for CRC calculation.
lengthIn: The number of bytes to transfer.
resultOut: Pointer to result buffer. Result is written to result[0..1], low byte first.

◆ PCD_ClearRegisterBitMask()

void MFRC522::PCD_ClearRegisterBitMask ( PCD_Register  reg,
byte  mask 
)

Clears the bits given in mask from register reg.

Parameters
regThe register to update. One of the PCD_Register enums.
maskThe bits to clear.

◆ PCD_CommunicateWithPICC()

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

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

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
commandThe command to execute. One of the PCD_Command enums.
waitIRqThe bits in the ComIrqReg register that signals successful completion of the command.
sendDataPointer to the data to transfer to the FIFO.
sendLenNumber of bytes to transfer to the FIFO.
backDatanullptr or pointer to buffer if data should be read back after executing the command.
backLenIn: Max number of bytes to write to *backData. Out: The number of bytes returned.
validBitsIn/Out: The number of valid bits in the last byte. 0 for 8 valid bits.
rxAlignIn: Defines the bit position in backData[0] for the first bit received. Default 0.
checkCRCIn: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.

◆ PCD_DumpVersionToSerial()

void MFRC522::PCD_DumpVersionToSerial ( )

Dumps debug info about the connected PCD to Serial. Shows all known firmware versions

◆ PCD_GetAntennaGain()

byte MFRC522::PCD_GetAntennaGain ( )

Get the current MFRC522 Receiver Gain (RxGain[2:0]) value. See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf NOTE: Return value scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits.

Returns
Value of the RxGain, scrubbed to the 3 bits used.

◆ PCD_Init() [1/2]

void MFRC522::PCD_Init ( )

Initializes the MFRC522 chip.

◆ PCD_Init() [2/2]

void MFRC522::PCD_Init ( byte  chipSelectPin,
byte  resetPowerDownPin 
)

Initializes the MFRC522 chip.

Parameters
chipSelectPinArduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low)
resetPowerDownPinArduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low)

◆ PCD_MIFARE_Transceive()

MFRC522::StatusCode MFRC522::PCD_MIFARE_Transceive ( byte *  sendData,
byte  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.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
sendDataPointer to the data to transfer to the FIFO. Do NOT include the CRC_A.
sendLenNumber of bytes in sendData.
acceptTimeoutTrue => A timeout is also success

◆ PCD_NTAG216_AUTH()

MFRC522::StatusCode MFRC522::PCD_NTAG216_AUTH ( byte *  passWord,
byte  pACK[] 
)

Authenticate with a NTAG216.

Only for NTAG216. First implemented by Gargantuanman.

Parameters
[in]passWordpassword.
[in]pACKresult success???.
Returns
STATUS_OK on success, STATUS_??? otherwise.

◆ PCD_PerformSelfTest()

bool MFRC522::PCD_PerformSelfTest ( )

Performs a self-test of the MFRC522 See 16.1.1 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf

Returns
Whether or not the test passed. Or false if no firmware reference is available.

◆ PCD_ReadRegister() [1/2]

byte MFRC522::PCD_ReadRegister ( PCD_Register  reg)

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

Parameters
regThe register to read from. One of the PCD_Register enums.

◆ PCD_ReadRegister() [2/2]

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

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

Parameters
regThe register to read from. One of the PCD_Register enums.
countThe number of bytes to read
valuesByte array to store the values in.
rxAlignOnly bit positions rxAlign..7 in values[0] are updated.

◆ PCD_Reset()

void MFRC522::PCD_Reset ( )

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

◆ PCD_SetAntennaGain()

void MFRC522::PCD_SetAntennaGain ( byte  mask)

Set the MFRC522 Receiver Gain (RxGain) to value specified by given mask. See 9.3.3.6 / table 98 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf NOTE: Given mask is scrubbed with (0x07<<4)=01110000b as RCFfgReg may use reserved bits.

◆ PCD_SetRegisterBitMask()

void MFRC522::PCD_SetRegisterBitMask ( PCD_Register  reg,
byte  mask 
)

Sets the bits given in mask in register reg.

Parameters
regThe register to update. One of the PCD_Register enums.
maskThe bits to set.

◆ PCD_StopCrypto1()

void MFRC522::PCD_StopCrypto1 ( )

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.

◆ PCD_TransceiveData()

MFRC522::StatusCode MFRC522::PCD_TransceiveData ( byte *  sendData,
byte  sendLen,
byte *  backData,
byte *  backLen,
byte *  validBits = nullptr,
byte  rxAlign = 0,
bool  checkCRC = false 
)

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

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
sendDataPointer to the data to transfer to the FIFO.
sendLenNumber of bytes to transfer to the FIFO.
backDatanullptr or pointer to buffer if data should be read back after executing the command.
backLenIn: Max number of bytes to write to *backData. Out: The number of bytes returned.
validBitsIn/Out: The number of valid bits in the last byte. 0 for 8 valid bits. Default nullptr.
rxAlignIn: Defines the bit position in backData[0] for the first bit received. Default 0.
checkCRCIn: True => The last two bytes of the response is assumed to be a CRC_A that must be validated.

◆ PCD_WriteRegister() [1/2]

void MFRC522::PCD_WriteRegister ( PCD_Register  reg,
byte  value 
)

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

Parameters
regThe register to write to. One of the PCD_Register enums.
valueThe value to write.

◆ PCD_WriteRegister() [2/2]

void MFRC522::PCD_WriteRegister ( PCD_Register  reg,
byte  count,
byte *  values 
)

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

Parameters
regThe register to write to. One of the PCD_Register enums.
countThe number of bytes to write to the register
valuesThe values to write. Byte array.

◆ PICC_DumpDetailsToSerial()

void MFRC522::PICC_DumpDetailsToSerial ( Uid uid)

Dumps card info (UID,SAK,Type) about the selected PICC to Serial.

kept for backward compatibility

Parameters
uidPointer to Uid struct returned from a successful PICC_Select().

◆ PICC_DumpMifareClassicSectorToSerial()

void MFRC522::PICC_DumpMifareClassicSectorToSerial ( Uid uid,
MIFARE_Key key,
byte  sector 
)

Dumps memory contents of a sector of a MIFARE Classic PICC. Uses PCD_Authenticate(), MIFARE_Read() and PCD_StopCrypto1. Always uses PICC_CMD_MF_AUTH_KEY_A because only Key A can always read the sector trailer access bits.

Parameters
uidPointer to Uid struct returned from a successful PICC_Select().
keyKey A for the sector.
sectorThe sector to dump, 0..39.

◆ PICC_DumpMifareClassicToSerial()

void MFRC522::PICC_DumpMifareClassicToSerial ( Uid uid,
PICC_Type  piccType,
MIFARE_Key key 
)

Dumps memory contents of a MIFARE Classic PICC. On success the PICC is halted after dumping the data.

Parameters
uidPointer to Uid struct returned from a successful PICC_Select().
piccTypeOne of the PICC_Type enums.
keyKey A used for all sectors.

◆ PICC_DumpMifareUltralightToSerial()

void MFRC522::PICC_DumpMifareUltralightToSerial ( )

Dumps memory contents of a MIFARE Ultralight PICC.

◆ PICC_DumpToSerial()

void MFRC522::PICC_DumpToSerial ( Uid uid)

Dumps debug info about the selected PICC to Serial. On success the PICC is halted after dumping the data. For MIFARE Classic the factory default key of 0xFFFFFFFFFFFF is tried.

Kept for bakward compatibility

Parameters
uidPointer to Uid struct returned from a successful PICC_Select().

◆ PICC_GetType()

MFRC522::PICC_Type MFRC522::PICC_GetType ( byte  sak)
static

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

Returns
PICC_Type
Parameters
sakThe SAK byte returned from PICC_Select().

◆ PICC_HaltA()

MFRC522::StatusCode MFRC522::PICC_HaltA ( )

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

Returns
STATUS_OK on success, STATUS_??? otherwise.

◆ PICC_IsNewCardPresent()

bool MFRC522::PICC_IsNewCardPresent ( )
virtual

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

◆ PICC_ReadCardSerial()

bool MFRC522::PICC_ReadCardSerial ( )
virtual

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

Returns
bool

◆ PICC_REQA_or_WUPA()

MFRC522::StatusCode MFRC522::PICC_REQA_or_WUPA ( byte  command,
byte *  bufferATQA,
byte *  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.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
commandThe command to send - PICC_CMD_REQA or PICC_CMD_WUPA
bufferATQAThe buffer to store the ATQA (Answer to request) in
bufferSizeBuffer size, at least two bytes. Also number of bytes returned if STATUS_OK.

◆ PICC_RequestA()

MFRC522::StatusCode MFRC522::PICC_RequestA ( byte *  bufferATQA,
byte *  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.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
bufferATQAThe buffer to store the ATQA (Answer to request) in
bufferSizeBuffer size, at least two bytes. Also number of bytes returned if STATUS_OK.

◆ PICC_Select()

MFRC522::StatusCode MFRC522::PICC_Select ( Uid uid,
byte  validBits = 0 
)
virtual

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

  • 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?

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
uidPointer to Uid struct. Normally output, but can also be used to supply a known UID.
validBitsThe number of known UID bits supplied in *uid. Normally 0. If set you must also supply uid->size.

◆ PICC_WakeupA()

MFRC522::StatusCode MFRC522::PICC_WakeupA ( byte *  bufferATQA,
byte *  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.

Returns
STATUS_OK on success, STATUS_??? otherwise.
Parameters
bufferATQAThe buffer to store the ATQA (Answer to request) in
bufferSizeBuffer size, at least two bytes. Also number of bytes returned if STATUS_OK.

The documentation for this class was generated from the following files: