Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ljos/MFRC522
Browse files Browse the repository at this point in the history
  • Loading branch information
ljos committed Jan 30, 2014
2 parents a08867a + 93d9b16 commit 8c9ae19
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 11 deletions.
64 changes: 64 additions & 0 deletions MFRC522.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,70 @@ byte MFRC522::getFirmwareVersion() {
return response;
}

/**************************************************************************/
/*!
@brief Runs the digital self test.
@returns True if the self test passes, false otherwise.
*/
/**************************************************************************/
boolean MFRC522::digitalSelfTestPass() {
int i;
byte n;

byte selfTestResultV1[] = {0x00, 0xC6, 0x37, 0xD5, 0x32, 0xB7, 0x57, 0x5C,
0xC2, 0xD8, 0x7C, 0x4D, 0xD9, 0x70, 0xC7, 0x73,
0x10, 0xE6, 0xD2, 0xAA, 0x5E, 0xA1, 0x3E, 0x5A,
0x14, 0xAF, 0x30, 0x61, 0xC9, 0x70, 0xDB, 0x2E,
0x64, 0x22, 0x72, 0xB5, 0xBD, 0x65, 0xF4, 0xEC,
0x22, 0xBC, 0xD3, 0x72, 0x35, 0xCD, 0xAA, 0x41,
0x1F, 0xA7, 0xF3, 0x53, 0x14, 0xDE, 0x7E, 0x02,
0xD9, 0x0F, 0xB5, 0x5E, 0x25, 0x1D, 0x29, 0x79};
byte selfTestResultV2[] = {0x00, 0xEB, 0x66, 0xBA, 0x57, 0xBF, 0x23, 0x95,
0xD0, 0xE3, 0x0D, 0x3D, 0x27, 0x89, 0x5C, 0xDE,
0x9D, 0x3B, 0xA7, 0x00, 0x21, 0x5B, 0x89, 0x82,
0x51, 0x3A, 0xEB, 0x02, 0x0C, 0xA5, 0x00, 0x49,
0x7C, 0x84, 0x4D, 0xB3, 0xCC, 0xD2, 0x1B, 0x81,
0x5D, 0x48, 0x76, 0xD5, 0x71, 0x61, 0x21, 0xA9,
0x86, 0x96, 0x83, 0x38, 0xCF, 0x9D, 0x5B, 0x6D,
0xDC, 0x15, 0xBA, 0x3E, 0x7D, 0x95, 0x3B, 0x2F};
byte *selfTestResult;
switch(getFirmwareVersion()) {
case 0x91 :
selfTestResult = selfTestResultV1;
break;
case 0x92 :
selfTestResult = selfTestResultV2;
break;
default:
return false;
}

reset();
writeToRegister(FIFODataReg, 0x00);
writeToRegister(CommandReg, MFRC522_MEM);
writeToRegister(AutoTestReg, 0x09);
writeToRegister(FIFODataReg, 0x00);
writeToRegister(CommandReg, MFRC522_CALCCRC);

// Wait for the self test to complete.
i = 0xFF;
do {
n = readFromRegister(DivIrqReg);
i--;
} while ((i != 0) && !(n & 0x04));

for (i=0; i < 64; i++) {
if (readFromRegister(FIFODataReg) != selfTestResult[i]) {
Serial.println(i);
return false;
}
}
return true;
}

/**************************************************************************/
/*!
Expand Down
1 change: 1 addition & 0 deletions MFRC522.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ class MFRC522 {
void begin();
void reset();
byte getFirmwareVersion();
boolean digitalSelfTestPass();
int commandTag(byte command, byte *data, int dlen, byte *result, int *rlen);
int requestTag(byte mode, byte *type);
int antiCollision(byte *serial);
Expand Down
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@ Arduino RFID Library for MFRC522 (13.56 Mhz)
Pin order, starting from the bottom left hand pin (in case your
MFRC522 doesn't have pin markings like the B2CQSHOP one):

| Pins | SPI | UNO | Mega2560 |
| ---- |:--------:| ----:| --------:|
| 1 | SAD (SS) | 10 | 53 |
| 2 | SCK | 13 | 52 |
| 3 | MOSI | 11 | 51 |
| 4 | MISO | 12 | 50 |
| 5 | IRQ | `*` | `*` |
| 6 | GND | GND | GND |
| 7 | RST | 5 | ? |
| 8 | +3.3V | 3V3 | 3V3 |
`* Not needed`
| Pins | SPI | UNO | Mega2560 | Leonardo |
| ---- |:--------:|:----:|:--------:|:--------:|
| 1 | SAD (SS) | 10 | 53 | 10 |
| 2 | SCK | 13 | 52 | SCK`1` |
| 3 | MOSI | 11 | 51 | MOSI`1` |
| 4 | MISO | 12 | 50 | MISO`1` |
| 5 | IRQ | `*` | `*` | `*` |
| 6 | GND | GND | GND | GND |
| 7 | RST | 5 | ? | Reset |
| 8 | +3.3V | 3V3 | 3V3 | 3.3V |
`*` Not needed
`1` on ICPS header

Using MFRC522 with other SPI components
---------------------------------------
Expand Down
Binary file added documentation/MFRC522.pdf
Binary file not shown.
6 changes: 6 additions & 0 deletions examples/check_firmware/check_firmware.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@ void setup() {
Serial.print("Firmware ver. 0x");
Serial.print(version, HEX);
Serial.println(".");

if (nfc.digitalSelfTestPass()) {
Serial.print("Digital self test by MFRC522 passed.");
} else {
Serial.print("Digital self test by MFRC522 failed.");
}
}

void loop() {
Expand Down

0 comments on commit 8c9ae19

Please sign in to comment.