How do I access the nRF52840 NFC-A Tag interface

I have a Nano BLE and I wish to make use of the NFC-A Tag feature of the nRF52840.

The store page Arduino Nano 33 BLE makes mention of the feature “The main processor includes other amazing features like Bluetooth® pairing via NFC and ultra low power consumption modes.”

But it does not mention NFC in the tech specs.

The pinout diagram does not show the underside of the board but the PDF full pinout diagram does.

Here on the PDF it tells me that… “Making a short circuit using the solder jumper allows only the function in the SJ Pin cells and also it changes the Pad connection of the pins D7 and D8 in P0.09 and P0.10.”

Then what… I tried searching on the Arduino website and nothing comes up in terms of libraries, tips, advice etc. There is nothing on the getting started guide for the nano BLE board.

Is there any official or supported NFC Tag library that I can use?

Thanks

I am also wondering if I soldered my shielded wire leads from my NFC Tag antenna directly onto the solder pads on the underside of the board, I assume I can use P0.09 and P0.10 in my code (this would free up D7/D8). If I can do so what would be the naming convention etc. that would be suitable for an Arduino library.

I've been exploring this issue some more.

I went to Boards Manager and searched for "nRF52" devices.

I see there is an Arduino nRF52 Boards option (Arduino Primo).

When you download this board into the Arduino IDE, I see this offers an NFC library option as a core library for the Arduino Primo.

However, when I choose my Arduino Nano BLE 33 board this library is not shown. It does not even show up in the "Incompatible" option.

So, it sounds like most of the work has already been done, but the way the nRF52 boards and libraries are configured none of these show up for the new Nano BLE board.

I am now searching through the ArduinoCore-nRF528x github page and I see there is an implementation for NFC.

and this is included as part of the board download files:

C:....\AppData\Local\Arduino15\packages\arduino\hardware\mbed\1.1.4\cores\arduino\mbed\features\nfc

It looks to be quite different to the Primo core library. Is this not reinventing the wheel or was this by design.

Anyway, the key question is how does one use this in an application/project?

@gerrikoio has also asked about this on the arduino/ArduinoCore-nRF528x-mbedos repository's issue tracker:

gerrikoio:
I assume I can use P0.09 and P0.10 in my code (this would free up D7/D8). If I can do so what would be the naming convention etc. that would be suitable for an Arduino library.

These pins aren't defined as Arduino pins, so I think the only way to use them with Arduino IO functions would be to add those pins to the end of the g_APinDescription array in variant.cpp:

  P0_9,  NULL, NULL,     // D34
  P0_10, NULL, NULL,     // D35

The Arduino pin number is the index of the array, so they can now be accessed as Arduino pins 34 and 35.


You also have the option of using the Mbed OS API to control these pins, which does not require any modifications to the Arduino nRF528x Boards (Mbed OS) platform source code. Here's an example of blinking P0.09:

mbed::DigitalOut myled(P0_9);

void setup() {}

void loop() {
  myled.write(1);
  delay(1000);

  myled.write(0);
  delay(1000);
}

Information on the Mbed OS API here:
https://os.mbed.com/docs/mbed-os/v5.15/apis/digitalout.html

Thanks for the feedback regarding the use of P0.09 and P0.10. That's really promising especially with this use of mbed.... I think I will start by trying use the mbed nfc library to avail of the nfc functionality, so this fits quite nicely.

I also discovered that I can use the "using namespace mbed;" option to make my code easier to read etc.

Another confusing bit for me is whether I need to define the path for the various components of the mbed nfc library, such as the ndef part.

I am trying to use the NFC library and examples as provided with the Nordic nRF52 SDK (using version 15.0).

I am getting loads of warnings such as:
#warning No configuration for LF clock source. Xtal source will be used as a default configuration.

I have verbose compile setting on and so when it says “Linking everything together…”

I get an error saying that my code has this undefined reference to `nfc_t2t_setup’ - this function is found within nRF52 SDK - t2t_lib/nfc_t2t_lib.h which I have included in my library src folder. This has an associated assembler (precompiled) file. So for some reason it does not like the “nfc_t2t_lib_gcc.a” file.
My library header is:

#ifndef NRF52_NFC_h
#define NRF52_NFC_h

#include "Arduino.h"
#include <stdint.h>


#ifdef __cplusplus
extern "C" {
#endif

#include "t2t_lib/nfc_t2t_lib.h" 

#ifdef __cplusplus
}
#endif

#define MAX_REC_COUNT       3     /**< Maximum records count. */
#define NRF_ERROR_BASE_NUM   (0x0)
#define NRF_SUCCESS   (NRF_ERROR_BASE_NUM + 0)

class NFCClass{

public:

uint32_t start(void);


private:


};

extern NFCClass NFC;

#endif //NRF52_NFC

And the cpp file is:

#include "nRF52_NFC.h"


static void nfc_callback(void * p_context, nfc_t2t_event_t event, const uint8_t * p_data, size_t data_length) 
{
   (void)p_context;

   switch (event)
   {
       case NFC_T2T_EVENT_FIELD_ON:
           // can try turn led on
           break;
       case NFC_T2T_EVENT_FIELD_OFF:
           // can try turn led off
           break;
       default:
           break;
   }
}

uint32_t NFCClass::start(void)
{
uint32_t err_code = nfc_t2t_setup(nfc_callback, NULL);
return err_code;
}

NFCClass NFC;

My Arduino code is:

#include <nRF52_NFC.h>

void setup() { 
 // start the NFC module
 NFC.start();
}


void loop() {}

I’ve seen some libraries add additional settings to the “library.properties” file, such as a “precompile=true” and there other “make” files to resolve but this is too advanced for me.

Maybe someone can advise what to do.

I was looking at the Particle.io Argon/Xenon nRF52840 NFC code implementation. Their code works pretty well, so I know it doable but it does look rather involved.

Just to mention, I thought that the Particle.io code have implemented a great way of handling the callback event by inserting multiple callbacks for the different events. This allows you to create your own custom behaviour to any of the particular NFC standardised event attributes (as defined by nRF52840 library).

In my opinion, NFC code and examples should be part of the core NanoBLE library to avoid version control issues with the nRF52 SDK/library. In much the same way as Arduino did it for the old Primo board.