munfc stack
µNFC Stack¶
This page will help you develop your first program using AppNearMe's µNFC stack.
First of all, be sure to get the proper hardware and wire it up to your mbed.
Importing and setting up the library¶
The mbed implementation of the µNFC stack is located here; import it in your program.
Import libraryAppNearMe_MuNFC_PN532
AppNearMe µNFC stack for the NXP PN532 chip License: You can use the stack free of charge to prototype with mbed; if you want to use the stack with your commercial product, get in touch!
The only thing you have to configure is whether you want to use a RTOS or not.
If so, import it from here:
Import librarymbed-rtos
Official mbed Real Time Operating System based on the RTX implementation of the CMSIS-RTOS API open standard.
In your project, create a file named MuNFCConfig.h.
In this file, create on of the following defines:
#define MUNFC_RTOS 1 //Use RTOS /* OR */ #define MUNFC_RTOS 0 //Do not use RTOS
Using the library¶
Include the libraries header file:
#include "MuNFC.h"
The main class that you will use is the MuNFC class:
Import libraryAppNearMe_MuNFC_PN532
Instantiate it:
MuNFC nfc("00000001aZSe2vF5", //Application hash 1, // Application version p11, // MOSI p12, // MISO p13, // SCK p19, // /CS p18 // /IRQ );
The stack provides some callbacks that you can register to interact with the mobile phone during a NFC transaction.
The encode callback will be called before transferring data from the mbed to the mobile phone. In this callback, you will have to populate a TLVList object that will appear as a JSON object in your mobile application.
The decode callback handles the reverse process: the JSON object generated by the mobile application appears as a TLVList object that you can decode.
Import libraryAppNearMe_MuNFC_PN532
Finally you can register the event callback to know when NFC transactions start/succeed/fail.
At this point, you can initialize the stack.
bool ret = nfc.init(); if(ret) { printf("AppNearMe/MuNFC stack initialized\n"); } else { printf("Could not initialize stack\n"); }
Finally, depending on the fact that you are using a RTOS or not:
//RTOS nfc.run(); //Start thread //Your code goes next //No RTOS while(true) { nfc.poll(); //Your code here }
Please not that for now, the poll() method will only return at the end of a NFC transaction, so it is only suitable for simple applications. In the next version of the stack this will only block if there is a pending transaction.
Example program¶
This example program provides a good starting point to use the stack with an RTOS:
Import programAppNearMe_MuNFC_PN532_Test
Test of the µNFC stack with the Adafruit PN532 board