ESP32用中断函数按键控制发送MODBUS指令控制继电器不动作, 串口监视器能检测到按键动作,继电器不动,是中断函数不支持这样通信吗?
void setup() {
Serial.begin(115200);
Serial2.begin(9600);
pinMode(34,INPUT_PULLDOWN);
pinMode(35,INPUT_PULLDOWN);
pinMode(18,INPUT_PULLUP);
pinMode(19,INPUT_PULLUP);
attachInterrupt(interruptPin1,ISR,FALLING);
attachInterrupt(interruptPin1,DAOZHU,CHANGE);
attachInterrupt(interruptPin2,DAOBEI,CHANGE);
}
void loop() {
Serial.print(digitalRead(interruptPin1));
delay(1000);
Serial.print(digitalRead(interruptPin2));
delay(1000);
/*Serial2.write(relay_ON5,sizeof(relay_ON5));
delay(5000);
Serial2.write(relay_OFF5,sizeof(relay_OFF5));
delay(5000);*/
}
void ISR()
{
Serial.print("断开");
}
void DAOZHU()
{
static unsigned long lasttime = 0;
unsigned long intime = millis();
if(intime - lasttime > 200){
Serial2.write(relay_ON0,sizeof(relay_ON0));
delay(5000);
Serial2.write(relay_OFF0,sizeof(relay_OFF0));
}
lasttime = intime;
}
void DAOBEI()
{
static unsigned long lasttime = 0;
unsigned long intime = millis();
if(intime - lasttime > 200)
{
Serial2.write(relay_ON0,sizeof(relay_ON0));
delay(5000);
Serial2.write(relay_OFF0,sizeof(relay_OFF0));
}
lasttime = intime;
}
rst:0x1 (POWERON_RESET),boot:0x13 (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
mode:DIO, clock div:1
load:0x3fff0030,len:1344
load:0x40078000,len:13864
load:0x40080400,len:3608
entry 0x400805f0
11111111断开0断开断开1断开01断开1断开
```