This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

NFC_T4T_EVENT_NDEF_UPDATED gets fired twice per NFC Write?

It looks like NFC_T4T_EVENT_NDEF_UPDATED gets passed as the event attribute in the nfc_callback function whenever a new NDEF message is written.

Is this expected behavior? Is the first one fired when the write starts and the second one when the write ends? It looks like that's the case. datalength is 0 on the first NDEF_UPDATED event, and is a perfect match with the written data length on the second event.

For example, this is the code snippit I've been using, and every time I send something over NFC using my smartphone, the text "NDEF UPDATED fired!" shows up twice in RTT Viewer.

	static void nfc_callback(
  void          * context     __attribute__((unused)),
	nfc_t4t_event_t event       __attribute__((unused)),
	const uint8_t * data        __attribute__((unused)),
	size_t          dataLength  __attribute__((unused)),
	uint32_t        flags       __attribute__((unused)))
{
	switch (event)
	{
	case NFC_T4T_EVENT_NDEF_READ:
		break;
	case NFC_T4T_EVENT_NDEF_UPDATED:
                    SEGGER_RTT_printf(0, "NDEF UPDATED fired! Data length: 0x%02X\n", dataLength);
		break;
	default:
		break;
	}
  • Hi, please have a look at the comments under the NFC_T4T_EVENT_NDEF_UPDATED declaration in nrf_t4t_lib.h. I believe this should explain it:

    ///< External Reader has written to length information of NDEF-Data from Emulation.
    /**<
     * The usual behavior of a Reader-Writer that accesses NDEF information for update is to set
     * the length to zero at the beginning of the update process. It then writes the content
     * of NDEF-Data. When all content is written it will update the length information inside
     * the NDEF file. This event will be generated every time an update to  the length is happening.
     * This length information is residing in the first 2 bytes of the NDEF-Content container and is called 'NLEN'.
     * Since this callback is triggered on any access to these bytes  the returned data_length
     * information might not be consistent (e.g. in case of only a single byte write to the length).
     */
    
Related