The NXP NTAG I2C is a NFC Forum Type 2 tag equipped with an I2C interface which allows for communication with a host device. This article demonstrates how to configure the NTAG I2C, via the I2C interface, to display simple text and URL messages in the NFC data exchange format (NDEF) . These examples were kept fairly generic to ensure they can be easily applied to a wide variety of I2C enabled devices.
NTAG I2C Demo Board:
The NTAG I2C demo board consists of two separate sections connected by a 6 pin header. The first section consists of a NXP LPC812 32 bit Cortex M0+ microcontroller, PCT2075 temperature sensor, three pushbuttons, three LEDs and a 10-pin mini JTAG debug header. The second section consists of the NTAG I2C chip, specifically the NT3H1201, an antenna tuned for the 13.56 MHz band and a breadboard compatible connector that makes it easy to interface the NTAG I2C chip with other devices. Only the second section needs to be used to perform the examples, but feel free to use the other section as well if the LPC812 is your preferred microcontroller.
The demo board comes pre-programmed with a example program, so it might be worth your while to experiment with the board a little before diving in to the following examples. Additional information about the demo program can be found in the following NXP app note: AN11597
Writing to the Tag using the I2C Bus:
The NTAG I2C uses a standard I2C bus for communication and configuration. thus the only extra components needed are pull up resistors for the SDA and SCL lines. The tag supports both Standard (100Kbps) and Fast (400Kbps) mode operation.
Schematic for 100 Kbps operation
NTAG I2C Demo Board mounted in a breadboard.
Writing to the tag:
The memory of the NTAG I2C is divided into separate blocks, each of which contain 16 bytes. The user memory begins at block 0x01. The procedure to write to these blocks is as follows:
- The host sends a start condition to the tag.
- The host then sends the I2C address, (default is 0x55), with the R/W bit set to 0.
- The host then sends the number of the block to be written to and the tag responds with an acknowledgment.
- The host can then write data to the block and the tag will respond to each byte written with an acknowledgement. After each byte is written, the byte index in each block will be automatically incremented, allowing each write to access a new byte of memory.
- The transactions ends with the host sending a stop condition.
In addition to the steps above, there are also two other important points to note. First when writing to a block, it is necessary to write to every byte in the block or else the write will not commit. If you do not have enough data to fill the block, you can simply write zeros to the rest of the block. Second, when writing data to multiple blocks, it is necessary to send a stop condition after each block is finished and then restart I2C communication to access the next block. This process is shown in the URL and Multiple records examples below.
I would also highly recommend looking at the memory map of the NTAG I2C. which can be found on page 15 of its datasheet.
Take care when writing to block 0. It contains the both the tag's I2C address and capability container. NXP already pre-configured the capability container according to the NFC Forum Type 2 Specification, so there should be no reason to change it unless you want to utilize some sort of proprietary, non-NDEF format. You will not need to modify block zero in any of the examples.
Text Demo PseudoCode:
Ensure you do not accidentally modify block 0 as it contains both the I2C address and the capability container! If you do modify it, these examples will not work!
Testing the Text Demo Using NXP's TagInfo App:
If you have an Android smartphone, you can easily test the demo above using NXP's TagInfo App which can be downloaded from the Google play store. Once the app is installed, you can test the tag using the following procedure:
- Ensure that the NTAG I2C board is connected to your microcontroller as shown in the "Writing to the tag using the I2C Bus" section above.
- Write the NDEF data to the tag as shown in the pseudocode above. This can take several seconds, so make sure to wait a little while before you try to read from the tag.
- Open the TagInfo app on your smartphone and then touch the back of the phone against the antenna of the demo board.The phone should vibrate, indicating that the tag has been read.
- Immediately after the tag is read, the app should display the message below indicating that an NXP tag was detected and that the tag contains an NDEF record.
- Select the NDEF tab in the app, you should see this record below.
URL Demo PseudoCode:
Testing the URL Demo Using NXP's TagInfo App:
The URL example can be tested using the same procedure that was used to test the text record example. The NDEF record should look similar to the picture below:
Multiple Records Demo Pseudocode:
Testing the Multiple Records Demo Using NXP's TagInfo App:
As before, the procedure used to test the text example will also work for testing this example. The NDEF records should look similar to the following: