Reading temperature with SD

Hi,

I would like to read the temperature of the nRF.

I tried to use the routine I found here in the forum

int32_t read_temperature(void)
{
  
  // This function contains workaround for PAN_028 rev2.0A anomalies 28, 29,30 and 31.
  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. */
  /*lint -e{845} // 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. */

  NRF_LOG_INFO("Actual temperature: %d", (int)temp);
  return temp;
}

Sometimes works sometimes the system crash.
I notice the system crash when the SD in on.

Routine access directly to the registers: there are any other function or SD function (I am using S140) to read temperature?

Thanks

Alessandro

Related