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

Read Chip Temperature Sensor on nrf52832

Hello,

I am trying to read the internal temperature sensor using interrupts (SoftDevice is disabled). This is what I have:

#include "nrf_temp.h"
#include "nrf_nvic.h"

static int32_t g_temp_reading;

void TEMP_IRQHandler()
{
    NRF_TEMP->EVENTS_DATARDY = 0;
    g_temp_reading = (nrf_temp_read() / 4);
    NRF_TEMP->TASKS_STOP = 1;
}

void init()
{
    nrf_temp_init();

    g_temp_reading = 0;

    NRF_TEMP->INTENSET |= TEMP_INTENSET_DATARDY_Enabled;

    sd_nvic_SetPriority(TEMP_IRQn, APP_IRQ_PRIORITY_LOW);
    sd_nvic_EnableIRQ(TEMP_IRQn);
}

void get_temperature()
{
    NRF_TEMP->TASKS_START = 1;
}

For some reason it never gets into "TEMP_IRQHandler()"

Could you please help me understand what I am doing wrong?

Thank you in advance.

  • Hello Simonr,

    In my first post I am enabling DATARDY inside init() function call with this:

    NRF_TEMP->INTENSET |= TEMP_INTENSET_DATARDY_Enabled;

    I am also starting a new measurement inside get_temperature() with this code:

    NRF_TEMP->TASKS_START = 1;

    But as I stated before, the interrupt handler never gets called. I guess it is because I am not using the softdevice and so these function calls inside init() have no effect:

        sd_nvic_SetPriority(TEMP_IRQn, APP_IRQ_PRIORITY_LOW);
        sd_nvic_EnableIRQ(TEMP_IRQn);

    But I have tried removing them and still my interrupt handler never gets called. I am having a look to the SDK source code and I am trying to understand how to do this without the softdevice enabled, but it doesn't seem to be any information about this.

    Can you please let me know what I am doing wrong?

    Regards,

    Alfonso

  • Hi Alfonso

    You have to enable and set the priority with functions that aren't using the SoftDevice. Using NVIC_SetPriority() and NVIC_EnableIRQ() instead of the sd_ "versions" should work.

    Best regards,

    Simon

Related