RFID-RC522 code for testing a cheap 13.56 MHz module with the Nucleo F401RE. Based on the MFRC522 code by Martin Olejar.

Dependencies:   mbed

Dependents:   RFID-RC522

Fork of MFRC522 by Martin Olejar

Embed: (wiki syntax)

« Back to documentation index

MFRC522 Class Reference

MFRC522 Class Reference

MFRC522 example. More...

#include <MFRC522.h>

Public Types

enum  PCD_Register
 

MFRC522 registers (described in chapter 9 of the datasheet).

More...

Public Member Functions

 MFRC522 (PinName mosi, PinName miso, PinName sclk, PinName cs, PinName reset)
 MFRC522 constructor.
 ~MFRC522 ()
 MFRC522 destructor.
Functions for manipulating the MFRC522
void PCD_Init (void)
 Initializes the MFRC522 chip.
void PCD_Reset (void)
 Performs a soft reset on the MFRC522 chip and waits for it to be ready again.
void PCD_AntennaOn (void)
 Turns the antenna on by enabling pins TX1 and TX2.
void PCD_WriteRegister (uint8_t reg, uint8_t value)
 Writes a byte to the specified register in the MFRC522 chip.
void PCD_WriteRegister (uint8_t reg, uint8_t count, uint8_t *values)
 Writes a number of bytes to the specified register in the MFRC522 chip.
uint8_t PCD_ReadRegister (uint8_t reg)
 Reads a byte from the specified register in the MFRC522 chip.
void PCD_ReadRegister (uint8_t reg, uint8_t count, uint8_t *values, uint8_t rxAlign=0)
 Reads a number of bytes from the specified register in the MFRC522 chip.
void PCD_SetRegisterBits (uint8_t reg, uint8_t mask)
 Sets the bits given in mask in register reg.
void PCD_ClrRegisterBits (uint8_t reg, uint8_t mask)
 Clears the bits given in mask from register reg.
uint8_t PCD_CalculateCRC (uint8_t *data, uint8_t length, uint8_t *result)
 Use the CRC coprocessor in the MFRC522 to calculate a CRC_A.
uint8_t 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.
uint8_t 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)
 Transfers data to the MFRC522 FIFO, executes a commend, waits for completion and transfers data back from the FIFO.
uint8_t PICC_RequestA (uint8_t *bufferATQA, uint8_t *bufferSize)
 Transmits a REQuest command, Type A.
uint8_t PICC_WakeupA (uint8_t *bufferATQA, uint8_t *bufferSize)
 Transmits a Wake-UP command, Type A.
uint8_t PICC_REQA_or_WUPA (uint8_t command, uint8_t *bufferATQA, uint8_t *bufferSize)
 Transmits REQA or WUPA commands.
uint8_t PICC_Select (Uid *uid, uint8_t validBits=0)
 Transmits SELECT/ANTICOLLISION commands to select a single PICC.
uint8_t PICC_HaltA (void)
 Instructs a PICC in state ACTIVE(*) to go to state HALT.
Functions for communicating with MIFARE PICCs
uint8_t PCD_Authenticate (uint8_t command, uint8_t blockAddr, MIFARE_Key *key, Uid *uid)
 Executes the MFRC522 MFAuthent command.
void PCD_StopCrypto1 (void)
 Used to exit the PCD from its authenticated state.
uint8_t MIFARE_Read (uint8_t blockAddr, uint8_t *buffer, uint8_t *bufferSize)
 Reads 16 bytes (+ 2 bytes CRC_A) from the active PICC.
uint8_t MIFARE_Write (uint8_t blockAddr, uint8_t *buffer, uint8_t bufferSize)
 Writes 16 bytes to the active PICC.
uint8_t MIFARE_UltralightWrite (uint8_t page, uint8_t *buffer, uint8_t bufferSize)
 Writes a 4 byte page to the active MIFARE Ultralight PICC.
uint8_t MIFARE_Decrement (uint8_t blockAddr, uint32_t delta)
 MIFARE Decrement subtracts the delta from the value of the addressed block, and stores the result in a volatile memory.
uint8_t MIFARE_Increment (uint8_t blockAddr, uint32_t delta)
 MIFARE Increment adds the delta to the value of the addressed block, and stores the result in a volatile memory.
uint8_t MIFARE_Restore (uint8_t blockAddr)
 MIFARE Restore copies the value of the addressed block into a volatile memory.
uint8_t MIFARE_Transfer (uint8_t blockAddr)
 MIFARE Transfer writes the value stored in the volatile memory into one MIFARE Classic block.
Support functions
uint8_t PCD_MIFARE_Transceive (uint8_t *sendData, uint8_t sendLen, bool acceptTimeout=false)
 Wrapper for MIFARE protocol communication.
uint8_t PICC_GetType (uint8_t sak)
 Translates the SAK (Select Acknowledge) to a PICC type.
char * PICC_GetTypeName (uint8_t type)
 Returns a string pointer to the PICC type name.
char * GetStatusCodeName (uint8_t code)
 Returns a string pointer to a status code name.
void 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.
Convenience functions - does not add extra functionality
bool PICC_IsNewCardPresent (void)
 Returns true if a PICC responds to PICC_CMD_REQA.
bool PICC_ReadCardSerial (void)
 Simple wrapper around PICC_Select.

Detailed Description

MFRC522 example.

 #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);
   }
 }

Definition at line 150 of file MFRC522.h.


Member Enumeration Documentation

MFRC522 registers (described in chapter 9 of the datasheet).

When using SPI all addresses are shifted one bit left in the "SPI address byte" (section 8.1.2.3)

Definition at line 157 of file MFRC522.h.


Constructor & Destructor Documentation

MFRC522 ( PinName  mosi,
PinName  miso,
PinName  sclk,
PinName  cs,
PinName  reset 
)

MFRC522 constructor.

Constructor.

Parameters:
mosiSPI MOSI pin
misoSPI MISO pin
sclkSPI SCLK pin
csSPI CS pin
resetReset pin

Prepares the output pins.

Definition at line 50 of file MFRC522.cpp.

~MFRC522 (  )

MFRC522 destructor.

Destructor.

Definition at line 71 of file MFRC522.cpp.


Member Function Documentation

char * GetStatusCodeName ( uint8_t  code )

Returns a string pointer to a status code name.

Parameters:
codeOne of the StatusCode enums.
Returns:
A string pointer to a status code name.

Definition at line 1108 of file MFRC522.cpp.

uint8_t MIFARE_Decrement ( uint8_t  blockAddr,
uint32_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.

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

Definition at line 926 of file MFRC522.cpp.

uint8_t MIFARE_Increment ( uint8_t  blockAddr,
uint32_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.

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

Definition at line 934 of file MFRC522.cpp.

uint8_t 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:
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.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 833 of file MFRC522.cpp.

uint8_t MIFARE_Restore ( uint8_t  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.

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

Definition at line 942 of file MFRC522.cpp.

void 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:
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)

Definition at line 1116 of file MFRC522.cpp.

uint8_t 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:
blockAddrThe block (0-0xff) number.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 982 of file MFRC522.cpp.

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

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

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.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 897 of file MFRC522.cpp.

uint8_t 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:
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.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 861 of file MFRC522.cpp.

void PCD_AntennaOn ( void   )

Turns the antenna on by enabling pins TX1 and TX2.

After a reset these pins disabled.

Definition at line 295 of file MFRC522.cpp.

uint8_t PCD_Authenticate ( uint8_t  command,
uint8_t  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.

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.
Returns:
STATUS_OK on success, STATUS_??? otherwise. Probably STATUS_TIMEOUT if you supply the wrong key.

Definition at line 797 of file MFRC522.cpp.

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

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

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

Definition at line 202 of file MFRC522.cpp.

void PCD_ClrRegisterBits ( uint8_t  reg,
uint8_t  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.

Definition at line 192 of file MFRC522.cpp.

uint8_t 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 
)

Transfers data to the MFRC522 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.

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.
backDataNULL 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.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

CRC validation can only be done if backData and backLen are specified.

Definition at line 328 of file MFRC522.cpp.

void PCD_Init ( void   )

Initializes the MFRC522 chip.

Definition at line 247 of file MFRC522.cpp.

uint8_t 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:
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
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 1003 of file MFRC522.cpp.

uint8_t PCD_ReadRegister ( uint8_t  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.
Returns:
Register value

The interface is described in the datasheet section 8.1.2.

Definition at line 118 of file MFRC522.cpp.

void PCD_ReadRegister ( uint8_t  reg,
uint8_t  count,
uint8_t *  values,
uint8_t  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.

The interface is described in the datasheet section 8.1.2.

Definition at line 138 of file MFRC522.cpp.

void PCD_Reset ( void   )

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

Definition at line 276 of file MFRC522.cpp.

void PCD_SetRegisterBits ( uint8_t  reg,
uint8_t  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.

Definition at line 183 of file MFRC522.cpp.

void 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.

Definition at line 824 of file MFRC522.cpp.

uint8_t 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:
sendDataPointer to the data to transfer to the FIFO.
sendLenNumber of bytes to transfer to the FIFO.
backDataNULL or pointer to buffer if data should be read back after executing the command.
backLenMax number of bytes to write to *backData. Out: The number of bytes returned.
validBitsThe number of valid bits in the last byte. 0 for 8 valid bits. Default NULL.
rxAlignDefines the bit position in backData[0] for the first bit received. Default 0.
checkCRCTrue => 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.

CRC validation can only be done if backData and backLen are specified.

Definition at line 312 of file MFRC522.cpp.

void PCD_WriteRegister ( uint8_t  reg,
uint8_t  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.

The interface is described in the datasheet section 8.1.2.

Definition at line 85 of file MFRC522.cpp.

void PCD_WriteRegister ( uint8_t  reg,
uint8_t  count,
uint8_t *  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.

The interface is described in the datasheet section 8.1.2.

Definition at line 100 of file MFRC522.cpp.

uint8_t PICC_GetType ( uint8_t  sak )

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

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

Definition at line 1057 of file MFRC522.cpp.

char * PICC_GetTypeName ( uint8_t  type )

Returns a string pointer to the PICC type name.

Parameters:
typeOne of the PICC_Type enums.
Returns:
A string pointer to the PICC type name.

Definition at line 1095 of file MFRC522.cpp.

uint8_t PICC_HaltA ( void   )

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

Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 757 of file MFRC522.cpp.

bool 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

Definition at line 1139 of file MFRC522.cpp.

bool PICC_ReadCardSerial ( void   )

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

Definition at line 1150 of file MFRC522.cpp.

uint8_t 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:
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.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 464 of file MFRC522.cpp.

uint8_t 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:
bufferATQAThe buffer to store the ATQA (Answer to request) in
bufferSizeBuffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 446 of file MFRC522.cpp.

uint8_t PICC_Select ( Uid *  uid,
uint8_t  validBits = 0 
)

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?

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.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

Definition at line 498 of file MFRC522.cpp.

uint8_t 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:
bufferATQAThe buffer to store the ATQA (Answer to request) in
bufferSizeBuffer size, at least two bytes. Also number of bytes returned if STATUS_OK.
Returns:
STATUS_OK on success, STATUS_??? otherwise.

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.

Definition at line 455 of file MFRC522.cpp.