ESP32 arduino定时器中断
·
ESP32 arduino定时器中断
hw_timer_t * timer = NULL; //声明一个定时器
void IRAM_ATTR onTimer() { //中断函数
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); //定时器使能
//timerDetachInterrupt(timer); //关闭定时器
}
void loop() {
}

更多推荐
所有评论(0)