Issue using NFC in nRF52832

Hello,

I am developing an NFC application using the nRF Connect SDK v2.6.0 and the nRF Toolchain v2.7.0. During development, I tested my application on the nRF52840 DevKit (built with the target nrf52840dk_nrf52840) and the nfc_callback function works as expected. However, when I switch to my final hardware—which uses the nRF52832 (building with the target nrf52dk_nrf52832)—I can still read the NFC tag, but the nfc_callback function is never called.

The codebase is essentially the same as the peripheral_hids_keyboard sample from the SDK, and the only difference is the target board selection. Below is the app_nfc.c file for reference. Are there any specific configurations or known differences on the nRF52832 that might prevent the callback from being triggered?

/*
 * Copyright (c) 2019 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
 */

#if CONFIG_NFC_OOB_PAIRING

#include "app_nfc.h"
#include <nfc_t2t_lib.h>

static struct bt_le_oob oob_local;
static uint8_t ndef_msg_buf[256]; /* Buffer used to hold an NFC NDEF message. */

void nfc_field_detected(void);
void nfc_field_lost(void);

static void nfc_callback(void *context,
			 nfc_t2t_event_t event,
			 const uint8_t *data,
			 size_t data_length)
{
	ARG_UNUSED(context);
	ARG_UNUSED(data);
	ARG_UNUSED(data_length);

	printk("\nNFC event: %d", event);

	switch (event) {
		case NFC_T2T_EVENT_FIELD_ON:
		case NFC_T2T_EVENT_DATA_READ:
			nfc_field_detected();
			break;
		case NFC_T2T_EVENT_FIELD_OFF:
			nfc_field_lost();
			break;
		default:
			break;
	}
}

int nfc_ndef_le_oob_msg_encode(uint8_t *buffer, uint32_t *len)
{
	int err;
	struct nfc_ndef_le_oob_rec_payload_desc rec_payload;

	err = bt_le_oob_get_local(BT_ID_DEFAULT, &oob_local);
	if (err) {
		printk("Error while fetching local OOB data: %d\n", err);
	}

	memset(&rec_payload, 0, sizeof(rec_payload));

	rec_payload.addr = &oob_local.addr;
	rec_payload.le_sc_data = &oob_local.le_sc_data;
	rec_payload.local_name = bt_get_name();
	rec_payload.le_role = NFC_NDEF_LE_OOB_REC_LE_ROLE(
		NFC_NDEF_LE_OOB_REC_LE_ROLE_PERIPH_ONLY);
	rec_payload.appearance = NFC_NDEF_LE_OOB_REC_APPEARANCE(
		CONFIG_BT_DEVICE_APPEARANCE);
	rec_payload.flags = NFC_NDEF_LE_OOB_REC_FLAGS(BT_LE_AD_NO_BREDR);

	/* Create NFC NDEF message description, capacity - 1 record */
	NFC_NDEF_MSG_DEF(nfc_le_oob_msg, 1);

	/* Create NFC NDEF LE OOB Record description without record ID field */
	NFC_NDEF_LE_OOB_RECORD_DESC_DEF(nfc_le_oob_rec, 0, &rec_payload);

	/* Add LE OOB Record as lone record to message */
	err = nfc_ndef_msg_record_add(&NFC_NDEF_MSG(nfc_le_oob_msg),
			&NFC_NDEF_LE_OOB_RECORD_DESC(nfc_le_oob_rec));
	if (err < 0) {
		printk("Error while adding LE OOB record: %d\n", err);
		return err;
	}

	err = nfc_ndef_msg_encode(&NFC_NDEF_MSG(nfc_le_oob_msg),
				      buffer,
				      len);
	if (err < 0) {
		printk("Error during NDEF message encoding: %d\n", err);
		return err;
	}

	return 0;
}

void app_nfc_init(void)
{
	uint32_t len = sizeof(ndef_msg_buf);

	printk("NFC configuration start\n");

	/* Set up NFC */
	int ret = nfc_t2t_setup(nfc_callback, NULL);
	printk("nfc_t2t_setup %d", ret);
	if (ret < 0) {
		printk("Cannot setup NFC T2T library!\n");
	}

	/* Prepare an NDEF message with LE OOB record. */
	ret = nfc_ndef_le_oob_msg_encode(ndef_msg_buf, &len);
	printk("nfc_t2t_setup %d", ret);
	if (ret < 0) {
		printk("Cannot encode BLE pair message!\n");
	}

	/* Set created message as the NFC payload */
	ret = nfc_t2t_payload_set(ndef_msg_buf, len);
	printk("nfc_t2t_setup %d", ret);
	if (ret < 0) {
		printk("Cannot set payload!\n");
	}

	/* Start sensing NFC field */
	ret = nfc_t2t_emulation_start();
	printk("nfc_t2t_setup %d", ret);
	if (ret < 0) {
		printk("Cannot start emulation!\n");
	}

	printk("NFC configuration done\n");
}

struct bt_le_oob *app_nfc_oob_data_get(void)
{
	return &oob_local;
}

#endif

Thank you!

  • Hi Arthur,

    Both the record_launch_app and record_text samples use callback in a similar manner and doesn't have any special setup for the nRF52832 targets. I believe no special configuration is necessary.

    Could you try flashing those samples and see if they work as intended first? Of course, make any change in pin configuration to adapt to your custom board.

    You mentioned using nRF Connect SDK (NCS) v2.6.0, but with toolchain from v2.7.0. I don't think that is the problem here, but just to be sure, could you please try with toolchain v2.6.0?

    Also likely not the issue, but I recommend moving to at least NCS v2.6.1.

    If the setup still fails after that, could you please have a private case for a hardware design review?

    I also recommend getting a nRF52 DK to test with the most similar environment.

    Hieu

  • Hi Hieu,

    Thank you for the previous suggestions. I followed your advice and tested the peripheral_nfc_pairing sample across multiple nRF Connect SDK and toolchain versions (ensuring they match). Specifically, I tested versions 2.5.2, 2.6.0, and 2.9.0, and the issue remains the same in all cases:

    • I can read the NFC tag information using a smartphone (with an app such as “NFC Tools”), so the tag is recognized and read properly.
    • However, the NFC callback never gets triggered, meaning the BLE advertising does not start (it seems the interrupt is never generated).

    I have double-checked the hardware setup to ensure there are no pin or antenna issues, but so far I haven’t identified anything that would prevent normal operation. If you have any additional troubleshooting steps or configuration changes you recommend, please let me know.

  • Hi Arthur,

    Could you please gather log from a run of the peripheral_nfc_pairing sample with the following Kconfig enabled.

    CONFIG_LOG_MODE_DEFERRED=y
    CONFIG_LOG_BUFFER_SIZE=8192
    CONFIG_LOG_BACKEND_UART_BUFFER_SIZE=8192 # Or RTT if you are logging via RTT.
    
    CONFIG_NFC_PLATFORM_LOG_LEVEL_DBG=y
    CONFIG_NFC_NDEF_CH_REC_PARSER_LOG_LEVEL_DBG=y
    CONFIG_NFC_NDEF_LE_OOB_REC_PARSER_LOG_LEVEL_DBG=y
    CONFIG_NFC_NDEF_PARSER_LOG_LEVEL_DBG=y
    CONFIG_NFC_TNEP_CH_LOG_LEVEL_DBG=y
    CONFIG_NFC_TNEP_TAG_LOG_LEVEL_DBG=y
    

    I am unsure what could be the issue here, so I just want to enable logging for all NFC-related modules to be safe.

    Are you against having a hardware review done by us? It's confidential, and it's helpful to have another pair of eyes checking things over. It's often hard to see a spot in something we have worked on over many days.

    Have you checked with only one unit, or multiple units?

Related