diff --git a/src/core/analogsensor.cpp b/src/core/analogsensor.cpp index 6d4b3f59b..134c69977 100644 --- a/src/core/analogsensor.cpp +++ b/src/core/analogsensor.cpp @@ -26,8 +26,8 @@ std::vector AnalogSensor::exclude_types_; #ifndef EMSESP_STANDALONE portMUX_TYPE mux = portMUX_INITIALIZER_UNLOCKED; -unsigned long AnalogSensor::edge[] = {0, 0, 0}; -unsigned long AnalogSensor::edgecnt[] = {0, 0, 0}; +volatile unsigned long AnalogSensor::edge[] = {0, 0, 0}; +volatile unsigned long AnalogSensor::edgecnt[] = {0, 0, 0}; void IRAM_ATTR AnalogSensor::freqIrq0() { portENTER_CRITICAL_ISR(&mux); diff --git a/src/core/analogsensor.h b/src/core/analogsensor.h index 592452f96..31a7af0ec 100644 --- a/src/core/analogsensor.h +++ b/src/core/analogsensor.h @@ -210,8 +210,8 @@ class AnalogSensor { static void IRAM_ATTR freqIrq0(); static void IRAM_ATTR freqIrq1(); static void IRAM_ATTR freqIrq2(); - static unsigned long edge[3]; - static unsigned long edgecnt[3]; + static volatile unsigned long edge[3]; // written from freqIrqN() ISRs, read from the main measure() loop (partly outside the critical section) + static volatile unsigned long edgecnt[3]; // written from freqIrqN() ISRs, read from the main measure() loop (partly outside the critical section) unsigned long lastedge[3] = {0, 0, 0}; #endif };