Wednesday, June 19, 2024

nodemcu12-f esp8266 flow sensor result ISR not in IRAM!

if we use esp8266 and have error ISR not in IRAm when we use interrupt

then we must code like this :

int sensorPin = 2;
volatile long pulse = 0;

// Declare the increase function prototype

void IRAM_ATTR increase() { // use this IRAM_ATTR
  pulse++;
}

void setup() {
  pinMode(sensorPin, INPUT_PULLUP);
  Serial.begin(115200);
  attachInterrupt(digitalPinToInterrupt(sensorPin), increase, FALLING);
}

void loop() {
  Serial.println(pulse);
  delay(500);
}



No comments:

Post a Comment