NFC: Writable NDEF Message

The Writable NDEF Message sample shows how to use the NFC tag to expose an NDEF message, which can be overwritten with any other NDEF message by an NFC device. It uses the NFC NDEF libraries.

Overview

When the sample starts, it initializes the NFC tag and loads the NDEF message from the file in flash memory. If the NDEF message file does not exist, a default message is generated: a URI message with a URI record containing the URL “nordicsemi.com”. The sample then sets up the NFC library for the Type 4 Tag platform, which uses the NDEF message and senses the external NFC field.

The library works in Read-Write emulation mode. In this mode, procedures for reading and updating an NDEF message are handled internally by the NFC library. Any changes to the NDEF message update the NDEF message file, which is stored in flash memory.

Requirements

  • One of the following development boards:

    • nRF5340 PDK board (PCA10095) - see Working with nRF5340

    • nRF52840 DK board (PCA10056)

    • nRF52 DK board (PCA10040)

  • Smartphone or tablet with NFC Tools application (or equivalent)

User interface

LED 1:

Indicates if an NFC field is present.

LED 2:

Indicates that the NDEF message was updated.

LED 4:

Indicates that the NDEF message was read.

Button 1:

Press during startup to restore the default NDEF message.

Building and running

This sample can be found under samples/nfc/writable_ndef_msg in the nRF Connect SDK folder structure.

See Building and programming a sample application for information about how to build and program the application.

Testing

After programming the sample to your board, test it by performing the following steps:

  1. Touch the NFC antenna with the smartphone or tablet and observe that LED 1 and LED 4 are lit.

  2. Observe that the smartphone/tablet tries to open the URL “http://www.nordicsemi.com” in a web browser.

  3. Use a proper application (for example, NFC Tools for Android) to overwrite the existing NDEF message with your own message.

  4. Power-cycle your board and touch the antenna again. Observe that the new message is displayed.

Dependencies

This sample uses the following nRF Connect SDK libraries:

In addition, it uses the Type 4 Tag library from nrfxlib:

The sample uses the following Zephyr libraries:

  • include/atomic.h

  • include/zephyr.h

  • include/device.h

  • include/nvs/nvs.h

  • GPIO Interface