lmn2005 发表于 2022-5-22 11:24

ESP8266 GPIO中断引起不断重启

本帖最后由 lmn2005 于 2022-5-24 18:39 编辑

ESP8266 启用GPIO中断后会引起不断重启,打印内容:
rl\0l恟$鈔 ?l?b|帎抮b?b騨nlnnb bp?blrlp騨 ?l ? b n鈔?? b尿nn'l?l`?nn $`nr帓抧 rr抈p騨? r?b  b n鈔  b尿nn' l`?nn $`nr帓抧 rl`r拻n rl`? 宭?l`鼈n抈ISR not in IRAM!

User exception (panic/abort/assert)
--------------- CUT HERE FOR EXCEPTION DECODER ---------------

Abort called

>>>stack>>>

ctx: cont
sp: 3fffff00 end: 3fffffc0 offset: 0000
3fffff00:feefeffe feefeffe feefeffe 3ffef33c
3fffff10:000000fe 00000000 00000000 00000000
3fffff20:00000000 00000000 00000000 00ff0000
3fffff30:5ffffe00 5ffffe00 0001c200 3ffee564
3fffff40:00000000 00000002 0000000d 40201dae
3fffff50:40100489 00000001 3ffee4fc 40201dc0
3fffff60:00000000 00000001 0000000d 402022fd
3fffff70:00000000 feefeffe feefeffe feefeffe
3fffff80:3fffdad0 00000000 3ffee550 4020239c
3fffff90:3fffdad0 00000000 3ffee550 402010f5
3fffffa0:feefeffe feefeffe feefeffe 4020193c
3fffffb0:feefeffe feefeffe 3ffe85d8 40100d45
<<<stack<<<

--------------- CUT HERE FOR EXCEPTION DECODER ---------------



#define LED_Pin 4            
#define K1_Pin 13
uint8led=0;
void keyscan() // GPIO输入中断函数
{
if (analogRead(K1_Pin) == LOW)
{
    delay(20);
    if (analogRead(K1_Pin) == LOW)
    {
      Serial.println("IRQ");
      if (led == 1)
      turnOffLed(); //关闭灯泡
      else
      turnOnLed(); //打开灯泡
    }
}
}

void turnOnLed() //打开灯泡
{
Serial.println("Turn ON");
led = 1;
digitalWrite(LED_Pin, LOW);
}

void turnOffLed() //关闭灯泡
{
Serial.println("Turn OFF");
led = 0;
digitalWrite(LED_Pin, HIGH);
}

void setup()
{
Serial.begin(115200);
pinMode(LED_Pin, OUTPUT);      
pinMode(K1_Pin, INPUT_PULLUP);      
attachInterrupt(digitalPinToInterrupt(K1_Pin), keyscan, FALLING); // 中断
}

void loop()
{

}


lwq1947 发表于 2022-5-23 16:10

把void keyscan() 改为:
void ICACHE_RAM_ATTR keyscan()

XlinliY.Zhang 发表于 2022-5-22 15:30

中断不仅没有中断头,还用delay

lmn2005 发表于 2022-5-22 18:04

XlinliY.Zhang 发表于 2022-5-22 15:30
中断不仅没有中断头,还用delay

没有中断头,不是设置这个就好吗?
pinMode(K1_Pin, INPUT_PULLUP);      
attachInterrupt(digitalPinToInterrupt(K1_Pin), keyscan, FALLING); // 中断
初入门,真的搞不懂,这是人家的示例,莫想到也是坑。

lmn2005 发表于 2022-5-24 18:38

lwq1947 发表于 2022-5-23 16:10
把void keyscan() 改为:
void ICACHE_RAM_ATTR keyscan()

谢谢!问题已经解决!
页: [1]
查看完整版本: ESP8266 GPIO中断引起不断重启