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

NFC Tag write : The text record payload size limitation ?

Hi,

   My project is based on SDK15.3 with NRF52840. I have referred to the "writable_ndef_msg" example to read/write the emulated NFC tag successfully. And I can get back the written text string using the below code:

case NFC_T4T_EVENT_NDEF_UPDATED:
	NRF_LOG_INFO("NFC Write %d", data_length);

	if(data_length>0)
	{
		uint32_t ret_val = ndef_msg_parser(read_nfc_buffer, &read_nfc_buffer_length, m_ndef_msg_buf+2, &data_length);
		if (ret_val != NRF_SUCCESS)
		{
			NRF_LOG_INFO("Nfc Error: 0x%x \r\n", ret_val);
			// NRF_LOG_INFO("Error during parsing a NDEF message.\r\n");
		}	
		else
		{
			nfc_ndef_msg_desc_t *p_msg_desc = (nfc_ndef_msg_desc_t *)read_nfc_buffer;
			for (int i = 0; i < p_msg_desc->record_count; i++)
			{
				// ndef_record_printout(i, p_msg_desc->pp_record[i]);
				nfc_ndef_record_desc_t *p_rec = p_msg_desc->pp_record[i];
				// NRF_LOG_INFO("Type=%02Xh", *(uint8_t *)p_rec->p_type);
				if (p_rec->payload_constructor == (p_payload_constructor_t) nfc_ndef_bin_payload_memcopy)
				{
					nfc_ndef_bin_payload_desc_t * p_bin_pay_desc = p_rec->p_payload_descriptor;
					if (p_bin_pay_desc->p_payload != NULL)
					{
						// NRF_LOG_INFO("Payload length: %d bytes", p_bin_pay_desc->payload_length);
						// NRF_LOG_HEXDUMP_INFO((uint8_t *)p_bin_pay_desc->p_payload, p_bin_pay_desc->payload_length);
						switch(p_bin_pay_desc->p_payload[0])
						{
							case 0x02:
								nfc_call_back(NFC_EV_WRITE_TEXT, (void *)&p_bin_pay_desc->p_payload[3], p_bin_pay_desc->payload_length-3);
								break;
							case 0x03:
								nfc_call_back(NFC_EV_WRITE_URI, (void *)&p_bin_pay_desc->p_payload[1], p_bin_pay_desc->payload_length-1);
								break;
							default:
								break;
						}
						
					}
					else
					{
						NRF_LOG_INFO("Nfc No payload");
					}
				}
			}
		}
		//--- Restore data length.
		read_nfc_buffer_length = sizeof(read_nfc_buffer);
	}
	break;

Here is some of my initial codes:

uint8_t  read_nfc_buffer[NFC_NDEF_PARSER_REQIRED_MEMO_SIZE_CALC(4)];
uint32_t read_nfc_buffer_length = sizeof(read_nfc_buffer);		

// ......

ret_code_t nfc_start()
{
    if(!nfcState.record_exist) return NRF_ERROR_INVALID_DATA;

    if(nfcState.enabled) return NRF_ERROR_INVALID_STATE;

    m_ndef_msg_buf_len = MAX_NDEF_BUF_LEN;

    NRF_LOG_INFO("msg len=%d", m_ndef_msg_buf_len);
    NRF_LOG_INFO("rec_cnt=%d", NFC_NDEF_MSG(m_ndef_msg).record_count);

    ret_code_t err_code = nfc_ndef_msg_encode(&NFC_NDEF_MSG(m_ndef_msg),
                                   m_ndef_msg_buf,
                                   &m_ndef_msg_buf_len);
    APP_ERROR_CHECK(err_code);
    
    NRF_LOG_INFO("remain buf sz=%d", m_ndef_msg_buf_len);
    
    // err_code = nfc_t2t_payload_set(m_ndef_msg_buf, m_ndef_msg_buf_len);
    err_code = nfc_t4t_ndef_rwpayload_set(m_ndef_msg_buf, m_ndef_msg_buf_len);
    APP_ERROR_CHECK(err_code);


    // err_code = nfc_t2t_emulation_start();
    err_code = nfc_t4t_emulation_start();
    APP_ERROR_CHECK(err_code);

    nfcState.enabled = true;

    NRF_LOG_FLUSH();

    return NRF_SUCCESS;
}

I use the Android APP "NFC Tools" to write the tag. When the tag content is less or equal to 56 characters(record size will be 63 bytes) , everything is just fine, write command is well executes. When tag content is larger the 57 characters, the NFC Tools report back that it's exceed the tag memory limitation. It's the same even I tried to use another APP.

Could someone help tell me where am I doing wrong ?

Related