Use Seeeduino Arch (or Arch Pro) + NFC Shield to write a Mifare Classic tag
Dependencies: PN532 USBDevice mbed
Diff: main.cpp
- Revision:
- 0:b81d113f3a83
- Child:
- 1:c5b5be0d6c5d
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Tue Oct 08 08:58:32 2013 +0000 @@ -0,0 +1,55 @@ +#include "mbed.h" +#include "PN532.h" +#include "USBSerial.h" + +// PN532(mosi, miso, clk, cs) +PN532 nfc(P1_22, P1_21, P1_20, P0_2); + +DigitalOut myled(LED1); + +USBSerial pc; + +int main() { + + nfc.begin(); + uint32_t versiondata = nfc.getFirmwareVersion(); + if (! versiondata) { + pc.printf("Didn't find PN532\r\n"); + while (1) { + myled = !myled; + 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); + + nfc.SAMConfig(); + + + while(1) { + bool success; + uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 }; // Buffer to store the returned UID + uint8_t uidLength; // Length of the UID (4 or 7 bytes depending on ISO14443A card type) + + // Wait for an ISO14443A type cards (Mifare, etc.). When one is found + // 'uid' will be populated with the UID, and uidLength will indicate + // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight) + 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); + for (uint8_t i=0; i < uidLength; i++) { + pc.printf("0x%X ", uid[i]); + } + + wait(1); + myled = 0; + } else { + pc.printf("Time out\r\n"); + wait(1); + } + } +}