1、平台条件
1.1 软件:esp-idf_3.3v
1.2 硬件:esp32
2、.h文件
#ifndef system_timer_h_
#define system_timer_h_
void system_timer_init(void);
void task_system_time(void);
void system_timer_start(void);
#endif
3、.c文件
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "esp_timer.h"
#include "esp_log.h"
#include "esp_sleep.h"
#include "sdkconfig.h"
#include "ble_gatts.h"
#include "adc_app.h"
#include "sd_card.h"
#include "system_timer.h"
#include "wdt_init.h"
#include "interface_rtc.h"
#include "sht30.h"
#include "lis3dh.h"
#include "uart_app.h"
static const char* TAG = "system_timer";
static void system_timer_callback(void* arg);
static uint8_t system_time_1s_enable =0;
esp_timer_handle_t system_timer;
/****************************************************** */
static void system_timer_callback(void* arg)
{
// int64_t time_since_boot = esp_timer_get_time();
system_time_1s_enable =1;
// ESP_LOGI(TAG, "Periodic timer called, time since boot: %lld us", esp_timer_get_time());
}
void system_timer_init(void)
{
const esp_timer_create_args_t system_timer_args =
{
.callback = &system_timer_callback,
.name = "periodic"
};
ESP_ERROR_CHECK(esp_timer_create(&system_timer_args, &system_timer));
system_timer_start();
}
void system_timer_start(void)
{
// 开启一个周期性定时器-----------------------------------------------------/
ESP_ERROR_CHECK(esp_timer_start_periodic(system_timer, 1000000)); // 1s -----单位是us
}
/*************************************************
*
* 1s定时器任务
*/
void task_system_time(void)
{
if(system_time_1s_enable==0) return;
system_time_1s_enable=0;
// 1s定时器处理应用程序
}
可以加入QQ群:687360507
与大伙沟通交流,技术在于分享而进步