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

Application "hangs" after nrfx_temp value returned

While trying to utilize the TEMP peripheral today, I found that after the event handler returns a single reading the application does not continue to run. Any actions that should occur after a temperature measurement is taken are not performed however the application error handler is never triggered. I originally thought I might be running into an interrupt priority issue but raising and lower the priority had no effect.

I've created a separate project that only takes a temperature measurement and logs the value and am met with the same behavior, one measurement is taken, printed to the console, and nothing else executes.

I've included the code for reference below.

volatile int32_t nrf_temp {0};

void init_log()
{
    ret_code_t err_code = NRF_LOG_INIT(NULL);
    APP_ERROR_CHECK(err_code);

    NRF_LOG_DEFAULT_BACKENDS_INIT();
}

void nrf_temp_data_handler(int32_t raw_temperature)
{
    int32_t core_temp = nrfx_temp_calculate(raw_temperature);
    uint32_t temp_diff = std::abs(core_temp - nrf_temp);
    if (temp_diff >= 1000)
    {
        nrf_temp = core_temp;
        NRF_LOG_INFO("%d", core_temp);
    }
    nrfx_temp_uninit();
}

void temp_init()
{
    const nrfx_temp_config_t config { .interrupt_priority = 3 };
    nrfx_temp_init(&config, nrf_temp_data_handler);
}

void get_nrf_temperature()
{
    temp_init();
    nrfx_temp_measure();
    
    // Get temperature every 5 minutes.
       
}

int main(void)
{
    init_log();
    
    while (1)
    {
        get_nrf_temperature();
        nrf_delay_ms(5000);
        NRF_LOG_FLUSH();
    }
}

Thanks.

  • Your code seem to work as expected here. I only commented out the if() statement in nrf_temp_data_handler() and reduced the delay to 1second to observe it faster. Though I am not using cpp, so I did small modification to c.

    volatile int32_t nrf_temp = {0};
    
    void init_log()
    {
        ret_code_t err_code = NRF_LOG_INIT(NULL);
        APP_ERROR_CHECK(err_code);
    
        NRF_LOG_DEFAULT_BACKENDS_INIT();
    }
    
    void nrf_temp_data_handler(int32_t raw_temperature)
    {
        int32_t core_temp = nrfx_temp_calculate(raw_temperature);
        uint32_t temp_diff = core_temp - nrf_temp;
        //if (temp_diff >= 1000)
        {
            nrf_temp = core_temp;
            NRF_LOG_INFO("%d", core_temp);
        }
        nrfx_temp_uninit();
    }
    
    void temp_init()
    {
        const nrfx_temp_config_t config = { .interrupt_priority = 3 };
        nrfx_temp_init(&config, nrf_temp_data_handler);
    }
    
    void get_nrf_temperature()
    {
        temp_init();
        nrfx_temp_measure();
        
        // Get temperature every 5 minutes.
           
    }
    
    int main(void)
    {
        init_log();
        
        while (1)
        {
            get_nrf_temperature();
            nrf_delay_ms(1000);
            NRF_LOG_FLUSH();
        }
    }
    
    

    Kenneth

Related