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

NFC problem: Sample code does not work in my own project.

Hi everybody,

I have some troble getting the record_url sample running in my own gcc based build environment. The function calls to the nfc library always return ok, but the sample URL is not being sent over nfc.

Is there something special that I have to do when I want to use nfc? Something that is not configured in main.c of the samples?

If I program the pre-compiled .hex file to my nRF52-DK, the nfc just works fine. But not if I compile the code by myself.

This is my main() function that shall initialize the nfc hardware:

static uint8_t ndef_msg_buf[256];

int main()
{
    NfcRetval  result_nfc;
    ret_code_t result;
    uint32_t   len;

    init_softdevice();    // enable SoftDevice, set ram size etc.

    result_nfc = nfcSetup(nfc_callback, NULL);
    if (result_nfc != NFC_RETVAL_OK)
        APP_ERROR_CHECK((uint32_t) result_nfc);

    len = sizeof(ndef_msg_buf);
    result = nfc_uri_msg_encode( NFC_URI_HTTP_WWW, "nordicsemi.com", 15, ndef_msg_buf, &len);
    APP_ERROR_CHECK(result);

    result_nfc = nfcSetPayload((char *)ndef_msg_buf, len);
    if (result_nfc != NFC_RETVAL_OK)
        APP_ERROR_CHECK((uint32_t) result_nfc);

    result_nfc = nfcStartEmulation();
    if (result_nfc != NFC_RETVAL_OK)
        APP_ERROR_CHECK((uint32_t) result_nfc);

    for (;;) { }
}

The nrf_callback() is never called and no data is sent to the smartphone that comes close. What could be the problem here? I am using SDK v11.0.0 and SoftDevice S132 v2.0.0.

Update:

I have tried debugging the software with EmbSysRegView. After calling nfcSetup(), I get the following NFCT register configuration:

image description

After calling nfcSetPayload() and nfcStartEmulation(), the registers don't change anymore.

If I move my smartphone close to the antenna, the EVENTS_FIELDDETECTED register becomes 1. If I move my smartphone away, it becomes 0 again. Though, FIELDPRESENT remains 0 at all times.

It seems like the NFC hardware is not configured correctly. For example, PACKETPTR and MAXLEN both are set to 0. Once again, I would like to mention that all calls to the nfc library return OK (´0´).

It is a bit annoying that the nfc library comes precompiled, so it is not possible to look into the sourcecode and track down the error. Isn't there any normal driver availabe that provides a simple interface? NFCT isn't even part of the HAL under drivers_nrf...

Related