1. 程式人生 > >NRF52832 temperature for sdk 15.2.0

NRF52832 temperature for sdk 15.2.0

1.引入標頭檔案

#include "nrf_temp.h"

2.定義變數

int32_t volatile temp;

3.在主函式中的處理

/**  * @brief Function for main application entry.  */ int main(void) {     uint32_t err_code;          bsp_board_init(BSP_INIT_LEDS);

    const app_uart_comm_params_t comm_params =       {           RX_PIN_NUMBER,           TX_PIN_NUMBER,           RTS_PIN_NUMBER,           CTS_PIN_NUMBER,           UART_HWFC,           false, #if defined (UART_PRESENT)           NRF_UART_BAUDRATE_115200 #else           NRF_UARTE_BAUDRATE_115200 #endif       };

    APP_UART_FIFO_INIT(&comm_params,                          UART_RX_BUF_SIZE,                          UART_TX_BUF_SIZE,                          uart_error_handle,                          APP_IRQ_PRIORITY_LOWEST,                          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;  // clear flag                  /**@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("temp is %d\n",temp);         nrf_delay_ms(1000);     }

}