The NFC Tag module emulates a basic NFC Forum Type 2 Tag with up to 1k of storage. The storage may be read and written by an NFC Reader as well as JS code.


Type 2 Tags support three commands, read, write and sector select (if the data area is larger than 1k). During read and write operations data is addressed in 4 byte blocks.

Most common Type 2 Tags have a dynamic memory structure. This structure defines the purpose of the first 16 bytes. Those are static and define the Tags type and configuration. In short: The first 10 bytes are a Unique ID and checksum. Those are followed by 16 lock bits. The final 4 bytes are a capability container.

This NFC Tag module initializes the first 10 bytes from NRF52's ROM area. The remaining 6 bytes followed by up to of 1008 bytes of data have to be initializes prior passing data into the module.


This example creates an empty 768-byte Tag. The table below describes the 9 initializer bytes used on the second line:

Index Value Explanation
0 0x00 Dynamic Lock Bits 0-7 (0x00 denotes no restriction)
1 0x00 Dynamic Lock Bits 8-15 (0x00 denotes no restriction)
2 0xE1 Magic number (Tag contains NFC Forum defined data)
3 0x10 Version (Major and Minor of nfc spec supported, v1.0)
4 0x60 Memory size (value multiplied by 8: 0x60 * 8 = 768 bytes)
5 0x00 Read and Write access (0x00 denotes no restriction)
6 0x03 Block contains an NDEF message
7 0x00 Empty NDEF Record
8 0xFE Last TLV block in the data area

It is writtable using almost any NFC Reader e.g. an Android phone (using NFC TagWriter by NXP) or an iPhone with iOS 13+ (using NFC Tools by wakdev)

var data = new Uint8Array(16+768);
data.set("\x00\x00\xE1\x10\x60\x00\x03\x00\xFE", 0x0A);
var tag = require("NFCTag").create(data);


/* For internal use - Receive Callback
NFCTag.prototype._rxCallBack = function (rx) { ... }

/* For internal use - Handle READ
NFCTag.prototype._read = function (rx) { ... }

/* For internal use - Handle WRITE
NFCTag.prototype._write = function (rx) { ... }

/* Set Tag contents
NFCTag.prototype.setData = function (data) { ... }

/* Retrieve tag contents as Uint8Array
NFCTag.prototype.getData = function () { ... }

/* Creates an NFCTag instance.
 * At most one NFCTag instance may
 * exist at any given time.
exports.create = function (data) { ... }

This page is auto-generated from GitHub. If you see any mistakes or have suggestions, please let us know.