Measuring temperature using the sensor in nRF52832

Hello,

In an application with the nRF52832, Softdevice and SDK 17.1.0 I try to use the temperature sensor according to the peripheral example. I attach the temperature.c file code.

#include <stdint.h>
#include "nrf_temp.h"

// Function to initialize and read temperature from the TEMP peripheral using SDK functions
int32_t nrf_read_temperature(void) {
   int32_t temp;

   nrf_temp_init();

   NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */

   /* Busy wait while temperature measurement is not finished, you can skip waiting if you enable interrupt for DATARDY event and read the result in the interrupt. */
   /* A zero has been given as right argument to operator '|'" */
   while (NRF_TEMP->EVENTS_DATARDY == 0)
   {
        // Do nothing.
   }
    NRF_TEMP->EVENTS_DATARDY = 0;

   /**@note Workaround for PAN_028 rev2.0A anomaly 29 - TEMP: Stop task clears the TEMP register. */
   temp = (nrf_temp_read() / 4);

    /**@note Workaround for PAN_028 rev2.0A anomaly 30 - TEMP: Temp module analog front end does not power down when DATARDY event occurs. */
    NRF_TEMP->TASKS_STOP = 1; /** Stop the temperature measurement. */

    return (temp);
    }

However, I have problems executing the nrf_read_temperature() function because the program breaks without an specific reason. Should I use another code? Any suggestion?

Thank you very much in advance.

Regards,

Joel

Parents Reply Children
No Data
Related