nRF5 SDK v15.3.0
Programming a tag

To program a tag, use the precompiled Type 2 Tag library.

Complete the following steps:

  1. Implement a callback function that handles events from the Type 2 Tag library and register it:
    uint32_t err_code;
    /* Callback for NFC events */
    static void nfc_callback(void * context, nfc_t2t_event_t event, const uint8_t * p_data, size_t data_length)
    {
    ...
    }
    /* Set up NFC and register application callback for NFC events. */
    err_code = nfc_t2t_setup(nfc_callback, NULL);
    APP_ERROR_CHECK(err_code);
    The NFCT interrupt handler runs at priority level APP_LOW.

  2. Configure the data for the tag. You can provide the data as NDEF message (recommended, see NFC Data Exchange Format) or as a raw TLV structure (advanced usage, see Type 2 Tag data format).
    • Set an NDEF message:
      uint8_t ndef_msg_buf[] = ...; // Buffer with the user NDEF message
      uint32_t len = sizeof(ndef_msg_buf);
      /* Set created message as the NFC payload. */
      err_code = nfc_t2t_payload_set(ndef_msg_buf, len);
      APP_ERROR_CHECK(err_code);
    • Alternatively, set a TLV structure:
      uint8_t tlv_buf[] = ...; // Buffer with the user TLV structure
      uint32_t len = sizeof(tlv_buf);
      /* Set created TLV structure as the NFC payload. */
      err_code = nfc_t2t_payload_raw_set(tlv_buf, len);
      APP_ERROR_CHECK(err_code);


  3. Activate the NFC tag so that it starts sensing and reacts when an NFC field is detected:
    /* Start sensing NFC field. */
    APP_ERROR_CHECK(err_code)

Documentation feedback | Developer Zone | Subscribe | Updated