ESP32使用硬件定时器中断引起重启-Arduino中文社区 - Powered by Discuz!

Arduino中文社区

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 501|回复: 5

[已解决] ESP32使用硬件定时器中断引起重启

[复制链接]
发表于 2022-6-1 08:19 | 显示全部楼层 |阅读模式
本帖最后由 lmn2005 于 2022-6-2 19:19 编辑

参考https://blog.csdn.net/weixin_42880082/article/details/120882798使用esp32内部硬件定时器,结果大约每隔4、5秒就会重启一次:


ets Jun  8 206 00:22:57

rst:0x (POWERON_RESET)bot:0x7 (SPI_FAST_FLASH_BOT)
configsip: 0, SPWP:0xee
clk_drv:0x00,_rv:0x00,d_drv:0x00,c0_drv:0x0,hd_drv:0x00,wp_dv:0x00
modeIO, clc div:1
load:0x3fff001,len:4
load:0x3fff001c,en:1128
load:0x400700,len:10124
load:0x0080400,len:5856
enry 0x40006a8
haha
1
haha
1
haha
1
haha
1
E (10102) task_wdt: Task watchdog got triggered. The following tasks did not reset the watchdog in time:
E (10102) task_wdt:  - IDLE0 (CPU 0)
E (10102) task_wdt: Tasks currently running:
E (10102) task_wdt: CPU 0: loopTask
E (10102) task_wdt: Aborting.
abort() was called at PC 0x400d43b3 on core 0

ELF file SHA256: 0000000000000000

Backtrace: 0x4008498c:0x3ffbe2b0 0x40084be9:0x3ffbe2d0 0x400d43b3:0x3ffbe2f0 0x400825aa:0x3ffbe310 0x400d0b24:0x3ffb1f90 0x400d1f79:0x3ffb1fb0 0x40085b55:0x3ffb1fd0

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
modeIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1128
load:0x40078000,len:10124
load:0x40080400,len:5856
entry 0x400806a8
haha
1
haha
1


这是为什么?
源代码如下:



#include <Arduino.h>
hw_timer_t *tim1 = NULL;
int tim1_IRQ_count = 0;

void ICACHE_RAM_ATTR tim1Interrupt() //中断服务函数
{
  Serial.println("haha");
  tim1_IRQ_count++;
  Serial.println(timerAlarmEnabled(tim1));
}

void setup()
{
  Serial.begin(115200);
  tim1 = timerBegin(0, 80, true); // 80MHZ, ESP32主频80MHz
  timerAttachInterrupt(tim1, tim1Interrupt, true);
  timerAlarmWrite(tim1, 1000000ul, true);
  timerAlarmEnable(tim1); // 使能定时器
}

void loop()
{
  if (tim1_IRQ_count > 10)
  {
    Serial.println("timer------");
    tim1_IRQ_count = 0;
  }
}






发表于 2022-6-1 14:02 | 显示全部楼层
loop中喂狗试试
发表于 2022-6-1 21:41 | 显示全部楼层
本帖最后由 王尼玛1 于 2022-6-1 22:45 编辑
  1. #include <Arduino.h>

  2. hw_timer_t *tim1 = NULL;
  3. int tim1_IRQ_count = 0;

  4. void ICACHE_RAM_ATTR tim1Interrupt() //中断服务函数
  5. {
  6.   
  7.   tim1_IRQ_count++;
  8.   // 中断里面不要用串口打印
  9.   //Serial.println("haha");
  10. // Serial.println(timerAlarmEnabled(tim1));
  11. }

  12. void setup()
  13. {
  14.   Serial.begin(115200);
  15.   tim1 = timerBegin(0, 80, true); // 80MHZ, ESP32主频80MHz
  16.   timerAttachInterrupt(tim1, tim1Interrupt, true);
  17.   timerAlarmWrite(tim1, 1000000ul, true);
  18.   timerAlarmEnable(tim1); // 使能定时器
  19. }

  20. void loop()
  21. {
  22.   if (tim1_IRQ_count > 10)
  23.   {
  24.     Serial.println("timer------");
  25.     tim1_IRQ_count = 0;
  26.   }
  27. }
复制代码

 楼主| 发表于 2022-6-2 19:09 | 显示全部楼层

参考https://blog.csdn.net/jianfengbeyond/article/details/123979350喂狗,没有作用。
 楼主| 发表于 2022-6-2 19:19 | 显示全部楼层
我试试在loop里面加了延时delay(1)就可以暂时解决。不知道还有没有更好的方案。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|Archiver|手机版|Arduino中文社区

GMT+8, 2025-1-1 20:29 , Processed in 0.073104 second(s), 15 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表