Merge branch 'master' into upd-readme
This commit is contained in:
14
MFRC522.cpp
14
MFRC522.cpp
@@ -293,7 +293,7 @@ void MFRC522::PCD_SetAntennaGain(byte mask) {
|
||||
* Performs a self-test of the MFRC522
|
||||
* See 16.1.1 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf
|
||||
*
|
||||
* @return Whether or not the test passed.
|
||||
* @return Whether or not the test passed. Or false if no firmware reference is available.
|
||||
*/
|
||||
bool MFRC522::PCD_PerformSelfTest() {
|
||||
// This follows directly the steps outlined in 16.1.1
|
||||
@@ -353,7 +353,7 @@ bool MFRC522::PCD_PerformSelfTest() {
|
||||
reference = MFRC522_firmware_referenceV2_0;
|
||||
break;
|
||||
default: // Unknown version
|
||||
return false;
|
||||
return false; // abort test
|
||||
}
|
||||
|
||||
// Verify that the results match up to our expectations
|
||||
@@ -1257,7 +1257,7 @@ MFRC522::PICC_Type MFRC522::PICC_GetType(byte sak ///< The SAK byte returned fr
|
||||
*
|
||||
* @return const __FlashStringHelper *
|
||||
*/
|
||||
const __FlashStringHelper *MFRC522::PICC_GetTypeName(byte piccType ///< One of the PICC_Type enums.
|
||||
const __FlashStringHelper *MFRC522::PICC_GetTypeName(PICC_Type piccType ///< One of the PICC_Type enums.
|
||||
) {
|
||||
switch (piccType) {
|
||||
case PICC_TYPE_ISO_14443_4: return F("PICC compliant with ISO/IEC 14443-4");
|
||||
@@ -1295,7 +1295,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
|
||||
Serial.println();
|
||||
|
||||
// PICC type
|
||||
byte piccType = PICC_GetType(uid->sak);
|
||||
PICC_Type piccType = PICC_GetType(uid->sak);
|
||||
Serial.print(F("PICC type: "));
|
||||
Serial.println(PICC_GetTypeName(piccType));
|
||||
|
||||
@@ -1337,7 +1337,7 @@ void MFRC522::PICC_DumpToSerial(Uid *uid ///< Pointer to Uid struct returned fro
|
||||
* On success the PICC is halted after dumping the data.
|
||||
*/
|
||||
void MFRC522::PICC_DumpMifareClassicToSerial( Uid *uid, ///< Pointer to Uid struct returned from a successful PICC_Select().
|
||||
byte piccType, ///< One of the PICC_Type enums.
|
||||
PICC_Type piccType, ///< One of the PICC_Type enums.
|
||||
MIFARE_Key *key ///< Key A used for all sectors.
|
||||
) {
|
||||
byte no_of_sectors = 0;
|
||||
@@ -1795,7 +1795,7 @@ bool MFRC522::MIFARE_UnbrickUidSector(bool logErrors) {
|
||||
bool MFRC522::PICC_IsNewCardPresent() {
|
||||
byte bufferATQA[2];
|
||||
byte bufferSize = sizeof(bufferATQA);
|
||||
byte result = PICC_RequestA(bufferATQA, &bufferSize);
|
||||
MFRC522::StatusCode result = PICC_RequestA(bufferATQA, &bufferSize);
|
||||
return (result == STATUS_OK || result == STATUS_COLLISION);
|
||||
} // End PICC_IsNewCardPresent()
|
||||
|
||||
@@ -1808,6 +1808,6 @@ bool MFRC522::PICC_IsNewCardPresent() {
|
||||
* @return bool
|
||||
*/
|
||||
bool MFRC522::PICC_ReadCardSerial() {
|
||||
byte result = PICC_Select(&uid);
|
||||
MFRC522::StatusCode result = PICC_Select(&uid);
|
||||
return (result == STATUS_OK);
|
||||
} // End
|
||||
|
||||
88
MFRC522.h
88
MFRC522.h
@@ -272,30 +272,32 @@ public:
|
||||
};
|
||||
|
||||
// PICC types we can detect. Remember to update PICC_GetTypeName() if you add more.
|
||||
// last value set to 255, hints compiler to use byte instead of default integer, works for arduino ide to save ram and flash
|
||||
enum PICC_Type {
|
||||
PICC_TYPE_UNKNOWN = 0,
|
||||
PICC_TYPE_ISO_14443_4 = 1, // PICC compliant with ISO/IEC 14443-4
|
||||
PICC_TYPE_ISO_18092 = 2, // PICC compliant with ISO/IEC 18092 (NFC)
|
||||
PICC_TYPE_MIFARE_MINI = 3, // MIFARE Classic protocol, 320 bytes
|
||||
PICC_TYPE_MIFARE_1K = 4, // MIFARE Classic protocol, 1KB
|
||||
PICC_TYPE_MIFARE_4K = 5, // MIFARE Classic protocol, 4KB
|
||||
PICC_TYPE_MIFARE_UL = 6, // MIFARE Ultralight or Ultralight C
|
||||
PICC_TYPE_MIFARE_PLUS = 7, // MIFARE Plus
|
||||
PICC_TYPE_TNP3XXX = 8, // Only mentioned in NXP AN 10833 MIFARE Type Identification Procedure
|
||||
PICC_TYPE_UNKNOWN ,
|
||||
PICC_TYPE_ISO_14443_4 , // PICC compliant with ISO/IEC 14443-4
|
||||
PICC_TYPE_ISO_18092 , // PICC compliant with ISO/IEC 18092 (NFC)
|
||||
PICC_TYPE_MIFARE_MINI , // MIFARE Classic protocol, 320 bytes
|
||||
PICC_TYPE_MIFARE_1K , // MIFARE Classic protocol, 1KB
|
||||
PICC_TYPE_MIFARE_4K , // MIFARE Classic protocol, 4KB
|
||||
PICC_TYPE_MIFARE_UL , // MIFARE Ultralight or Ultralight C
|
||||
PICC_TYPE_MIFARE_PLUS , // MIFARE Plus
|
||||
PICC_TYPE_TNP3XXX , // Only mentioned in NXP AN 10833 MIFARE Type Identification Procedure
|
||||
PICC_TYPE_NOT_COMPLETE = 255 // SAK indicates UID is not complete.
|
||||
};
|
||||
|
||||
// Return codes from the functions in this class. Remember to update GetStatusCodeName() if you add more.
|
||||
// last value set to 255, hints compiler to use byte instead of default integer, works for arduino ide to save ram and flash
|
||||
enum StatusCode {
|
||||
STATUS_OK = 1, // Success
|
||||
STATUS_ERROR = 2, // Error in communication
|
||||
STATUS_COLLISION = 3, // Collission detected
|
||||
STATUS_TIMEOUT = 4, // Timeout in communication.
|
||||
STATUS_NO_ROOM = 5, // A buffer is not big enough.
|
||||
STATUS_INTERNAL_ERROR = 6, // Internal error in the code. Should not happen ;-)
|
||||
STATUS_INVALID = 7, // Invalid argument.
|
||||
STATUS_CRC_WRONG = 8, // The CRC_A does not match
|
||||
STATUS_MIFARE_NACK = 9 // A MIFARE PICC responded with NAK.
|
||||
STATUS_OK , // Success
|
||||
STATUS_ERROR , // Error in communication
|
||||
STATUS_COLLISION , // Collission detected
|
||||
STATUS_TIMEOUT , // Timeout in communication.
|
||||
STATUS_NO_ROOM , // A buffer is not big enough.
|
||||
STATUS_INTERNAL_ERROR , // Internal error in the code. Should not happen ;-)
|
||||
STATUS_INVALID , // Invalid argument.
|
||||
STATUS_CRC_WRONG , // The CRC_A does not match
|
||||
STATUS_MIFARE_NACK = 255 // A MIFARE PICC responded with NAK.
|
||||
};
|
||||
|
||||
// A struct used for passing the UID of a PICC.
|
||||
@@ -333,7 +335,7 @@ public:
|
||||
void setBitMask(unsigned char reg, unsigned char mask);
|
||||
void PCD_SetRegisterBitMask(byte reg, byte mask);
|
||||
void PCD_ClearRegisterBitMask(byte reg, byte mask);
|
||||
MFRC522::StatusCode PCD_CalculateCRC(byte *data, byte length, byte *result);
|
||||
StatusCode PCD_CalculateCRC(byte *data, byte length, byte *result);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for manipulating the MFRC522
|
||||
@@ -350,43 +352,43 @@ public:
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for communicating with PICCs
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
MFRC522::StatusCode PCD_TransceiveData(byte *sendData, byte sendLen, byte *backData, byte *backLen, byte *validBits = NULL, byte rxAlign = 0, bool checkCRC = false);
|
||||
MFRC522::StatusCode PCD_CommunicateWithPICC(byte command, byte waitIRq, byte *sendData, byte sendLen, byte *backData = NULL, byte *backLen = NULL, byte *validBits = NULL, byte rxAlign = 0, bool checkCRC = false);
|
||||
MFRC522::StatusCode PICC_RequestA(byte *bufferATQA, byte *bufferSize);
|
||||
MFRC522::StatusCode PICC_WakeupA(byte *bufferATQA, byte *bufferSize);
|
||||
MFRC522::StatusCode PICC_REQA_or_WUPA(byte command, byte *bufferATQA, byte *bufferSize);
|
||||
MFRC522::StatusCode PICC_Select(Uid *uid, byte validBits = 0);
|
||||
MFRC522::StatusCode PICC_HaltA();
|
||||
StatusCode PCD_TransceiveData(byte *sendData, byte sendLen, byte *backData, byte *backLen, byte *validBits = NULL, byte rxAlign = 0, bool checkCRC = false);
|
||||
StatusCode PCD_CommunicateWithPICC(byte command, byte waitIRq, byte *sendData, byte sendLen, byte *backData = NULL, byte *backLen = NULL, byte *validBits = NULL, 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);
|
||||
StatusCode PICC_Select(Uid *uid, byte validBits = 0);
|
||||
StatusCode PICC_HaltA();
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Functions for communicating with MIFARE PICCs
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
MFRC522::StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
|
||||
StatusCode PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid *uid);
|
||||
void PCD_StopCrypto1();
|
||||
MFRC522::StatusCode MIFARE_Read(byte blockAddr, byte *buffer, byte *bufferSize);
|
||||
MFRC522::StatusCode MIFARE_Write(byte blockAddr, byte *buffer, byte bufferSize);
|
||||
MFRC522::StatusCode MIFARE_Ultralight_Write(byte page, byte *buffer, byte bufferSize);
|
||||
MFRC522::StatusCode MIFARE_Decrement(byte blockAddr, long delta);
|
||||
MFRC522::StatusCode MIFARE_Increment(byte blockAddr, long delta);
|
||||
MFRC522::StatusCode MIFARE_Restore(byte blockAddr);
|
||||
MFRC522::StatusCode MIFARE_Transfer(byte blockAddr);
|
||||
MFRC522::StatusCode MIFARE_GetValue(byte blockAddr, long *value);
|
||||
MFRC522::StatusCode MIFARE_SetValue(byte blockAddr, long value);
|
||||
MFRC522::StatusCode PCD_NTAG216_AUTH(byte *passWord, byte pACK[]);
|
||||
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, long delta);
|
||||
StatusCode MIFARE_Increment(byte blockAddr, long delta);
|
||||
StatusCode MIFARE_Restore(byte blockAddr);
|
||||
StatusCode MIFARE_Transfer(byte blockAddr);
|
||||
StatusCode MIFARE_GetValue(byte blockAddr, long *value);
|
||||
StatusCode MIFARE_SetValue(byte blockAddr, long value);
|
||||
StatusCode PCD_NTAG216_AUTH(byte *passWord, byte pACK[]);
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
// Support functions
|
||||
/////////////////////////////////////////////////////////////////////////////////////
|
||||
MFRC522::StatusCode PCD_MIFARE_Transceive(byte *sendData, byte sendLen, bool acceptTimeout = false);
|
||||
StatusCode PCD_MIFARE_Transceive(byte *sendData, byte sendLen, bool acceptTimeout = false);
|
||||
// old function used too much memory, now name moved to flash; if you need char, copy from flash to memory
|
||||
//const char *GetStatusCodeName(byte code);
|
||||
const __FlashStringHelper *GetStatusCodeName(MFRC522::StatusCode code);
|
||||
MFRC522::PICC_Type PICC_GetType(byte sak);
|
||||
const __FlashStringHelper *GetStatusCodeName(StatusCode code);
|
||||
PICC_Type PICC_GetType(byte sak);
|
||||
// old function used too much memory, now name moved to flash; if you need char, copy from flash to memory
|
||||
//const char *PICC_GetTypeName(byte type);
|
||||
const __FlashStringHelper *PICC_GetTypeName(byte type);
|
||||
const __FlashStringHelper *PICC_GetTypeName(PICC_Type type);
|
||||
void PICC_DumpToSerial(Uid *uid);
|
||||
void PICC_DumpMifareClassicToSerial(Uid *uid, byte piccType, MIFARE_Key *key);
|
||||
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);
|
||||
@@ -403,7 +405,7 @@ public:
|
||||
private:
|
||||
byte _chipSelectPin; // Arduino pin connected to MFRC522's SPI slave select input (Pin 24, NSS, active low)
|
||||
byte _resetPowerDownPin; // Arduino pin connected to MFRC522's reset and power down input (Pin 6, NRSTPD, active low)
|
||||
MFRC522::StatusCode MIFARE_TwoStepHelper(byte command, byte blockAddr, long data);
|
||||
StatusCode MIFARE_TwoStepHelper(byte command, byte blockAddr, long data);
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
5 Dec 2015
|
||||
- recognize infineon cards correctly @mayatforest
|
||||
- added multi reader support, see example @lmmeng
|
||||
- functions return MFRC522::StatusCode instead of generic byte @rotzbua
|
||||
- functions return MFRC522::StatusCode and MFRC522::PICC_Type instead of generic byte @rotzbua
|
||||
- removed int-values of MFRC522::StatusCode and MFRC522::PICC_Type @rotzbua
|
||||
|
||||
10 Nov 2014
|
||||
- Updated the changelog.
|
||||
|
||||
@@ -91,7 +91,7 @@ void loop() {
|
||||
Serial.println();
|
||||
|
||||
// Dump PICC type
|
||||
// byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
// MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
// Serial.print(F("PICC type: "));
|
||||
// Serial.print(mfrc522.PICC_GetTypeName(piccType));
|
||||
// Serial.print(F(" (SAK "));
|
||||
|
||||
@@ -78,7 +78,7 @@ void loop() {
|
||||
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
||||
Serial.println();
|
||||
Serial.print(F("PICC type: "));
|
||||
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
||||
|
||||
// Check for compatibility
|
||||
|
||||
@@ -77,7 +77,7 @@ void loop() {
|
||||
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
||||
Serial.println();
|
||||
Serial.print(F("PICC type: "));
|
||||
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
||||
|
||||
// Check for compatibility
|
||||
|
||||
@@ -72,7 +72,7 @@ void loop() {
|
||||
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
|
||||
Serial.println();
|
||||
Serial.print(F("PICC type: "));
|
||||
byte piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
|
||||
MFRC522::PICC_Type piccType = mfrc522[reader].PICC_GetType(mfrc522[reader].uid.sak);
|
||||
Serial.println(mfrc522[reader].PICC_GetTypeName(piccType));
|
||||
|
||||
// Halt PICC
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
/*
|
||||
* ----------------------------------------------------------------------------
|
||||
* --------------------------------------------------------------------------------------------------------------------
|
||||
* Example sketch/program to test your firmware.
|
||||
* ----------------------------------------------------------------------------
|
||||
* This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid
|
||||
* for further details and other examples.
|
||||
* --------------------------------------------------------------------------------------------------------------------
|
||||
* This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
|
||||
*
|
||||
* NOTE: The library file MFRC522.h has a lot of useful info. The functions are
|
||||
* documented in MFRC522.cpp. Please read it.
|
||||
* This example test the firmware of your MFRC522 reader module, only known version can be checked. If the test passed
|
||||
* it do not mean that your module is faultless! Some modules have bad or broken antennas or the PICC is broken.
|
||||
*
|
||||
* NOTE: for more informations read the README.rst
|
||||
*
|
||||
* Released into the public domain.
|
||||
*
|
||||
@@ -31,8 +32,11 @@
|
||||
#define RST_PIN 9 // Configurable, see typical pin layout above
|
||||
#define SS_PIN 10 // Configurable, see typical pin layout above
|
||||
|
||||
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
|
||||
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
|
||||
|
||||
/**
|
||||
* Check firmware only once at startup
|
||||
*/
|
||||
void setup() {
|
||||
Serial.begin(9600); // Initialize serial communications with the PC
|
||||
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
|
||||
@@ -43,8 +47,11 @@ void setup() {
|
||||
Serial.println(F("MFRC522 Digital self test"));
|
||||
Serial.println(F("*****************************"));
|
||||
ShowReaderVersion(); // Show version of PCD - MFRC522 Card Reader
|
||||
Serial.println(F("-----------------------------"));
|
||||
Serial.println(F("Only known versions supported"));
|
||||
Serial.println(F("-----------------------------"));
|
||||
Serial.println(F("Performing test..."));
|
||||
bool result = mfrc522.PCD_PerformSelfTest();
|
||||
bool result = mfrc522.PCD_PerformSelfTest(); // perform the test
|
||||
Serial.println(F("-----------------------------"));
|
||||
Serial.print(F("Result: "));
|
||||
if (result)
|
||||
@@ -64,17 +71,14 @@ void ShowReaderVersion() {
|
||||
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
|
||||
Serial.print(F("Firmware Version: 0x"));
|
||||
Serial.print(v, HEX);
|
||||
if (v == 0x88)
|
||||
Serial.print(F(" = (clone)"));
|
||||
else if (v == 0x90)
|
||||
Serial.print(F(" = v0.0"));
|
||||
else if (v == 0x91)
|
||||
Serial.print(F(" = v1.0"));
|
||||
else if (v == 0x92)
|
||||
Serial.print(F(" = v2.0"));
|
||||
else
|
||||
Serial.print(F(" = (unknown)"));
|
||||
Serial.println();
|
||||
// Lookup which version
|
||||
switch(v) {
|
||||
case 0x88: Serial.println(F(" = (clone)")); break;
|
||||
case 0x90: Serial.println(F(" = v0.0")); break;
|
||||
case 0x91: Serial.println(F(" = v1.0")); break;
|
||||
case 0x92: Serial.println(F(" = v2.0")); break;
|
||||
default: Serial.println(F(" = (unknown)"));
|
||||
}
|
||||
// When 0x00 or 0xFF is returned, communication probably failed
|
||||
if ((v == 0x00) || (v == 0xFF))
|
||||
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
|
||||
|
||||
@@ -132,7 +132,7 @@ void loop() {
|
||||
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size);
|
||||
Serial.println();
|
||||
Serial.print(F("PICC type: "));
|
||||
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
||||
|
||||
// Try the known default keys
|
||||
|
||||
@@ -53,7 +53,7 @@ void loop() {
|
||||
Serial.print(mfrc522.uid.uidByte[i], HEX);
|
||||
}
|
||||
Serial.print(F(" PICC type: ")); // Dump PICC type
|
||||
byte piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
|
||||
Serial.println(mfrc522.PICC_GetTypeName(piccType));
|
||||
|
||||
byte buffer[34];
|
||||
|
||||
Reference in New Issue
Block a user