I want to implement the function of periodic temperature collection,but I didn`t find any data show in putty terminal,and I`ve set NRFX_TIMER_ENABLED 1 NRFX_TIMER0_ENABLED 1.
Is there something wrong with my code?
#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include "nrf.h"
#include "nrf_drv_timer.h"
#include "bsp.h"
#include "app_error.h"
#include "E:/BaiduNetdiskDownload/nRF5_SDK_15.2.0_9412b96/nRF5_SDK_15.2.0_9412b96/components/libraries/delay/nrf_delay.h"
#include "nrf_temp.h"
#include "app_error.h"
#include "nrf_log.h"
#include "nrf_log_ctrl.h"
#include "nrf_log_default_backends.h"
const nrf_drv_timer_t TIMER_LED = NRF_DRV_TIMER_INSTANCE(0);
/**
* @brief Handler for timer events.
*/
void timer_led_event_handler(nrf_timer_event_t event_type, void* p_context)
{
int32_t volatile temp;
nrf_temp_init();
APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
NRF_LOG_DEFAULT_BACKENDS_INIT();
NRF_LOG_INFO("Temperature example started.");
NRF_TEMP->TASKS_START = 1; /** Start the temperature measurement. */
while (NRF_TEMP->EVENTS_DATARDY == 0)
{
}
NRF_TEMP->EVENTS_DATARDY = 0;
temp = (nrf_temp_read() / 4);
NRF_TEMP->TASKS_STOP = 1;
NRF_LOG_INFO("Actual temperature: %d", (int)temp);
}
int main(void)
{
uint32_t time_ms = 500; //Time(in miliseconds) between consecutive compare events.
uint32_t time_ticks;
uint32_t err_code = NRF_SUCCESS;
nrf_drv_timer_config_t timer_cfg = NRF_DRV_TIMER_DEFAULT_CONFIG;
err_code = nrf_drv_timer_init(&TIMER_LED, &timer_cfg, timer_led_event_handler);
APP_ERROR_CHECK(err_code);
time_ticks = nrf_drv_timer_ms_to_ticks(&TIMER_LED, time_ms);
nrf_drv_timer_extended_compare(
&TIMER_LED, NRF_TIMER_CC_CHANNEL0, time_ticks, NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK, true);
nrf_drv_timer_enable(&TIMER_LED);
while (1)
{
__WFI();
}
}