nfct not working when i configure the hfclk

Hi, 

 In my project, I need turn on/off  the hfxo, I found when i configure the hfxo, the nfc is not working. Here is my code:

void gps_server_function(void *p1, void *p2, void *p3)
{
    msg_gps_type_t item;
    int ret;
    static bool gps_power_lock = false;
    while (true)
    {
        k_msgq_get(&gps_task_msgq, &item, K_FOREVER); // 等待消息
        switch (item)
        {
        case GPS_OPEN_LOCK:
            LOG_INF("open gps module");
            sim66md_power(1);
            gps_power_lock = true;
            nfc_t4t_emulation_stop();
            ret = clock_control_on(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
            if (ret != 0)
            {
                LOG_INF("Failed to start HFCLK: %d", ret);
            }
            else
            {
                LOG_INF("HFCLK started successfully.");
                nfc_t4t_emulation_start();
            }
            break;
        case GPS_FETCH:
            sim66md_power(1);
            int ret = sim66md_get_rmc(&rmc_frame, 90);
            if (ret < 0)
            {
                rmc_frame.valid = false;
                LOG_ERR("can not get valid rmc message");
            }
            else
            {
                LOG_INF("coordinates: (%f,%f); speed: (%f);",
                        minmea_tocoord(&rmc_frame.latitude),
                        minmea_tocoord(&rmc_frame.longitude),
                        minmea_tofloat(&rmc_frame.speed));
            }
            if (gps_power_lock == false)
            {
                sim66md_power(0);
            }

            break;
        case GPS_CLOSE:
            LOG_INF("close gps module");
            sim66md_power(0);
            gps_power_lock = false;
            clock_control_off(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
            LOG_INF("HFCLK stopped.");
            break;
        default:
            break;
        }
    }
}
Parents
  • Hi!

    I see you have this in the code:

            case GPS_CLOSE:
                LOG_INF("close gps module");
                sim66md_power(0);
                gps_power_lock = false;
                clock_control_off(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
                LOG_INF("HFCLK stopped.");
                break;

    If you remove, "clock_control_off(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);" line, does the nfc work as expected then?

  • Here is my updated code, it still have same problem
    void gps_server_function(void *p1, void *p2, void *p3)
    {
        msg_gps_type_t item;
        int ret;
        static bool gps_power_lock = false;
        while (true)
        {
            k_msgq_get(&gps_task_msgq, &item, K_FOREVER); // 等待消息
            switch (item)
            {
            case GPS_OPEN_LOCK:
                LOG_INF("open gps module");
                sim66md_power(1);
                gps_power_lock = true;
                nfc_t4t_emulation_stop();
                ret = clock_control_on(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
                if (ret != 0)
                {
                    LOG_INF("Failed to start HFCLK: %d", ret);
                }
                else
                {
                    LOG_INF("HFCLK started successfully.");
                }
                break;
            case GPS_FETCH:
                sim66md_power(1);
                int ret = sim66md_get_rmc(&rmc_frame, 90);
                if (ret < 0)
                {
                    rmc_frame.valid = false;
                    LOG_ERR("can not get valid rmc message");
                }
                else
                {
                    LOG_INF("coordinates: (%f,%f); speed: (%f);",
                            minmea_tocoord(&rmc_frame.latitude),
                            minmea_tocoord(&rmc_frame.longitude),
                            minmea_tofloat(&rmc_frame.speed));
                }
                if (gps_power_lock == false)
                {
                    sim66md_power(0);
                }

                break;
            case GPS_CLOSE:
                LOG_INF("close gps module");
                sim66md_power(0);
                gps_power_lock = false;
                nfc_t4t_emulation_start();
                clock_control_off(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
                LOG_INF("HFCLK stopped.");
                break;
            default:
                break;
            }
        }
    }
Reply
  • Here is my updated code, it still have same problem
    void gps_server_function(void *p1, void *p2, void *p3)
    {
        msg_gps_type_t item;
        int ret;
        static bool gps_power_lock = false;
        while (true)
        {
            k_msgq_get(&gps_task_msgq, &item, K_FOREVER); // 等待消息
            switch (item)
            {
            case GPS_OPEN_LOCK:
                LOG_INF("open gps module");
                sim66md_power(1);
                gps_power_lock = true;
                nfc_t4t_emulation_stop();
                ret = clock_control_on(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
                if (ret != 0)
                {
                    LOG_INF("Failed to start HFCLK: %d", ret);
                }
                else
                {
                    LOG_INF("HFCLK started successfully.");
                }
                break;
            case GPS_FETCH:
                sim66md_power(1);
                int ret = sim66md_get_rmc(&rmc_frame, 90);
                if (ret < 0)
                {
                    rmc_frame.valid = false;
                    LOG_ERR("can not get valid rmc message");
                }
                else
                {
                    LOG_INF("coordinates: (%f,%f); speed: (%f);",
                            minmea_tocoord(&rmc_frame.latitude),
                            minmea_tocoord(&rmc_frame.longitude),
                            minmea_tofloat(&rmc_frame.speed));
                }
                if (gps_power_lock == false)
                {
                    sim66md_power(0);
                }

                break;
            case GPS_CLOSE:
                LOG_INF("close gps module");
                sim66md_power(0);
                gps_power_lock = false;
                nfc_t4t_emulation_start();
                clock_control_off(clock_dev, CLOCK_CONTROL_NRF_SUBSYS_HF);
                LOG_INF("HFCLK stopped.");
                break;
            default:
                break;
            }
        }
    }
Children
  • Hi!

    Could you try to explain what you are trying to do here? Why start NFC and stop HFXO on case GPS_CLOSE?

    Also did you call e.g. nfc_t4t_setup() ?

    You should also check the return code from nfc_t4t_emulation_start() and nfc_t4t_emulation_stop().

    e.g.

    int err;

    err = nfc_t4t_emulation_start();
    if (err) {
    LOG_ERR("Failed to start NFC T4T emulation, (err: %d)", err);
    }

  • Due to low power requirements, I need to dynamically enable and disable HFXO. When I turn on the GPS, I enable HFXO, and before enabling HFXO, I disable the NFC function to prevent NFC from being in an unknown state after switching to HFXO. Before turning off HFXO, I first restore the NFC functionality. Additionally, nfc_t4t_emulation_start always returns successfully as long as it is not called repeatedl

  • I also noticed that the function nfct_field_timer_config(uint8_t irq_priority) at line 383 in the file D:\Nordic\v2.5.1\modules\hal\nordic\nrfx\drivers\src\nrfx_nfct.c uses timer2. When I change the HFCLK clock source, it should affect timer2, which could lead to NFC not functioning properl

    static inline nrfx_err_t nfct_field_timer_config(uint8_t irq_priority)
    {
        nrfx_err_t err_code;
        nrfx_timer_config_t timer_cfg = NRFX_TIMER_DEFAULT_CONFIG(FIELD_TIMER_FREQUENCY_HZ);
        timer_cfg.interrupt_priority = irq_priority;
    
        err_code = nrfx_timer_init(&m_timer_workaround.timer,
                                   &timer_cfg,
                                   nfct_field_timer_handler);
        if (err_code != NRFX_SUCCESS)
        {
            return err_code;
        }
    
        nrfx_timer_extended_compare(&m_timer_workaround.timer,
                                    NRF_TIMER_CC_CHANNEL0,
                                    nrfx_timer_us_to_ticks(&m_timer_workaround.timer,
                                                           NRFX_NFCT_TIMER_PERIOD),
                                    NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK,
                                    true);
        return err_code;
    }

Related