I can't write to the NFC tag.

Hello,

I'm using NFC Type 4 Tag (T4T) but I can't write to it. The tool I'm using is the nRF NFC Toolbox. From the app screen I generate a Record and then touch the tag to attempt a write,

but only "tag discovered" appears and no message indicating success is shown.

After a bit of investigation, the issue seems to occur after the tag side generates an NDEF message. Below is the source code that generates the message and record.

void binary_encode(uint8_t *buffer, uint32_t *len)
{
	uint8_t data[6] = {0x00,0x01, 0x02, 0x03, 0x04, 0x05};
	uint8_t id[2] = {0x00, 0x00};
	int err;

	NFC_NDEF_MSG_DEF(nfc_test_msg, 1);

	NFC_NDEF_RECORD_BIN_DATA_DEF(nfc_tset_record,				
				     TNF_EXTERNAL_TYPE,
				     id,
				     2,	
				     NULL,
				     0,
				     data,
				     sizeof(data));

	err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_test_msg),
						&NFC_NDEF_RECORD_BIN_DATA(nfc_tset_record));

	if (err) {
		printk("Cannot add record!\n");
	}
	
	/* Encode whole message into buffer */
	err = nfc_ndef_msg_encode(&NFC_NDEF_MSG(nfc_test_msg),
				       buffer,
				       len);
	if (err) {
		printk("Cannot encode message!\n");
	}

	err = nfc_t4t_ndef_file_encode(buffer, len);
	if (err) {
		printk("Cannot encode file!\n");
	}
}


In this source code I'm creating binary data as an NDEF message with the Type Name Format set to "External Type".
However, if I comment out the final nfc_ndef_msg_encode and nfc_t4t_ndef_file_encode calls, I can write using the app — the app shows "Tag written successfully". I understand those functions set the NDEF message into the buffer. Once the message is set, is it no longer possible to write?

Also, I confirmed that if I use a different Type Name Format instead of External Type, writing works normally. Below is the source code.

int welcome_msg_encode(uint8_t *buffer, uint32_t *len)
{
	int err;

	/* Create NFC NDEF text record description in English */
	NFC_NDEF_TEXT_RECORD_DESC_DEF(nfc_en_text_rec,
				      UTF_8,
				      en_code,
				      sizeof(en_code),
				      en_payload,
				      sizeof(en_payload));

	/* Create NFC NDEF message description, capacity - MAX_REC_COUNT
	 * records
	 */
	NFC_NDEF_MSG_DEF(nfc_text_msg, MAX_REC_COUNT);

	/* Add text records to NDEF text message */
	err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_text_msg),
				   &NFC_NDEF_TEXT_RECORD_DESC(nfc_en_text_rec));
	if (err < 0) {
		printk("Cannot add first record!\n");
		return err;
	}

	err = nfc_ndef_msg_encode(&NFC_NDEF_MSG(nfc_text_msg),
				      &buffer[2],
				      len);
	if (err < 0) {
		printk("Cannot encode message!\n");
	}

	err = nfc_t4t_ndef_file_encode(buffer, len);
	if (err) {
		return err;
	}
	return err;
}


The above uses the Well-known Type Name Format and generates text data as an NDEF message. I confirmed that with this, writing succeeds even if I do not comment out the encode calls.

I don’t understand why writing fails when the Type Name Format is External Type. Is there a restriction that prevents writing after an External Type message has been created? Also, could the app be imposing a restriction on External Type writes — I’d like to know if that’s possible.
If you notice any mistakes or issues in the source code above, please let me know.

cpu:nrf5340
zephyr:3.5.99
sdk 2.6.0
NFC:T4T
borard:nrf5340dk

best regards.

Parents Reply Children
No Data
Related