diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index 8120e0d6c5..d7462bc99d 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -1483,8 +1483,15 @@ void Temperature::set_current_temp_raw() { */ ISR(TIMER0_COMPB_vect) { Temperature::isr(); } +volatile bool Temperature::in_temp_isr = false; + void Temperature::isr() { - //Allow UART and stepper ISRs + // The stepper ISR can interrupt this ISR. When it does it re-enables this ISR + // at the end of its run, potentially causing re-entry. This flag prevents it. + if (in_temp_isr) return; + in_temp_isr = true; + + // Allow UART and stepper ISRs CBI(TIMSK0, OCIE0B); //Disable Temperature ISR sei(); @@ -1949,5 +1956,7 @@ void Temperature::isr() { } #endif + cli(); + in_temp_isr = false; SBI(TIMSK0, OCIE0B); //re-enable Temperature ISR } diff --git a/Marlin/temperature.h b/Marlin/temperature.h index 182efd5645..e592148447 100644 --- a/Marlin/temperature.h +++ b/Marlin/temperature.h @@ -61,6 +61,8 @@ class Temperature { current_temperature_bed_raw, target_temperature_bed; + static volatile bool in_temp_isr; + #if ENABLED(TEMP_SENSOR_1_AS_REDUNDANT) static float redundant_temperature; #endif