From bafa2faeadf890e6a5278986ae828811ad9dc1f9 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Tue, 8 Dec 2015 12:31:15 +0100 Subject: [PATCH] renew example firmware_check.ino - add some comments at performselftest() --- MFRC522.cpp | 4 +-- examples/firmware_check/firmware_check.ino | 42 ++++++++++++---------- 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/MFRC522.cpp b/MFRC522.cpp index 63d13b8..4ecdadb 100644 --- a/MFRC522.cpp +++ b/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 diff --git a/examples/firmware_check/firmware_check.ino b/examples/firmware_check/firmware_check.ino index b923074..49a8624 100644 --- a/examples/firmware_check/firmware_check.ino +++ b/examples/firmware_check/firmware_check.ino @@ -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?"));