NFC: TNEP tag
The TNEP tag sample demonstrates how to use the TNEP for tag device library to exchange data using NFC’s TNEP Protocol on an NFC Tag device.
Requirements
The sample supports the following development kits:
Hardware platforms |
PCA |
Board name |
Board target |
---|---|---|---|
PCA10156 |
|
||
nRF54L15 DK |
PCA10156 |
|
|
PCA10175 |
|
||
PCA10095 |
|
||
PCA10040 |
|
||
PCA10056 |
|
When built for a board target with the */ns
variant, the sample is configured to compile and run as a non-secure application with Cortex-M Security Extensions enabled.
Therefore, it automatically includes Trusted Firmware-M that prepares the required peripherals and secure services to be available for the application.
Overview
The sample uses the Type 4 Tag as the tag transport layer. It creates the initial NDEF message that contains the Services Parameter records and the NDEF records.
If the NFC polling device does not support the TNEP library, it can interact with the NDEF records. If the poller supports the TNEP library, it can select the TNEP Service and exchange data with it.
Every TNEP Tag service has a callback structure that provides information to the application about Service State changes. The sample has two TNEP services defined, each of them containing the NDEF text records.
User interface
- LED 1:
Lit when the TNEP Tag is initialized.
- LED 3:
Lit when the TNEP service one is selected.
- LED 4:
Lit when the TNEP service two is selected.
- Button 1:
Press to provide the application data when the application service two is selected.
- LED 0:
Lit when the TNEP Tag is initialized.
- LED 2:
Lit when the TNEP service one is selected.
- LED 3:
Lit when the TNEP service two is selected.
- Button 0:
Press to provide the application data when the application service two is selected.
Building and running
This sample can be found under samples/nfc/tnep_tag
in the nRF Connect SDK folder structure.
When built as firmware image for a board target with the */ns
variant, the sample has Cortex-M Security Extensions (CMSE) enabled and separates the firmware between Non-Secure Processing Environment (NSPE) and Secure Processing Environment (SPE).
Because of this, it automatically includes the Trusted Firmware-M (TF-M).
To read more about CMSE, see Processing environments.
To build the sample, follow the instructions in Building an application for your preferred building environment. See also Programming an application for programming steps and Testing and optimization for general information about testing and debugging in the nRF Connect SDK.
Note
When building repository applications in the SDK repositories, building with sysbuild is enabled by default.
If you work with out-of-tree freestanding applications, you need to manually pass the --sysbuild
parameter to every build command or configure west to always use it.
Note
If you are using debug messages in the NFCT driver, the driver might not be working properly if you have CONFIG_LOG_MODE_IMMEDIATE
enabled.
The NFCT driver is part of the nrfx driver package.
For more information about this driver, see the NFCT driver page in the nrfx repository.
Testing
After programming the sample to your development kit, you can test it with an NFC-A polling device that supports NFC’s Tag NDEF Exchange Protocol. Complete the following steps:
Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Reset the development kit.
Touch the NFC antenna with the NFC polling device.
Observe the output in the terminal.
If the NFC polling device selects the service two, you have 27 seconds to press Button 1 to provide application data. If you do not do this, the NFC polling device deselects the service.
Connect to the kit with a terminal emulator (for example, nRF Connect Serial Terminal). See Testing and optimization for the required settings and steps.
Reset the development kit.
Touch the NFC antenna with the NFC polling device.
Observe the output in the terminal.
If the NFC polling device selects the service two, you have 27 seconds to press Button 0 to provide application data. If you do not do this, the NFC polling device deselects the service.
Dependencies
This sample uses the following nRF Connect SDK libraries:
In addition, it uses the following Zephyr libraries:
include/sys/until.h
The sample also uses the following secure firmware component: