Mistake on this page?
Report an issue in GitHub or email us


NFCController class hierarchy

Using an NFC controller with Mbed OS allows you to emulate NFC tags that a smartphone can read, as well as generate NDEF messages on demand.

To use an NFC controller, you must initiate the instance with a driver instance, an event queue and a scratch buffer for NDEF messages.

NFCController class reference

Data Structures
struct  Delegate
 The NFCController delegate. More...
Public Member Functions
 NFCController (NFCControllerDriver *driver, events::EventQueue *queue, const Span< uint8_t > &ndef_buffer)
 Construct a NFCController instance. More...
nfc_err_t initialize ()
 Initialize the NFC controller. More...
void set_delegate (Delegate *delegate)
 Set the delegate that will receive events generated by this controller. More...
nfc_rf_protocols_bitmask_t get_supported_rf_protocols () const
 Get the list of RF protocols supported by this controller. More...
nfc_err_t configure_rf_protocols (nfc_rf_protocols_bitmask_t rf_protocols)
 Set the list of RF protocols to look for during discovery. More...
nfc_err_t start_discovery ()
 Start the discovery process using the protocols configured previously. More...
nfc_err_t cancel_discovery ()
 Cancel/stop a running discovery process. More...

NFCController example

#include "stdint.h"

#include "NFC.h"
#include "events/EventQueue.h"
#include "nfc/controllers/PN512Driver.h"
#include "nfc/controllers/PN512SPITransportDriver.h"

static uint8_t ndef_buffer[1024] = {0};

int main() {
    mbed::nfc::PN512SPITransportDriver pn512_transport(D11, D12, D13, D10, A1, A0);
    mbed::nfc::PN512Driver pn512_driver(&pn512_transport);
    events::EventQueue queue;
    mbed::nfc::NFCController nfc(&pn512_driver, &queue, ndef_buffer);


A delegate mechanism handles events throughout the API.

For instance, a delegate for a NFC controller can look similar to this:

struct NFCDelegate : mbed::nfc::NFCController::Delegate {
    virtual void on_discovery_terminated(nfc_discovery_terminated_reason_t reason) {
        printf("Discovery terminated:\r\n");
        if(reason != nfc_discovery_terminated_completed) {
            nfc_ptr->start_discovery(); // Error, restart discovery
    virtual void on_nfc_initiator_discovered(const SharedPtr< mbed::nfc::NFCRemoteInitiator> &nfc_initiator) {
        printf("Remote inititator detected\r\n");
        nfc_initiator->connect(); // Connect to the initiator
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.