Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of readMifare by
Revision 4:70acff42d8b4, committed 2016-03-16
- Comitter:
- mjovanov1
- Date:
- Wed Mar 16 20:05:34 2016 +0000
- Parent:
- 3:08251c301e26
- Child:
- 5:4b238fd5f347
- Commit message:
- blalaa
Changed in this revision
| PN532/Adafruit_PN532.cpp | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/PN532/Adafruit_PN532.cpp Wed Mar 16 09:52:22 2016 +0000
+++ b/PN532/Adafruit_PN532.cpp Wed Mar 16 20:05:34 2016 +0000
@@ -536,7 +536,9 @@
#ifdef MIFAREDEBUG
SERIAL_PRINT("Trying to authenticate card ");
Adafruit_PN532::PrintHex(_uid, _uidLen);
- SERIAL_PRINT("Using authentication KEY ");SERIAL_PRINT(keyNumber ? 'B' : 'A');SERIAL_PRINT(": ");
+ SERIAL_PRINT("Using authentication KEY ");
+ SERIAL_PRINT(keyNumber ? "B" : "A");
+ SERIAL_PRINT(": ");
Adafruit_PN532::PrintHex(_key, 6);
#endif
@@ -550,6 +552,10 @@
{
pn532_packetbuffer[10+i] = _uid[i]; /* 4 uint8_t card ID */
}
+
+ printf("Auth request:\r\n");
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 10+_uidLen);
+ printf("\r\n");
if (! sendCommandCheckAck(pn532_packetbuffer, 10+_uidLen))
return 0;
@@ -563,11 +569,12 @@
{
#ifdef PN532DEBUG
SERIAL_PRINT("Authentification failed: ");
- Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 12);
#endif
return 0;
}
-
+ printf("Auth response:\r\n");
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer, 20);
+ printf("\r\n");
return 1;
}
@@ -593,10 +600,14 @@
/* Prepare the command */
uint8_t pn532_packetbuffer2[PN532_PACKBUFFSIZ];
- pn532_packetbuffer2[0] = PN532_COMMAND_INDATAEXCHANGE;
+ pn532_packetbuffer2[0] = PN532_COMMAND_INDATAEXCHANGE; /* 0x40 */
pn532_packetbuffer2[1] = 1; /* Card number */
pn532_packetbuffer2[2] = MIFARE_CMD_READ; /* Mifare Read command = 0x30 */
pn532_packetbuffer2[3] = blockNumber; /* Block Number (0..63 for 1K, 0..255 for 4K) */
+
+ printf("Read request:\r\n");
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer2, 4);
+ printf("\r\n");
/* Send the command */
if (! sendCommandCheckAck(pn532_packetbuffer2, 4))
@@ -624,12 +635,10 @@
/* Block content starts at uint8_t 9 of a valid response */
memcpy (data, pn532_packetbuffer2+8, 16);
- /* Display data for debug if requested */
- #ifdef MIFAREDEBUG
- SERIAL_PRINT("Block ");
- SERIAL_PRINTln(blockNumber);
- Adafruit_PN532::PrintHexChar(data, 16);
- #endif
+
+ printf("Read response:\r\n");
+ Adafruit_PN532::PrintHexChar(pn532_packetbuffer2, 24);
+ printf("\r\n");
return 1;
}
--- a/main.cpp Wed Mar 16 09:52:22 2016 +0000
+++ b/main.cpp Wed Mar 16 20:05:34 2016 +0000
@@ -40,10 +40,10 @@
#include "mbed.h"
#include "Adafruit_PN532.h"
-#define MOSI p5
-#define MISO p6
-#define SCK p7
-#define SS p8
+#define MOSI p11
+#define MISO p12
+#define SCK p13
+#define SS p20
Serial pc(USBTX, USBRX);
Adafruit_PN532 nfc(SCK, MISO, MOSI, SS);
@@ -105,12 +105,11 @@
// Try with the factory default KeyA: 0xFF 0xFF 0xFF 0xFF 0xFF 0xFF
pc.printf("Trying to authenticate block 4 with default KEYA value\r\n");
uint8_t keya[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 };
- int block = 128;
// Start with block 4 (the first block of sector 1) since sector 0
// contains the manufacturer data and it's probably better just
// to leave it alone unless you know what you're doing
- success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, block, 0, keya);
+ success = nfc.mifareclassic_AuthenticateBlock(uid, uidLength, 128, 0, keya);
if (success)
{
@@ -118,15 +117,17 @@
int respSize = 16;
uint8_t data[respSize];
- success = nfc.mifareclassic_ReadDataBlock(block, data);
+ success = nfc.mifareclassic_ReadDataBlock(128, data);
if (success)
{
// Data seems to have been read ... spit it out
- pc.printf("Reading Block %d:\r\n\t", block);
+ pc.printf("Reading Block %d:\r\n\t", 128);
nfc.PrintHexChar(data, respSize);
pc.printf("\r\n");
+
+
// Wait a bit before reading the card again
wait(1);
}
