ESP32笔记(3) 定时器的使用

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
与大伙沟通交流,技术在于分享而进步

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值