Better implementation of the PCD_Init() method. Thanks to Rotzbua

to point this out.
This commit is contained in:
liviu
2015-12-05 10:50:34 +01:00
parent dd3bd76f5d
commit 118a03cde0
3 changed files with 146 additions and 168 deletions

View File

@@ -10,6 +10,9 @@
* This sample shows how to read and write data blocks on a MIFARE Classic PICC
* (= card/tag).
*
* BEWARE: Data will be written to the PICC, in sector #1 (blocks #4 to #7).
*
*
* Typical pin layout used:
* -----------------------------------------------------------------------------------------
* MFRC522 Arduino Arduino Arduino Arduino Arduino
@@ -17,7 +20,7 @@
* Signal Pin Pin Pin Pin Pin Pin
* -----------------------------------------------------------------------------------------
* RST/Reset RST 9 5 D9 RESET/ICSP-5 RST
* SPI SS 1 SDA(SS) 5 53 D10 10 10
* SPI SS 1 SDA(SS) 10 53 D10 10 10
* SPI SS 2 SDA(SS) 2 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
@@ -28,9 +31,9 @@
#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define RST_PIN 10 // Configurable, see typical pin layout above
#define SS_1_PIN 5 // Configurable, see typical pin layout above
#define SS_2_PIN 2 // Configurable, see typical pin layout above
#define SS_2_PIN 3 // Configurable, see typical pin layout above
#define NR_OF_READERS 2
@@ -38,12 +41,11 @@ byte ssPins[] = {SS_1_PIN, SS_2_PIN};
MFRC522 mfrc522[NR_OF_READERS]; // Create MFRC522 instance.
MFRC522::MIFARE_Key key;
/**
* Initialize.
*/
void setup() {
Serial.begin(115200); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
@@ -59,12 +61,14 @@ void setup() {
*/
void loop() {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
// Look for new cards
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
if (mfrc522[reader].PICC_IsNewCardPresent() && mfrc522[reader].PICC_ReadCardSerial()) {
Serial.print(F("Reader: "));
Serial.print(reader);
// Show some details of the PICC (that is: the tag/card)
Serial.print(F("Card UID:"));
Serial.print(F(" Card UID:"));
dump_byte_array(mfrc522[reader].uid.uidByte, mfrc522[reader].uid.size);
Serial.println();
Serial.print(F("PICC type: "));