From b49790d40c1176cc800dbbc1e7415e8083ac7afc Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Fri, 3 Apr 2015 19:47:11 +0200 Subject: [PATCH 1/7] example for firmware check --- examples/firmware_check/firmware_check.ino | 72 ++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 examples/firmware_check/firmware_check.ino diff --git a/examples/firmware_check/firmware_check.ino b/examples/firmware_check/firmware_check.ino new file mode 100644 index 0000000..c72795b --- /dev/null +++ b/examples/firmware_check/firmware_check.ino @@ -0,0 +1,72 @@ +/* + * ---------------------------------------------------------------------------- + * This is a MFRC522 library example; 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 + * documented in MFRC522.cpp. Please read it. + * + * Released into the public domain. + * ---------------------------------------------------------------------------- + * Example sketch/program showing how to test your firmware. + * + * Typical pin layout used: + * ----------------------------------------------------------------------------------------- + * MFRC522 Arduino Arduino Arduino Arduino Arduino + * Reader/PCD Uno Mega Nano v3 Leonardo/Micro Pro Micro + * Signal Pin Pin Pin Pin Pin Pin + * ----------------------------------------------------------------------------------------- + * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST + * SPI SS SDA(SS) 10 53 D10 10 10 + * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 + * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 + * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 + */ + +#include +#include + +#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. + +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) + SPI.begin(); // Init SPI bus + mfrc522.PCD_Init(); // Init MFRC522 module + + Serial.println(F("*****************************")); + Serial.println(F("MFRC522 Digital self test")); + Serial.println(F("*****************************")); + ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details + Serial.println(F("Performing test...")); + bool result = mfrc522.PCD_PerformSelfTest(); + Serial.println(F("-----------------------------")); + Serial.print(F("Result: ")); + if (result) + Serial.println(F("OK")); + else + Serial.println(F("defect or unknown")); + Serial.println(); +} + +void loop() {} // nothing to do + +void ShowReaderDetails() { + // Get the MFRC522 firmware version + byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); + Serial.print(F("Firmware Version: 0x")); + Serial.print(v, HEX); + if (v == 0x91) + Serial.print(F(" = v1.0")); + else if (v == 0x92) + Serial.print(F(" = v2.0")); + else + Serial.print(F(" = (unknown)")); + Serial.println(); + // 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?")); +} From 956df8e4344f395a671578e1e860e1250ed8e2ad Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Sat, 11 Apr 2015 23:48:48 +0200 Subject: [PATCH 2/7] add comment --- examples/firmware_check/firmware_check.ino | 3 +++ 1 file changed, 3 insertions(+) diff --git a/examples/firmware_check/firmware_check.ino b/examples/firmware_check/firmware_check.ino index c72795b..2bdf348 100644 --- a/examples/firmware_check/firmware_check.ino +++ b/examples/firmware_check/firmware_check.ino @@ -54,6 +54,9 @@ void setup() { void loop() {} // nothing to do +/** +* Helper to print MFRC522 module info +*/ void ShowReaderDetails() { // Get the MFRC522 firmware version byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); From 33fc41a302c7f3069f902b3429fa721dd2bc04f3 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Sun, 12 Apr 2015 16:33:06 +0200 Subject: [PATCH 3/7] add self-test reference for 0x90 --- MFRC522.cpp | 9 ++++++--- MFRC522.h | 20 +++++++++++++++++--- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/MFRC522.cpp b/MFRC522.cpp index 88d7478..b9e7484 100644 --- a/MFRC522.cpp +++ b/MFRC522.cpp @@ -285,9 +285,9 @@ bool MFRC522::PCD_PerformSelfTest() { // 2. Clear the internal buffer by writing 25 bytes of 00h byte ZEROES[25] = {0x00}; - PCD_SetRegisterBitMask(FIFOLevelReg, 0x80); // flush the FIFO buffer - PCD_WriteRegister(FIFODataReg, 25, ZEROES); // write 25 bytes of 00h to FIFO - PCD_WriteRegister(CommandReg, PCD_Mem); // transfer to internal buffer + PCD_SetRegisterBitMask(FIFOLevelReg, 0x80); // flush the FIFO buffer + PCD_WriteRegister(FIFODataReg, 25, ZEROES); // write 25 bytes of 00h to FIFO + PCD_WriteRegister(CommandReg, PCD_Mem); // transfer to internal buffer // 3. Enable self-test PCD_WriteRegister(AutoTestReg, 0x09); @@ -323,6 +323,9 @@ bool MFRC522::PCD_PerformSelfTest() { // Pick the appropriate reference values const byte *reference; switch (version) { + case 0x90: // Version 0.0 + reference = MFRC522_firmware_referenceV0_0; + break; case 0x91: // Version 1.0 reference = MFRC522_firmware_referenceV1_0; break; diff --git a/MFRC522.h b/MFRC522.h index d2c00da..8ac78b7 100644 --- a/MFRC522.h +++ b/MFRC522.h @@ -79,8 +79,21 @@ #include // Firmware data for self-test -// Reference values based on firmware version; taken from 16.1.1 in spec. -// Version 1.0 +// Reference values based on firmware version +// Version 0.0 (0x90) +// Philips Semiconductors; Preliminary Specification Revision 2.0 - 01 August 2005; 16.1 Sefttest +const byte MFRC522_firmware_referenceV0_0[] PROGMEM = { + 0x00, 0x87, 0x98, 0x0f, 0x49, 0xFF, 0x07, 0x19, + 0xBF, 0x22, 0x30, 0x49, 0x59, 0x63, 0xAD, 0xCA, + 0x7F, 0xE3, 0x4E, 0x03, 0x5C, 0x4E, 0x49, 0x50, + 0x47, 0x9A, 0x37, 0x61, 0xE7, 0xE2, 0xC6, 0x2E, + 0x75, 0x5A, 0xED, 0x04, 0x3D, 0x02, 0x4B, 0x78, + 0x32, 0xFF, 0x58, 0x3B, 0x7C, 0xE9, 0x00, 0x94, + 0xB4, 0x4A, 0x59, 0x5B, 0xFD, 0xC9, 0x29, 0xDF, + 0x35, 0x96, 0x98, 0x9E, 0x4F, 0x30, 0x32, 0x8D +}; +// Version 1.0 (0x91) +// NXP Semiconductors; Rev. 3.8 - 17 September 2014; 16.1.1 Self test const byte MFRC522_firmware_referenceV1_0[] PROGMEM = { 0x00, 0xC6, 0x37, 0xD5, 0x32, 0xB7, 0x57, 0x5C, 0xC2, 0xD8, 0x7C, 0x4D, 0xD9, 0x70, 0xC7, 0x73, @@ -91,7 +104,8 @@ const byte MFRC522_firmware_referenceV1_0[] PROGMEM = { 0x1F, 0xA7, 0xF3, 0x53, 0x14, 0xDE, 0x7E, 0x02, 0xD9, 0x0F, 0xB5, 0x5E, 0x25, 0x1D, 0x29, 0x79 }; -// Version 2.0 +// Version 2.0 (0x92) +// NXP Semiconductors; Rev. 3.8 - 17 September 2014; 16.1.1 Self test const byte MFRC522_firmware_referenceV2_0[] PROGMEM = { 0x00, 0xEB, 0x66, 0xBA, 0x57, 0xBF, 0x23, 0x95, 0xD0, 0xE3, 0x0D, 0x3D, 0x27, 0x89, 0x5C, 0xDE, From 7da08d8fd8b6b0c40dc9b10cf6288ad8d77bf3fe Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Tue, 14 Apr 2015 02:16:36 +0200 Subject: [PATCH 4/7] add firmware version to ShowReaderDetails --- examples/firmware_check/firmware_check.ino | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/examples/firmware_check/firmware_check.ino b/examples/firmware_check/firmware_check.ino index 2bdf348..b774ffd 100644 --- a/examples/firmware_check/firmware_check.ino +++ b/examples/firmware_check/firmware_check.ino @@ -62,7 +62,9 @@ void ShowReaderDetails() { byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); Serial.print(F("Firmware Version: 0x")); Serial.print(v, HEX); - if (v == 0x91) + 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")); From a5efda7ab31fe9db3b84e5ee27c370cefd8b4bfd Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Fri, 4 Sep 2015 10:46:59 +0200 Subject: [PATCH 5/7] readme wrong pin at mega; fix #114 --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 48af024..3aa6397 100644 --- a/README.rst +++ b/README.rst @@ -28,11 +28,11 @@ The following table shows the typical pin layout used: +-----------+----------+-------------+---------+---------+---------------+-----------+--------+ | SPI SS | SDA [3]_ | 10 [2]_ | 53 [2]_ | D10 | 10 | 10 | 10 | +-----------+----------+-------------+---------+---------+---------------+-----------+--------+ -| SPI MOSI | MOSI | 11 / ICSP-4 | 52 | D11 | ICSP-4 | 16 | 11 | +| SPI MOSI | MOSI | 11 / ICSP-4 | 51 | D11 | ICSP-4 | 16 | 11 | +-----------+----------+-------------+---------+---------+---------------+-----------+--------+ -| SPI MISO | MISO | 12 / ICSP-1 | 51 | D12 | ICSP-1 | 14 | 12 | +| SPI MISO | MISO | 12 / ICSP-1 | 50 | D12 | ICSP-1 | 14 | 12 | +-----------+----------+-------------+---------+---------+---------------+-----------+--------+ -| SPI SCK | SCK | 13 / ICSP-3 | 50 | D13 | ICSP-3 | 15 | 13 | +| SPI SCK | SCK | 13 / ICSP-3 | 52 | D13 | ICSP-3 | 15 | 13 | +-----------+----------+-------------+---------+---------+---------------+-----------+--------+ .. [1] Configurable, typically defined as RST_PIN in sketch/program. From 7e9a17db4969e87e898d309143893cedc4b5268b Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Fri, 4 Sep 2015 11:32:43 +0200 Subject: [PATCH 6/7] upd library version for arduino lib manager --- library.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library.properties b/library.properties index 9b26c35..d223ed8 100644 --- a/library.properties +++ b/library.properties @@ -1,6 +1,6 @@ name=MFRC522 -#date as version -version=20150405 +#date as version - no leading zero +version=2015.9.4 author=GithubCommunity maintainer=miguelbalboa sentence=Arduino RFID Library for MFRC522 (SPI) From da578441885b37cfa4361f4079857dc0383663d9 Mon Sep 17 00:00:00 2001 From: Rotzbua Date: Fri, 4 Sep 2015 12:54:23 +0200 Subject: [PATCH 7/7] upd firmware_check example --- examples/firmware_check/firmware_check.ino | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples/firmware_check/firmware_check.ino b/examples/firmware_check/firmware_check.ino index b774ffd..b923074 100644 --- a/examples/firmware_check/firmware_check.ino +++ b/examples/firmware_check/firmware_check.ino @@ -1,4 +1,6 @@ /* + * ---------------------------------------------------------------------------- + * 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. @@ -7,8 +9,6 @@ * documented in MFRC522.cpp. Please read it. * * Released into the public domain. - * ---------------------------------------------------------------------------- - * Example sketch/program showing how to test your firmware. * * Typical pin layout used: * ----------------------------------------------------------------------------------------- @@ -21,6 +21,8 @@ * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 + * + * @author Rotzbua */ #include @@ -40,7 +42,7 @@ void setup() { Serial.println(F("*****************************")); Serial.println(F("MFRC522 Digital self test")); Serial.println(F("*****************************")); - ShowReaderDetails(); // Show details of PCD - MFRC522 Card Reader details + ShowReaderVersion(); // Show version of PCD - MFRC522 Card Reader Serial.println(F("Performing test...")); bool result = mfrc522.PCD_PerformSelfTest(); Serial.println(F("-----------------------------")); @@ -48,7 +50,7 @@ void setup() { if (result) Serial.println(F("OK")); else - Serial.println(F("defect or unknown")); + Serial.println(F("DEFECT or UNKNOWN")); Serial.println(); } @@ -57,12 +59,14 @@ void loop() {} // nothing to do /** * Helper to print MFRC522 module info */ -void ShowReaderDetails() { +void ShowReaderVersion() { // Get the MFRC522 firmware version byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg); Serial.print(F("Firmware Version: 0x")); Serial.print(v, HEX); - if (v == 0x90) + 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"));