renew example firmware_check.ino

- add some comments at performselftest()
This commit is contained in:
Rotzbua
2015-12-08 12:31:15 +01:00
parent 933080c87c
commit bafa2faead
2 changed files with 25 additions and 21 deletions

View File

@@ -293,7 +293,7 @@ void MFRC522::PCD_SetAntennaGain(byte mask) {
* Performs a self-test of the MFRC522 * Performs a self-test of the MFRC522
* See 16.1.1 in http://www.nxp.com/documents/data_sheet/MFRC522.pdf * 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() { bool MFRC522::PCD_PerformSelfTest() {
// This follows directly the steps outlined in 16.1.1 // This follows directly the steps outlined in 16.1.1
@@ -353,7 +353,7 @@ bool MFRC522::PCD_PerformSelfTest() {
reference = MFRC522_firmware_referenceV2_0; reference = MFRC522_firmware_referenceV2_0;
break; break;
default: // Unknown version default: // Unknown version
return false; return false; // abort test
} }
// Verify that the results match up to our expectations // Verify that the results match up to our expectations

View File

@@ -1,12 +1,13 @@
/* /*
* ---------------------------------------------------------------------------- * --------------------------------------------------------------------------------------------------------------------
* Example sketch/program to test your firmware. * Example sketch/program to test your firmware.
* ---------------------------------------------------------------------------- * --------------------------------------------------------------------------------------------------------------------
* This is a MFRC522 library example; see https://github.com/miguelbalboa/rfid * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
* for further details and other examples.
* *
* NOTE: The library file MFRC522.h has a lot of useful info. The functions are * This example test the firmware of your MFRC522 reader module, only known version can be checked. If the test passed
* documented in MFRC522.cpp. Please read it. * 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. * Released into the public domain.
* *
@@ -31,8 +32,11 @@
#define RST_PIN 9 // Configurable, see typical pin layout above #define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // 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() { void setup() {
Serial.begin(9600); // Initialize serial communications with the PC 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) 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("MFRC522 Digital self test"));
Serial.println(F("*****************************")); Serial.println(F("*****************************"));
ShowReaderVersion(); // Show version of PCD - MFRC522 Card Reader 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...")); Serial.println(F("Performing test..."));
bool result = mfrc522.PCD_PerformSelfTest(); bool result = mfrc522.PCD_PerformSelfTest(); // perform the test
Serial.println(F("-----------------------------")); Serial.println(F("-----------------------------"));
Serial.print(F("Result: ")); Serial.print(F("Result: "));
if (result) if (result)
@@ -64,17 +71,14 @@ void ShowReaderVersion() {
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print(F("Firmware Version: 0x")); Serial.print(F("Firmware Version: 0x"));
Serial.print(v, HEX); Serial.print(v, HEX);
if (v == 0x88) // Lookup which version
Serial.print(F(" = (clone)")); switch(v) {
else if (v == 0x90) case 0x88: Serial.println(F(" = (clone)")); break;
Serial.print(F(" = v0.0")); case 0x90: Serial.println(F(" = v0.0")); break;
else if (v == 0x91) case 0x91: Serial.println(F(" = v1.0")); break;
Serial.print(F(" = v1.0")); case 0x92: Serial.println(F(" = v2.0")); break;
else if (v == 0x92) default: Serial.println(F(" = (unknown)"));
Serial.print(F(" = v2.0")); }
else
Serial.print(F(" = (unknown)"));
Serial.println();
// When 0x00 or 0xFF is returned, communication probably failed // When 0x00 or 0xFF is returned, communication probably failed
if ((v == 0x00) || (v == 0xFF)) if ((v == 0x00) || (v == 0xFF))
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?")); Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));