You are viewing an older revision! See the latest version
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.
[Not converted]
The only thing you have to configure is whether you want to use a RTOS or not.
If so, import it from here:
[Not converted]
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:
[Not converted]
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.
[Not converted]
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:
[Not converted]
