void nrf5TempProcess(void) { int32_t prevTemperature = sTemperature; uint64_t now; #if SOFTDEVICE_PRESENT now = nrf5AlarmGetCurrentTime(); if (now - sLastReadTimestamp > (TEMP_MEASUREMENT_INTERVAL * US_PER_S)) { (void)sd_temp_get(&sTemperature); sLastReadTimestamp = now; } #else if (NRF_TEMP->EVENTS_DATARDY) { dataReadyEventClear(); sTemperature = nrf_temp_read(); } now = nrf5AlarmGetCurrentTime(); if (now - sLastReadTimestamp > (TEMP_MEASUREMENT_INTERVAL * US_PER_S)) { NRF_TEMP->TASKS_START = 1; sLastReadTimestamp = now; } #endif if (prevTemperature != sTemperature) { nrf_802154_temperature_changed(); } }
/** @brief Function for main application entry. */ int main(void) { // This function contains workaround for PAN_028 rev2.0A anomalies 28, 29,30 and 31. int32_t volatile temp; nrf_temp_init(); APP_ERROR_CHECK(NRF_LOG_INIT(NULL)); while (true) { 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\r\n", (int)temp); nrf_delay_ms(500); NRF_LOG_FLUSH(); } }
// the temperature from the internal temperature sensor JsVarFloat jshReadTemperature() { nrf_temp_init(); NRF_TEMP->TASKS_START = 1; while (NRF_TEMP->EVENTS_DATARDY == 0) ;// Do nothing... NRF_TEMP->EVENTS_DATARDY = 0; int32_t nrf_temp = nrf_temp_read(); NRF_TEMP->TASKS_STOP = 1; return nrf_temp / 4.0; }
/** @brief Function for main application entry. */ int main(void) { // This function contains workaround for PAN_028 rev2.0A anomalies 28, 29,30 and 31. int32_t volatile temp; nrf_temp_init(); uint32_t err_code; APP_GPIOTE_INIT(1); const app_uart_comm_params_t comm_params = { RX_PIN_NUMBER, TX_PIN_NUMBER, RTS_PIN_NUMBER, CTS_PIN_NUMBER, APP_UART_FLOW_CONTROL_ENABLED, false, UART_BAUDRATE_BAUDRATE_Baud38400 }; APP_UART_FIFO_INIT(&comm_params, UART_RX_BUF_SIZE, UART_TX_BUF_SIZE, uart_error_handle, APP_IRQ_PRIORITY_LOW, err_code); APP_ERROR_CHECK(err_code); while (true) { 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. */ printf("Actual temperature: %d\n\r", (int)temp); nrf_delay_ms(500); } }
/*====================================================================================================*/ int32_t TEMP_GetTemp( void ) { __IO uint32_t Temp = 0; NRF_TEMP->TASKS_START = 1; while (NRF_TEMP->EVENTS_DATARDY == 0); NRF_TEMP->EVENTS_DATARDY = 0; Temp = nrf_temp_read(); NRF_TEMP->TASKS_STOP = 1; return Temp; }
int32_t nrf5TempGet(void) { NRF_TEMP->TASKS_START = 1; while (NRF_TEMP->EVENTS_DATARDY == 0) { ; } dataReadyEventClear(); int32_t temperature = nrf_temp_read(); NRF_TEMP->TASKS_STOP = 1; return temperature; }
uint32_t nrf_utils_read_temperature(void) { nrf_temp_init(); int32_t volatile nrf_temp; NRF_TEMP->TASKS_START = 1; while (NRF_TEMP->EVENTS_DATARDY == 0) { // Do nothing... } NRF_TEMP->EVENTS_DATARDY = 0; nrf_temp = (nrf_temp_read() / 4); NRF_TEMP->TASKS_STOP = 1; return (uint32_t) nrf_temp; }
/*====================================================================================================*/ int32_t TEMP_GetTemp( void ) { return nrf_temp_read(); }
// the temperature from the internal temperature sensor JsVarFloat jshReadTemperature() { nrf_temp_init(); return nrf_temp_read() / 4.0; }