nRF5 SDK is not maintained anymore
More Info: Consider nRF Connect SDK for new designs

nRF52832 + PN532 Write

Hi,

    I am testing NFC read/ write examples . in nRF 5 SDK 17.1.0

I am trying to write the tag using PN532 using the adafruit tag reader example but i receive error like invalid length.

DEVICE 1 adafruit_tag_reader with PN532

DEVICE 2 is writable_ndef_msg .

using Device 1 i can able to read url of the device 2

i want to overwrite the url data from the PN532 device

Simply i am trying to write the NFC tag using PN532 .

ret_code_t t4t_data_read_and_analyze(nfc_a_tag_info * p_tag_info)
{
    ret_code_t err_code;

    // Static declaration of Type 4 Tag structure.
    NFC_T4T_CC_DESC_DEF(cc_file, MAX_TLV_BLOCKS);
    static uint8_t ndef_files_buffs[MAX_TLV_BLOCKS][TAG_TYPE_4_NDEF_FILE_SIZE];

    err_code = nfc_t4t_ndef_tag_app_select();
    T4T_ERROR_HANDLE(err_code, "Error (0x%X) during NDEF Tag Application Select Procedure.");

    err_code = nfc_t4t_cc_select();
    T4T_ERROR_HANDLE(err_code, "Error (0x%X) during CC Select Procedure.");

    nfc_t4t_capability_container_t * cc_file = &NFC_T4T_CC_DESC(cc_file);
    err_code = nfc_t4t_cc_read(cc_file);
    T4T_ERROR_HANDLE(err_code, "Error (0x%X) during CC Read Procedure.");

    nfc_t4t_tlv_block_t * p_tlv_block = cc_file->p_tlv_block_array;
    uint32_t              i;

    for (i = 0; i < cc_file->tlv_count; i++)
    {
        if ((p_tlv_block->type == NDEF_FILE_CONTROL_TLV) ||
            (p_tlv_block->value.read_access == CONTROL_FILE_READ_ACCESS_GRANTED))
        {
            err_code = nfc_t4t_file_select(p_tlv_block->value.file_id);
            T4T_ERROR_HANDLE(err_code, "Error (0x%X) during NDEF Select Procedure.");

            err_code = nfc_t4t_ndef_read(cc_file, ndef_files_buffs[i], TAG_TYPE_4_NDEF_FILE_SIZE);
            T4T_ERROR_HANDLE(err_code, "Error (0x%X) during NDEF Read Procedure.");  
            NRF_LOG_FLUSH();
        p_tlv_block++;
    }

    nfc_t4t_cc_file_printout(cc_file);

    p_tlv_block = cc_file->p_tlv_block_array;

    for (i = 0; i < cc_file->tlv_count; i++)
    {
        if ((p_tlv_block->type == NDEF_FILE_CONTROL_TLV) ||
            (p_tlv_block->value.file.p_content != NULL))
        {
            ndef_data_analyze(p_tlv_block->value.file.p_content + TAG_TYPE_4_NLEN_FIELD_SIZE,
                              p_tlv_block->value.file.len - TAG_TYPE_4_NLEN_FIELD_SIZE);
        }

        p_tlv_block++;
    }
     /* Encode URI message into buffer */
    err_code = nfc_uri_msg_encode( NFC_URI_HTTP_WWW,
                                   m_url,
                                   sizeof(m_url),
                                   m_ndef_msg_buf,
                                   &len);

    APP_ERROR_CHECK(err_code);

    err_code = nfc_t4t_ndef_update(cc_file, m_ndef_msg_buf,len);
    T4T_ERROR_HANDLE(err_code, "Error (0x%X) during NDEF Update Procedure.");  
    
    return NRF_SUCCESS;
}

<info> app: NFC Adafruit tag reader example started.
<info> app: Type 4 Tag Platform detected. 
<info> nfc_t4t_hl_detection_procedures: NDEF Tag Application Select Procedure 
<info> nfc_t4t_apdu: R-APDU status: 9000 
<info> nfc_t4t_apdu: R-APDU no data field present.

<info> nfc_t4t_hl_detection_procedures: Capability Container Select Procedure 
<info> nfc_t4t_apdu: R-APDU status: 9000 
<info> nfc_t4t_apdu: R-APDU no data field present.

<info> nfc_t4t_hl_detection_procedures: Capability Container Read Procedure 
<info> nfc_t4t_apdu: R-APDU status: 9000 
<info> nfc_t4t_apdu: R-APDU data: 
<info> nfc_t4t_apdu:  00 0F 20 00 F8 00 F8 04|.. .....
<info> nfc_t4t_apdu:  06 E1 04 04 00 00 00   |....... 

<info> nfc_t4t_hl_detection_procedures: File (ID = E104) Select Procedure 
<info> nfc_t4t_apdu: R-APDU status: 9000 
<info> nfc_t4t_apdu: R-APDU no data field present.

<info> nfc_t4t_hl_detection_procedures: NDEF Read Procedure 
<info> nfc_t4t_apdu: R-APDU status: 9000 
<info> nfc_t4t_apdu: R-APDU data: 
<info> nfc_t4t_apdu:  00 16                  |..      
<info> nfc_t4t_apdu: R-APDU status: 9000 
<info> nfc_t4t_apdu: R-APDU data: 
<info> nfc_t4t_apdu:  C1 01 00 00 00 0F 55 01|......U.
<info> nfc_t4t_apdu:  6E 6F 72 64 69 63 73 65|nordicse
<info> nfc_t4t_apdu:  6D 69 2E 63 6F 6D      |mi.com  

<info> nfc_t4t_cc_file_parser: Capability Container File content: 
<info> nfc_t4t_cc_file_parser: CCLEN: 15 
<info> nfc_t4t_cc_file_parser: Mapping Version: 2.0 
<info> nfc_t4t_cc_file_parser: MLe: 248 
<info> nfc_t4t_cc_file_parser: MLc: 248 
<info> nfc_t4t_cc_file_parser: Capability Container File contains 1 File Control TLV block(s).
<info> nfc_t4t_tlv_block_parser: 0 file Control TLV
<info> nfc_t4t_tlv_block_parser: Type: NDEF File Control (0x04)
<info> nfc_t4t_tlv_block_parser: Length (in bytes): 6
<info> nfc_t4t_tlv_block_parser: File Identifier: 0xE104 
<info> nfc_t4t_tlv_block_parser: Maximum file size: 1024 
<info> nfc_t4t_tlv_block_parser: Read access condition: 0x00 
<info> nfc_t4t_tlv_block_parser: Write access condition: 0x00 
<info> nfc_t4t_tlv_block_parser: NDEF file content present. Length: 24 
<info> nfc_t4t_tlv_block_parser:  00 16 C1 01 00 00 00 0F|........
<info> nfc_t4t_tlv_block_parser:  55 01 6E 6F 72 64 69 63|U.nordic
<info> nfc_t4t_tlv_block_parser:  73 65 6D 69 2E 63 6F 6D|semi.com
<info> nfc_ndef_msg_parser: NDEF message contains 1 record(s)
<info> nfc_ndef_parser: NDEF record 0 content:
<info> nfc_ndef_parser: TNF: NFC Forum well-known type
<info> nfc_ndef_parser: type:
<info> nfc_ndef_parser:  55                     |U       
<info> nfc_ndef_parser: Payload length: 15 bytes
<info> nfc_t4t_hl_detection_procedures: NDEF Update Procedure 
<info> app: Error (0x9) during NDEF Update Procedure.
<info> app: Error during tag read.

Error is

<info> nfc_t4t_hl_detection_procedures: NDEF Update Procedure
<info> app: Error (0x9) during NDEF Update Procedure.
<info> app: Error during tag read.

Error 0x09 - says invalid length

How to update the nDEF.

Related