定时器中断

wxyaoo
Posts: 5
Joined: Mon May 31, 2021 10:01 am

定时器中断

Postby wxyaoo » Fri Jun 11, 2021 6:20 am

请问为什么我的程序就是进不去这个定时中断呢,中断回调函数一直都不执行,是哪里出了为题,大声能帮忙看看吗?

Code: Select all

const int button = 0;         //  按键用于触发延时
const int wdtTimeout = 3000;  //  看门狗时间(ms)
hw_timer_t *timer = NULL;

void IRAM_ATTR resetModule() { // 中断函数
  Serial.println("reboot\n");
  esp_restart();
}

void setup() {
  Serial.begin(9600);
  Serial.println();
  Serial.println("running setup");

  pinMode(button, INPUT_PULLUP);                    
  timer = timerBegin(0, 80, true);                  // 选择timer0,分频系数为80,向上计数
  timerAttachInterrupt(timer, &resetModule, true);  // 绑定中断函数
  timerAlarmWrite(timer, wdtTimeout * 1000, false); // 设置报警保护函数
  timerAlarmEnable(timer);                          // 使能报警器
}

void loop() {
  Serial.println("running main loop");

  timerWrite(timer, 0); // 重置定时器,喂狗 (feed watchdog)
  long loopTime = millis();
  // 当按键被按着超过了3秒,看门狗重启程序
  while (!digitalRead(button)) {
    Serial.println("button pressed");
    delay(500);
  }
  delay(1000); 
  loopTime = millis() - loopTime;
  
  Serial.print("loop time is = ");
  Serial.println(loopTime);
}

ESP_Eavo
Posts: 186
Joined: Tue Jun 08, 2021 6:23 am

Re: 定时器中断

Postby ESP_Eavo » Fri Jun 11, 2021 12:18 pm

您好,请您详细描述下问题:
- 硬件平台:Chip or Module or DevKit? ESP8266 or ESP32 or C3...?
- 软件版本和 commit id:
- 问题现象:
- log 和其它资料:
- 复现步骤:
- 其它:

Who is online

Users browsing this forum: No registered users and 175 guests