Use Seeeduino Arch (or Arch Pro) + NFC Shield to write a Mifare Classic tag

Dependencies:   PN532 USBDevice mbed

main.cpp

Committer:
yihui
Date:
2013-11-21
Revision:
2:56402cae2c3c
Parent:
1:c5b5be0d6c5d
Child:
3:59afaef9fb24

File content as of revision 2:56402cae2c3c:

#include "mbed.h"
#include "PN532_SPI.h"
#include "NfcAdapter.h"

#define LOG(args...)        pc.printf(args)

#if 0                           // Using Seeeduino Arch
#include "USBSerial.h"
USBSerial pc;
SPI spi(P1_22, P1_21, P1_20);  // SPI(mosi, miso, clk)
PN532_SPI pn532spi(spi, P0_2)

#else                           // Using Arch Pro
Serial pc(USBTX, USBRX);
SPI spi(P0_18, P0_17, P0_15);
PN532_SPI pn532spi(spi, P0_6);
#endif

NfcAdapter nfc(pn532spi);
DigitalOut led(LED1);


int main() {
    nfc.begin();
    while (1) {
        if (nfc.tagPresent()) {
            NdefMessage message = NdefMessage();
            message.addUriRecord("http://seeedstudio.com");
    
            bool success = nfc.write(message);
            if (success) {
                LOG("Success. Try reading this tag with your phone.");        
            } else {
                LOG("Write failed.");
            }
        }
        wait(6);
    }
}