Hi,
I'm on NCS 1.8.0 and I've successfully built and run the peripheral_nfc_example sample.
Printed logs when reading NDEF message using a smartphone
I: NFC configuration done D: reader polling detected I: tnep_initial_msg_encode D: reader polling OFF I: tnep_initial_msg_encode D: reader polling OFF I: tnep_initial_msg_encode D: reader polling detected I: tnep_initial_msg_encode D: reader has read NDEF data
When I came to integrate the sample with a BLE NUS service application, the reader fails.
The polling field is detected, but something gets wrong and the reading process never come to a conclusion
[00:00:01.064,849] <inf> nfc: NFC configuration done [00:00:05.630,554] <inf> batt: discharging [00:00:13.444,183] <dbg> nfc.nfc_callback: reader polling detected [00:00:13.450[00:00:13.451,965] <dbg> nfc.nfc_callback: reader polling OFF ,775] <inf> nfc: tnep_initial_msg_encode [00:00:13.462,615] <inf> nfc: tnep_initial_msg_encode [00:00:13.489,959] <dbg> nfc.nfc_callback: reader polling OFF [00:00:13.496,032] <inf> nfc: tnep_initial_msg_encode [00:00:13.813,720] <dbg> nfc.nfc_callback: reader polling detected [00:00:13.820,[00:00:13.821,472] <dbg> nfc.nfc_callback: reader polling OFF 312] <inf> nfc: tnep_initial_msg_encode [00:00:13.832,122] <inf> nfc: tnep_initial_msg_encode [00:00:13.859,497] <dbg> nfc.nfc_callback: reader polling OFF [00:00:13.865,570] <inf> nfc: tnep_initial_msg_encode [00:00:14.183,258] <dbg> nfc.nfc_callback: reader polling detected [00:00:14.189,[00:00:14.191,009] <dbg> nfc.nfc_callback: reader polling OFF 849] <inf> nfc: tnep_initial_msg_encode ...
In the porting process I've replaced the infinite loop of the sample with a thread. Maybe the error is here ?
This is the nfc_callback (almost unchanged from the sample) and the thread code definitions.
static void nfc_callback(void *context,
enum nfc_t4t_event event,
const uint8_t *data,
size_t data_length,
uint32_t flags)
{
ARG_UNUSED(context);
ARG_UNUSED(data);
ARG_UNUSED(flags);
switch (event) {
case NFC_T4T_EVENT_FIELD_ON:
nfc_tnep_tag_on_selected();
LOG_DBG("reader polling detected");
adv_permission = true;
break;
case NFC_T4T_EVENT_FIELD_OFF:
nfc_tnep_tag_on_selected();
LOG_DBG("reader polling OFF");
break;
case NFC_T4T_EVENT_NDEF_READ:
LOG_DBG("reader has read NDEF data");
if (adv_permission) {
advertising_start();
adv_permission = false;
}
break;
case NFC_T4T_EVENT_NDEF_UPDATED:
LOG_DBG("reader has written NDEF data (%u)", data_length);
if (data_length > 0) {
nfc_tnep_tag_rx_msg_indicate(nfc_t4t_ndef_file_msg_get(data),
data_length);
}
default:
break;
}
}
extern struct k_sem nfc_init_ok;
#define NFC_TIMEOUT_MS 100
#define NFC_STACKSIZE CONFIG_BT_NUS_THREAD_STACK_SIZE
#define NFC_PRIORITY 7
void nfc_thread(void *arg1, void *arg2, void *arg3)
{
int rc;
ARG_UNUSED(arg1);
ARG_UNUSED(arg2);
ARG_UNUSED(arg3);
/* Don't go any further until initialized */
k_sem_take(&nfc_init_ok, K_FOREVER);
rc = pairing_key_generate();
if (rc) {
return;
}
k_work_init(&adv_work, adv_handler);
pair_key_generate_init();
nfc_init();
for (;;) {
k_poll(events, ARRAY_SIZE(events), K_FOREVER);
nfc_tnep_tag_process();
pairing_key_process();
k_msleep(NFC_TIMEOUT_MS);
}
}
K_THREAD_DEFINE(nfc_thread_id, NFC_STACKSIZE, \
nfc_thread, NULL, NULL, NULL, NFC_PRIORITY, 0, 0);
Changing the thread constants doesn't help.