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
* 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

View File

@@ -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?"));