Use Seeeduino Arch (or Arch Pro) + NFC Shield to write a Mifare Classic tag
Dependencies: PN532 USBDevice mbed
Diff: main.cpp
- Revision:
- 1:c5b5be0d6c5d
- Parent:
- 0:b81d113f3a83
- Child:
- 2:56402cae2c3c
--- a/main.cpp Tue Oct 08 08:58:32 2013 +0000 +++ b/main.cpp Thu Oct 17 07:10:06 2013 +0000 @@ -1,28 +1,39 @@ #include "mbed.h" #include "PN532.h" + +#if 0 + +#define LOG(args...) + +#else #include "USBSerial.h" +#define LOG(args...) pc.printf(args) + +USBSerial pc; +#endif + // PN532(mosi, miso, clk, cs) PN532 nfc(P1_22, P1_21, P1_20, P0_2); -DigitalOut myled(LED1); +DigitalOut led1(LED1); -USBSerial pc; + int main() { nfc.begin(); uint32_t versiondata = nfc.getFirmwareVersion(); if (! versiondata) { - pc.printf("Didn't find PN532\r\n"); + LOG("Didn't find PN532\r\n"); while (1) { - myled = !myled; + led1 = !led1; wait(0.1); } } - pc.printf("Found chip PN5%2X\r\n", versiondata >> 24); - pc.printf("Firmware V%d.%d\r\n", (versiondata >> 16) & 0xFF, (versiondata >> 8) & 0xFF); + LOG("Found chip PN5%2X\r\n", versiondata >> 24); + LOG("Firmware V%d.%d\r\n", (versiondata >> 16) & 0xFF, (versiondata >> 8) & 0xFF); nfc.SAMConfig(); @@ -38,17 +49,17 @@ success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength); if (success) { - myled = 1; - pc.printf("Found a card\r\n"); - pc.printf("UID length: %d\r\nUID Value: ", uidLength); + led1 = 1; + LOG("Found a card\r\n"); + LOG("UID length: %d\r\nUID Value: ", uidLength); for (uint8_t i=0; i < uidLength; i++) { - pc.printf("0x%X ", uid[i]); + LOG("0x%X ", uid[i]); } wait(1); - myled = 0; + led1 = 0; } else { - pc.printf("Time out\r\n"); + LOG("Time out\r\n"); wait(1); } }