1
volatile boolean  interrupt_occurred = false; 
#define           LED_pin D1

void ICACHE_RAM_ATTR handleInterrupt() {
  digitalWrite(LED_pin, HIGH); // Interrupt occurred, so turn On LED
  interrupt_occurred = true;   // Record that an interrupt occurred
}

void setup() {
  noInterrupts();
  
  //for test
  pinMode(LED_pin, OUTPUT);   // LED pin to Output mode
  digitalWrite(LED_pin, LOW); // Turn LED off (High = On, Low = Off)

  pinMode(D10, FUNCTION_1); // Set D10 as UART transmitter
  pinMode(D9, FUNCTION_1); // Set D9 as UART receiver
  Serial.begin(115200, SERIAL_8N1); // initialize the serial

  //pinMode(D9, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(D9), handleInterrupt, FALLING);
  interrupts();
}


void loop() {
 
  delay(1000);
  
   if (interrupt_occurred == true) { 
    Serial.println("An interrupt occurred");
    delay(500);
    digitalWrite(LED_pin, LOW);     // Now turn Off LED, ready for the next interrupt
    interrupt_occurred = false;
  }  
}

enter image description here

I am using arduino IDE to program ESP8266-12F, and use a USB-uart converter to connect the D9(RX) and D10(TX) of ESP8266 with my laptop, when I tried to send something from my PC to the corresponding COM, the interrupt is not executed, but when ESP8266 sends something to my PC, PC can reveive it and print out, it seems that ESP8266 cannot receive message from my PC, why?

Jiaao Liu
  • 11
  • 1

0 Answers0