第一种报错
Guru Meditation Error: Core 1 panic'ed (Interrupt wdt timeout on CPU1).
导致原因多半是在中断里加入print了,串口打印是有阻塞性的
这使看门狗报警指CPU1卡死
办法一:在loop里和中断里给CPU1的看门狗喂食即可
#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"
hw_timer_t * timer = NULL; //声明一个定时器
ICACHE_RAM_ATTR void onTimer() { //中断函数
TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE; // 写使能,允许写入看门狗寄存器
TIMERG0.wdt_feed = 1; // 喂狗,重置看门狗计时器
TIMERG0.wdt_wprotect = 0; // 写保护,禁止写入看门狗寄存器
Serial.println('1');
}
void setup() {
Serial.begin(115200);
timer = timerBegin(0, 80, true); //初始化
timerAttachInterrupt(timer, &onTimer, true); //调用中断函数
timerAlarmWrite(timer, 1000000, true); //timerBegin的参数二 80位80MHZ,这里为1000000 意思为1秒
timerAlarmEnable(timer); //定时器使能
}
void loop() {
TIMERG0.wdt_wprotect = TIMG_WDT_WKEY_VALUE; // 写使能,允许写入看门狗寄存器
TIMERG0.wdt_feed = 1; // 喂狗,重置看门狗计时器
TIMERG0.wdt_wprotect = 0; // 写保护,禁止写入看门狗寄存器
}
办法二:创造一个标志位(BOOL)最好这样做
hw_timer_t * timer = NULL; //声明一个定时器
bool mark = 0;
ICACHE_RAM_ATTR void onTimer() { //中断函数
mark = 1;
}
void setup() {
Serial.begin(115200);
timer = timerBegin(0, 80, true); //初始化
timerAttachInterrupt(timer, &onTimer, true); //调用中断函数
timerAlarmWrite(timer, 1000000, true); //timerBegin的参数二 80位80MHZ,这里为1000000 意思为1秒
timerAlarmEnable(timer); //定时器使能
}
void loop() {
if(mark == 1)
{
Serial.println("1");
mark = 0;
}
}
第二种报错
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled
这个报错导致原因是再中断中滞留时间过长别在里面加太多代码处理方法跟上述问题的第二种解决方法一样加个标志位即可.