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

Type 4 tag NDEF record update

Hello,

i am working with SDK 14 type 4 tag library on NRF52832 hardware. I've based my code on the example "writable ndef msg".

When receiving a record, the NFC handler assumes, that NLEN is first updated to 0, and, after the write is complete, it is updated to the length of the write:

        if (dataLength == 0)
        {
            m_update_state = true;
        }
        else if (m_update_state)
        {
            ret_code_t err_code;
            m_update_state = false;
            bsp_board_led_on(BSP_BOARD_LED_1);

            // Update FLASH NDEF message file with new message.
            err_code = ndef_file_update(m_ndef_msg_buf, dataLength + NLEN_FIELD_SIZE);
            APP_ERROR_CHECK(err_code);
            NRF_LOG_DEBUG("NDEF message updated!");
        }

I've tested this using the Android NDEF library with Samsung J5, and it works as the example expects. When testing with Nokia 3, the NDEF library writes the NLEN only once, leaving out the 0 length update. The code is identical, comprising connecting the NDEF object, performing a writeNdefMessage, and closing the NDEF object. The 0 length update happens somewhere inside the NDEF layer.

What could be the cause for this? How did you come up with this sequence when creating the NDEF example?

What is your recommended solution for solving this issue? One option would be to accept both ways, i.e. check the contents right away if the length is not 0, but this seemed a little unstable when i ran multiple writes. If a solution, which can e.g. make the tag indentify differently, and consequently make the Nokia NDEF message write work like the one with Samsung, i would opt for it.

BR, tommi

  • According to the specification, NDEF Update procedure usually consists of several NDEF update commands. The first one should set the NLEN field to 0, then the following commands should update NDEF message data field and the last update command should set the NLEN field to the new value that is equal to the size of NDEF message. In this case, the NFC_T4T_EVENT_NDEF_UPDATED event appears twice (for each update of NLEN field).

    However, it is possible to use single NDEF update command if the NLEN field and the NDEF message field fit inside the data field of the NDEF Update command. In this case, the NFC_T4T_EVENT_NDEF_UPDATED event appears only once.

    So your idea of accepting these two different types of NDEF update should be enough. Here is the code sample

    case NFC_T4T_EVENT_NDEF_UPDATED:
        if (dataLength > 0)
        {
            ret_code_t err_code;
    
            bsp_board_led_on(BSP_BOARD_LED_1);
    
            // Schedule update of NDEF message in the flash file.
            err_code = ndef_file_update(m_ndef_msg_buf, dataLength + NLEN_FIELD_SIZE);
            APP_ERROR_CHECK(err_code);
        }
    break;
    
  • Thank you for your answer!

    However, it is possible to use single NDEF update command if the NLEN field and the NDEF message field fit inside the data field of the NDEF Update command. In this case, the NFC_T4T_EVENT_NDEF_UPDATED event appears only once.

    This actually explains everything.

    BR, tommi

Related