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

nrf5340 read temperature by nrfx_temp_measure() function sometimes return -53℃ at room temperature

following is my code

#include <nrfx_temp.h>

static void temp_handler(int32_t temperature)
{ 
    m_soc_temperature = temperature;
    printk("Temperature (Celcius): %d \n",temperature / 4);
}

static void soc_temperature_peripheral_init(void)
{
    int err;
    nrfx_temp_config_t temp_config = NRFX_TEMP_DEFAULT_CONFIG;
    err = nrfx_temp_init(&temp_config,temp_handler);
    IRQ_CONNECT(TEMP_IRQn,5,nrfx_temp_irq_handler,NULL,0);
    if (err!=NRFX_SUCCESS) 
    {	
	    printk("soc_temperature_peripheral_init error %d\n", err);
    }
}

int main()
{
    soc_temperature_peripheral_init();
    for(;;)
    {
        k_sleep(K_SECONDS(1));
        if(NRFX_SUCCESS == nrfx_temp_measure()){
            LOG_INF("soc temperature is %d",m_soc_temperature/4);
        }
    }
}

prj.conf file :

CONFIG_NRFX_TEMP=y

Parents Reply
  • Hi Kenneth,
    Thanks for offering to help. I have so far been unable to create a minimal project that shows the problem.

    Our application firmware shows the problem when run on a nRF5340-DK, but for complexity and security reasons I can't share that.

    What I have noticed is that after flashing the application core firmware using VS Code, the temperature values seem to be correct. Typical values are TEMP=0x00000066. Resetting the chip from the VS Code debugger does not change that.

    But when I reset the chip using SW5 on the DK, suddenly I get negative values, e.g. TEMP=0xFFFFFF2B.

    I will try to further narrow down the problem.

    --Stephan

Children
Related