diff --git a/Marlin/Configuration.h b/Marlin/Configuration.h index 83c1c541e363..87a98298a58e 100644 --- a/Marlin/Configuration.h +++ b/Marlin/Configuration.h @@ -564,6 +564,10 @@ #define MAX31865_SENSOR_OHMS_1 100 #define MAX31865_CALIBRATION_OHMS_1 430 #endif +#if TEMP_SENSOR_IS_MAX_TC(2) + #define MAX31865_SENSOR_OHMS_2 100 + #define MAX31865_CALIBRATION_OHMS_2 430 +#endif #if HAS_E_TEMP_SENSOR #define TEMP_RESIDENCY_TIME 10 // (seconds) Time to wait for hotend to "settle" in M109 diff --git a/Marlin/Configuration_adv.h b/Marlin/Configuration_adv.h index 01a2bd85c53b..9a54b10b82b1 100644 --- a/Marlin/Configuration_adv.h +++ b/Marlin/Configuration_adv.h @@ -175,6 +175,7 @@ //#define TEMP_SENSOR_FORCE_HW_SPI // Ignore SCK/MOSI/MISO pins; use CS and the default SPI bus. //#define MAX31865_SENSOR_WIRES_0 2 // (2-4) Number of wires for the probe connected to a MAX31865 board. //#define MAX31865_SENSOR_WIRES_1 2 +//#define MAX31865_SENSOR_WIRES_2 2 //#define MAX31865_50HZ_FILTER // Use a 50Hz filter instead of the default 60Hz. //#define MAX31865_USE_READ_ERROR_DETECTION // Treat value spikes (20°C delta in under 1s) as read errors. @@ -185,6 +186,7 @@ //#define MAX31865_WIRE_OHMS_0 0.95f // For 2-wire, set the wire resistances for more accurate readings. //#define MAX31865_WIRE_OHMS_1 0.0f +//#define MAX31865_WIRE_OHMS_2 0.0f /** * Hephestos 2 24V heated bed upgrade kit. diff --git a/Marlin/src/inc/Conditionals_adv.h b/Marlin/src/inc/Conditionals_adv.h index 1f8f0ddfb61e..dd69e61c9275 100644 --- a/Marlin/src/inc/Conditionals_adv.h +++ b/Marlin/src/inc/Conditionals_adv.h @@ -262,26 +262,72 @@ #undef HEATER_1_MAXTEMP #endif +#if TEMP_SENSOR_IS_MAX_TC(2) + #if TEMP_SENSOR_2 == -5 + #define TEMP_SENSOR_2_IS_MAX31865 1 + #define TEMP_SENSOR_2_MAX_TC_TMIN 0 + #define TEMP_SENSOR_2_MAX_TC_TMAX 1024 + #ifndef MAX31865_SENSOR_WIRES_2 + #define MAX31865_SENSOR_WIRES_2 2 + #endif + #ifndef MAX31865_WIRE_OHMS_2 + #define MAX31865_WIRE_OHMS_2 0.0f + #endif + #elif TEMP_SENSOR_2 == -3 + #define TEMP_SENSOR_2_IS_MAX31855 1 + #define TEMP_SENSOR_2_MAX_TC_TMIN -270 + #define TEMP_SENSOR_2_MAX_TC_TMAX 1800 + #elif TEMP_SENSOR_2 == -2 + #define TEMP_SENSOR_2_IS_MAX6675 1 + #define TEMP_SENSOR_2_MAX_TC_TMIN 0 + #define TEMP_SENSOR_2_MAX_TC_TMAX 1024 + #endif + + #if TEMP_SENSOR_2 != TEMP_SENSOR_0 + #if TEMP_SENSOR_2 == -5 + #error "If MAX31865 Thermocouple (-5) is used for TEMP_SENSOR_2 then TEMP_SENSOR_0 must match." + #elif TEMP_SENSOR_2 == -3 + #error "If MAX31855 Thermocouple (-3) is used for TEMP_SENSOR_2 then TEMP_SENSOR_0 must match." + #elif TEMP_SENSOR_2 == -2 + #error "If MAX6675 Thermocouple (-2) is used for TEMP_SENSOR_2 then TEMP_SENSOR_0 must match." + #endif + #endif +#elif TEMP_SENSOR_2 == -4 + #define TEMP_SENSOR_2_IS_AD8495 1 +#elif TEMP_SENSOR_2 == -1 + #define TEMP_SENSOR_2_IS_AD595 1 +#elif TEMP_SENSOR_2 > 0 + #define TEMP_SENSOR_2_IS_THERMISTOR 1 + #if TEMP_SENSOR_2 == 1000 + #define TEMP_SENSOR_2_IS_CUSTOM 1 + #elif TEMP_SENSOR_2 == 998 || TEMP_SENSOR_2 == 999 + #define TEMP_SENSOR_2_IS_DUMMY 1 + #endif +#else + #undef HEATER_2_MINTEMP + #undef HEATER_2_MAXTEMP +#endif + #if TEMP_SENSOR_IS_MAX_TC(REDUNDANT) #if TEMP_SENSOR_REDUNDANT == -5 - #if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) - #error "MAX31865 Thermocouples (-5) not supported for TEMP_SENSOR_REDUNDANT_SOURCE other than TEMP_SENSOR_0/TEMP_SENSOR_1 (0/1)." + #if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) && !REDUNDANT_TEMP_MATCH(SOURCE, E2) + #error "MAX31865 Thermocouples (-5) not supported for TEMP_SENSOR_REDUNDANT_SOURCE other than TEMP_SENSOR_0/TEMP_SENSOR_1/TEMP_SENSOR_2 (0/1/2)." #endif #define TEMP_SENSOR_REDUNDANT_IS_MAX31865 1 #define TEMP_SENSOR_REDUNDANT_MAX_TC_TMIN 0 #define TEMP_SENSOR_REDUNDANT_MAX_TC_TMAX 1024 #elif TEMP_SENSOR_REDUNDANT == -3 - #if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) - #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_REDUNDANT_SOURCE other than TEMP_SENSOR_0/TEMP_SENSOR_1 (0/1)." + #if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) && !REDUNDANT_TEMP_MATCH(SOURCE, E2) + #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_REDUNDANT_SOURCE other than TEMP_SENSOR_0/TEMP_SENSOR_1/TEMP_SENSOR_2 (0/1/2)." #endif #define TEMP_SENSOR_REDUNDANT_IS_MAX31855 1 #define TEMP_SENSOR_REDUNDANT_MAX_TC_TMIN -270 #define TEMP_SENSOR_REDUNDANT_MAX_TC_TMAX 1800 #elif TEMP_SENSOR_REDUNDANT == -2 - #if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) - #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_REDUNDANT_SOURCE other than TEMP_SENSOR_0/TEMP_SENSOR_1 (0/1)." + #if !REDUNDANT_TEMP_MATCH(SOURCE, E0) && !REDUNDANT_TEMP_MATCH(SOURCE, E1) && !REDUNDANT_TEMP_MATCH(SOURCE, E2) + #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_REDUNDANT_SOURCE other than TEMP_SENSOR_0/TEMP_SENSOR_1/TEMP_SENSOR_2 (0/1/2)." #endif #define TEMP_SENSOR_REDUNDANT_IS_MAX6675 1 @@ -302,15 +348,21 @@ #ifndef MAX31865_SENSOR_WIRES_1 #define MAX31865_SENSOR_WIRES_1 2 #endif + #elif REDUNDANT_TEMP_MATCH(SOURCE, E2) + #define TEMP_SENSOR_2_MAX_TC_TMIN TEMP_SENSOR_REDUNDANT_MAX_TC_TMIN + #define TEMP_SENSOR_2_MAX_TC_TMAX TEMP_SENSOR_REDUNDANT_MAX_TC_TMAX + #ifndef MAX31865_SENSOR_WIRES_2 + #define MAX31865_SENSOR_WIRES_2 2 + #endif #endif - #if (TEMP_SENSOR_IS_MAX_TC(0) && TEMP_SENSOR_REDUNDANT != TEMP_SENSOR_0) || (TEMP_SENSOR_IS_MAX_TC(1) && TEMP_SENSOR_REDUNDANT != TEMP_SENSOR_1) + #if (TEMP_SENSOR_IS_MAX_TC(0) && TEMP_SENSOR_REDUNDANT != TEMP_SENSOR_0) || (TEMP_SENSOR_IS_MAX_TC(1) && TEMP_SENSOR_REDUNDANT != TEMP_SENSOR_1) || (TEMP_SENSOR_IS_MAX_TC(2) && TEMP_SENSOR_REDUNDANT != TEMP_SENSOR_2) #if TEMP_SENSOR_REDUNDANT == -5 - #error "If MAX31865 Thermocouple (-5) is used for TEMP_SENSOR_0/TEMP_SENSOR_1 then TEMP_SENSOR_REDUNDANT must match." + #error "If MAX31865 Thermocouple (-5) is used for TEMP_SENSOR_0/TEMP_SENSOR_1/TEMP_SENSOR_2 then TEMP_SENSOR_REDUNDANT must match." #elif TEMP_SENSOR_REDUNDANT == -3 - #error "If MAX31855 Thermocouple (-3) is used for TEMP_SENSOR_0/TEMP_SENSOR_1 then TEMP_SENSOR_REDUNDANT must match." + #error "If MAX31855 Thermocouple (-3) is used for TEMP_SENSOR_0/TEMP_SENSOR_1/TEMP_SENSOR_2 then TEMP_SENSOR_REDUNDANT must match." #elif TEMP_SENSOR_REDUNDANT == -2 - #error "If MAX6675 Thermocouple (-2) is used for TEMP_SENSOR_0/TEMP_SENSOR_1 then TEMP_SENSOR_REDUNDANT must match." + #error "If MAX6675 Thermocouple (-2) is used for TEMP_SENSOR_0/TEMP_SENSOR_1/TEMP_SENSOR_2 then TEMP_SENSOR_REDUNDANT must match." #endif #endif #elif TEMP_SENSOR_REDUNDANT == -4 @@ -326,39 +378,19 @@ #endif #endif -#if TEMP_SENSOR_IS_MAX_TC(0) || TEMP_SENSOR_IS_MAX_TC(1) || TEMP_SENSOR_IS_MAX_TC(REDUNDANT) +#if TEMP_SENSOR_IS_MAX_TC(0) || TEMP_SENSOR_IS_MAX_TC(1) || TEMP_SENSOR_IS_MAX_TC(2) || TEMP_SENSOR_IS_MAX_TC(REDUNDANT) #define HAS_MAX_TC 1 #endif -#if TEMP_SENSOR_0_IS_MAX6675 || TEMP_SENSOR_1_IS_MAX6675 || TEMP_SENSOR_REDUNDANT_IS_MAX6675 +#if TEMP_SENSOR_0_IS_MAX6675 || TEMP_SENSOR_1_IS_MAX6675 || TEMP_SENSOR_2_IS_MAX6675 || TEMP_SENSOR_REDUNDANT_IS_MAX6675 #define HAS_MAX6675 1 #endif -#if TEMP_SENSOR_0_IS_MAX31855 || TEMP_SENSOR_1_IS_MAX31855 || TEMP_SENSOR_REDUNDANT_IS_MAX31855 +#if TEMP_SENSOR_0_IS_MAX31855 || TEMP_SENSOR_1_IS_MAX31855 || TEMP_SENSOR_2_IS_MAX31855 || TEMP_SENSOR_REDUNDANT_IS_MAX31855 #define HAS_MAX31855 1 #endif -#if TEMP_SENSOR_0_IS_MAX31865 || TEMP_SENSOR_1_IS_MAX31865 || TEMP_SENSOR_REDUNDANT_IS_MAX31865 +#if TEMP_SENSOR_0_IS_MAX31865 || TEMP_SENSOR_1_IS_MAX31865 || TEMP_SENSOR_2_IS_MAX31865 || TEMP_SENSOR_REDUNDANT_IS_MAX31865 #define HAS_MAX31865 1 #endif -#if TEMP_SENSOR_2 == -4 - #define TEMP_SENSOR_2_IS_AD8495 1 -#elif TEMP_SENSOR_2 == -3 - #error "MAX31855 Thermocouples (-3) not supported for TEMP_SENSOR_2." -#elif TEMP_SENSOR_2 == -2 - #error "MAX6675 Thermocouples (-2) not supported for TEMP_SENSOR_2." -#elif TEMP_SENSOR_2 == -1 - #define TEMP_SENSOR_2_IS_AD595 1 -#elif TEMP_SENSOR_2 > 0 - #define TEMP_SENSOR_2_IS_THERMISTOR 1 - #if TEMP_SENSOR_2 == 1000 - #define TEMP_SENSOR_2_IS_CUSTOM 1 - #elif TEMP_SENSOR_2 == 998 || TEMP_SENSOR_2 == 999 - #define TEMP_SENSOR_2_IS_DUMMY 1 - #endif -#else - #undef HEATER_2_MINTEMP - #undef HEATER_2_MAXTEMP -#endif - #if TEMP_SENSOR_3 == -4 #define TEMP_SENSOR_3_IS_AD8495 1 #elif TEMP_SENSOR_3 == -3 diff --git a/Marlin/src/inc/Conditionals_post.h b/Marlin/src/inc/Conditionals_post.h index 21f0eed622da..5f540393921d 100644 --- a/Marlin/src/inc/Conditionals_post.h +++ b/Marlin/src/inc/Conditionals_post.h @@ -723,19 +723,19 @@ #define TEMP_0_SCK_PIN MAX31855_SCK_PIN #endif - #elif TEMP_SENSOR_1_IS_MAX31865 - #if !PIN_EXISTS(TEMP_1_MISO) // DO + #elif TEMP_SENSOR_0_IS_MAX31865 + #if !PIN_EXISTS(TEMP_0_MISO) // DO #if PIN_EXISTS(MAX31865_MISO) - #define TEMP_1_MISO_PIN MAX31865_MISO_PIN + #define TEMP_0_MISO_PIN MAX31865_MISO_PIN #elif PIN_EXISTS(MAX31865_DO) - #define TEMP_1_MISO_PIN MAX31865_DO_PIN + #define TEMP_0_MISO_PIN MAX31865_DO_PIN #endif #endif - #if !PIN_EXISTS(TEMP_1_SCK) && PIN_EXISTS(MAX31865_SCK) - #define TEMP_1_SCK_PIN MAX31865_SCK_PIN + #if !PIN_EXISTS(TEMP_0_SCK) && PIN_EXISTS(MAX31865_SCK) + #define TEMP_0_SCK_PIN MAX31865_SCK_PIN #endif - #if !PIN_EXISTS(TEMP_1_MOSI) && PIN_EXISTS(MAX31865_MOSI) // MOSI for '65 only - #define TEMP_1_MOSI_PIN MAX31865_MOSI_PIN + #if !PIN_EXISTS(TEMP_0_MOSI) && PIN_EXISTS(MAX31865_MOSI) // MOSI for '65 only + #define TEMP_0_MOSI_PIN MAX31865_MOSI_PIN #endif #endif @@ -819,6 +819,75 @@ #endif // TEMP_SENSOR_IS_MAX_TC(1) + #if TEMP_SENSOR_IS_MAX_TC(2) || (TEMP_SENSOR_IS_MAX_TC(REDUNDANT) && REDUNDANT_TEMP_MATCH(SOURCE, E2)) + + #if !PIN_EXISTS(TEMP_2_CS) // SS3, CS3 + #if PIN_EXISTS(MAX6675_SS3) + #define TEMP_2_CS_PIN MAX6675_SS3_PIN + #elif PIN_EXISTS(MAX6675_CS) + #define TEMP_2_CS_PIN MAX6675_CS3_PIN + #elif PIN_EXISTS(MAX31855_SS3) + #define TEMP_2_CS_PIN MAX31855_SS3_PIN + #elif PIN_EXISTS(MAX31855_CS3) + #define TEMP_2_CS_PIN MAX31855_CS3_PIN + #elif PIN_EXISTS(MAX31865_SS3) + #define TEMP_2_CS_PIN MAX31865_SS3_PIN + #elif PIN_EXISTS(MAX31865_CS3) + #define TEMP_2_CS_PIN MAX31865_CS3_PIN + #endif + #endif + + #if TEMP_SENSOR_2_IS_MAX6675 + #if !PIN_EXISTS(TEMP_2_MISO) // DO + #if PIN_EXISTS(MAX6675_MISO) + #define TEMP_2_MISO_PIN MAX6675_MISO_PIN + #elif PIN_EXISTS(MAX6675_DO) + #define TEMP_2_MISO_PIN MAX6675_DO_PIN + #endif + #endif + #if !PIN_EXISTS(TEMP_2_SCK) && PIN_EXISTS(MAX6675_SCK) + #define TEMP_2_SCK_PIN MAX6675_SCK_PIN + #endif + + #elif TEMP_SENSOR_2_IS_MAX31855 + #if !PIN_EXISTS(TEMP_2_MISO) // DO + #if PIN_EXISTS(MAX31855_MISO) + #define TEMP_2_MISO_PIN MAX31855_MISO_PIN + #elif PIN_EXISTS(MAX31855_DO) + #define TEMP_2_MISO_PIN MAX31855_DO_PIN + #endif + #endif + #if !PIN_EXISTS(TEMP_2_SCK) && PIN_EXISTS(MAX31855_SCK) + #define TEMP_2_SCK_PIN MAX31855_SCK_PIN + #endif + + #elif TEMP_SENSOR_2_IS_MAX31865 + #if !PIN_EXISTS(TEMP_2_MISO) // DO + #if PIN_EXISTS(MAX31865_MISO) + #define TEMP_2_MISO_PIN MAX31865_MISO_PIN + #elif PIN_EXISTS(MAX31865_DO) + #define TEMP_2_MISO_PIN MAX31865_DO_PIN + #endif + #endif + #if !PIN_EXISTS(TEMP_2_SCK) && PIN_EXISTS(MAX31865_SCK) + #define TEMP_2_SCK_PIN MAX31865_SCK_PIN + #endif + #if !PIN_EXISTS(TEMP_2_MOSI) && PIN_EXISTS(MAX31865_MOSI) // MOSI for '65 only + #define TEMP_2_MOSI_PIN MAX31865_MOSI_PIN + #endif + #endif + + // Software SPI - enable if MISO/SCK are defined. + #if PIN_EXISTS(TEMP_2_MISO) && PIN_EXISTS(TEMP_2_SCK) && DISABLED(TEMP_SENSOR_2_FORCE_HW_SPI) + #if TEMP_SENSOR_2_IS_MAX31865 && !PIN_EXISTS(TEMP_2_MOSI) + #error "TEMP_SENSOR_2 MAX31865 requires TEMP_2_MOSI_PIN defined for Software SPI. To use Hardware SPI instead, undefine MISO/SCK or enable TEMP_SENSOR_2_FORCE_HW_SPI." + #else + #define TEMP_SENSOR_2_HAS_SPI_PINS 1 + #endif + #endif + + #endif // TEMP_SENSOR_IS_MAX_TC(2) + // // User-defined thermocouple libraries // diff --git a/Marlin/src/inc/SanityCheck.h b/Marlin/src/inc/SanityCheck.h index 06b8f32946ad..744e68a5bb0d 100644 --- a/Marlin/src/inc/SanityCheck.h +++ b/Marlin/src/inc/SanityCheck.h @@ -416,17 +416,17 @@ #elif defined(CHDK) #error "CHDK is now CHDK_PIN." #elif ANY_PIN( \ - MAX6675_SS, MAX6675_SS2, MAX6675_CS, MAX6675_CS2, \ - MAX31855_SS, MAX31855_SS2, MAX31855_CS, MAX31855_CS2, \ - MAX31865_SS, MAX31865_SS2, MAX31865_CS, MAX31865_CS2) - #warning "MAX*_SS_PIN, MAX*_SS2_PIN, MAX*_CS_PIN, and MAX*_CS2_PIN are deprecated and will be removed in a future version. Please use TEMP_0_CS_PIN/TEMP_1_CS_PIN instead." + MAX6675_SS, MAX6675_SS2, MAX6675_SS3, MAX6675_CS, MAX6675_CS2, MAX6675_CS3,\ + MAX31855_SS, MAX31855_SS2, MAX31855_SS3, MAX31855_CS, MAX31855_CS2, MAX31855_CS3, \ + MAX31865_SS, MAX31865_SS2, MAX31865_SS3, MAX31865_CS, MAX31865_CS2, MAX31865_CS3) + #warning "MAX*_SS_PIN, MAX*_SS2_PIN, MAX*_SS3_PIN, MAX*_CS_PIN, MAX*_CS2_PIN, and MAX*_CS3_PIN, are deprecated and will be removed in a future version. Please use TEMP_0_CS_PIN/TEMP_1_CS_PIN/TEMP_2_CS_PIN instead." #elif ANY_PIN(MAX6675_SCK, MAX31855_SCK, MAX31865_SCK) - #warning "MAX*_SCK_PIN is deprecated and will be removed in a future version. Please use TEMP_0_SCK_PIN/TEMP_1_SCK_PIN instead." + #warning "MAX*_SCK_PIN is deprecated and will be removed in a future version. Please use TEMP_0_SCK_PIN/TEMP_1_SCK_PIN/TEMP_2_SCK_PIN instead." #elif ANY_PIN(MAX6675_MISO, MAX6675_DO, MAX31855_MISO, MAX31855_DO, MAX31865_MISO, MAX31865_DO) - #warning "MAX*_MISO_PIN and MAX*_DO_PIN are deprecated and will be removed in a future version. Please use TEMP_0_MISO_PIN/TEMP_1_MISO_PIN instead." + #warning "MAX*_MISO_PIN and MAX*_DO_PIN are deprecated and will be removed in a future version. Please use TEMP_0_MISO_PIN/TEMP_1_MISO_PIN/TEMP_2_MISO_PIN instead." #elif PIN_EXISTS(MAX31865_MOSI) - #warning "MAX31865_MOSI_PIN is deprecated and will be removed in a future version. Please use TEMP_0_MOSI_PIN/TEMP_1_MOSI_PIN instead." -#elif ANY_PIN(THERMO_CS1_PIN, THERMO_CS2_PIN, THERMO_DO_PIN, THERMO_SCK_PIN) + #warning "MAX31865_MOSI_PIN is deprecated and will be removed in a future version. Please use TEMP_0_MOSI_PIN/TEMP_1_MOSI_PIN/TEMP_2_MOSI_PIN instead." +#elif ANY_PIN(THERMO_CS1_PIN, THERMO_CS2_PIN, THERMO_CS3_PIN, THERMO_DO_PIN, THERMO_SCK_PIN) #error "THERMO_*_PIN is now TEMP_n_CS_PIN, TEMP_n_SCK_PIN, TEMP_n_MOSI_PIN, TEMP_n_MISO_PIN." #elif defined(MAX31865_SENSOR_OHMS) #error "MAX31865_SENSOR_OHMS is now MAX31865_SENSOR_OHMS_0." @@ -2340,6 +2340,13 @@ static_assert(Y_MAX_LENGTH >= Y_BED_SIZE, "Movement bounds (Y_MIN_POS, Y_MAX_POS #error "MAX31865_SENSOR_OHMS_1 and MAX31865_CALIBRATION_OHMS_1 must be set if TEMP_SENSOR_1/TEMP_SENSOR_REDUNDANT is MAX31865." #endif #endif +#if TEMP_SENSOR_2_IS_MAX31865 || (TEMP_SENSOR_REDUNDANT_IS_MAX31865 && REDUNDANT_TEMP_MATCH(SOURCE, E2)) + #if !defined(MAX31865_SENSOR_WIRES_2) || !WITHIN(MAX31865_SENSOR_WIRES_2, 2, 4) + #error "MAX31865_SENSOR_WIRES_2 must be defined as an integer between 2 and 4." + #elif !defined(MAX31865_SENSOR_OHMS_2) || !defined(MAX31865_CALIBRATION_OHMS_2) + #error "MAX31865_SENSOR_OHMS_2 and MAX31865_CALIBRATION_OHMS_2 must be set if TEMP_SENSOR_2/TEMP_SENSOR_REDUNDANT is MAX31865." + #endif +#endif /** * Redundant temperature sensor config diff --git a/Marlin/src/module/temperature.cpp b/Marlin/src/module/temperature.cpp index 7515396fbefb..8843582f4e67 100644 --- a/Marlin/src/module/temperature.cpp +++ b/Marlin/src/module/temperature.cpp @@ -113,13 +113,16 @@ // 3. CS, MISO, and SCK pins w/ FORCE_HW_SPI: Hardware SPI on the default bus, ignoring MISO, SCK. // #if TEMP_SENSOR_IS_ANY_MAX_TC(0) && TEMP_SENSOR_0_HAS_SPI_PINS && DISABLED(TEMP_SENSOR_FORCE_HW_SPI) - #define TEMP_SENSOR_0_USES_SW_SPI 1 + #define TEMP_SENSOR_0_USES_SW_SPI 1 #endif #if TEMP_SENSOR_IS_ANY_MAX_TC(1) && TEMP_SENSOR_1_HAS_SPI_PINS && DISABLED(TEMP_SENSOR_FORCE_HW_SPI) - #define TEMP_SENSOR_1_USES_SW_SPI 1 + #define TEMP_SENSOR_1_USES_SW_SPI 1 +#endif +#if TEMP_SENSOR_IS_ANY_MAX_TC(2) && TEMP_SENSOR_2_HAS_SPI_PINS && DISABLED(TEMP_SENSOR_FORCE_HW_SPI) + #define TEMP_SENSOR_2_USES_SW_SPI 1 #endif -#if (TEMP_SENSOR_0_USES_SW_SPI || TEMP_SENSOR_1_USES_SW_SPI) && !HAS_MAXTC_LIBRARIES +#if (TEMP_SENSOR_0_USES_SW_SPI || TEMP_SENSOR_1_USES_SW_SPI || TEMP_SENSOR_2_USES_SW_SPI) && !HAS_MAXTC_LIBRARIES #include "../libs/private_spi.h" #define HAS_MAXTC_SW_SPI 1 @@ -130,12 +133,18 @@ #if PIN_EXISTS(TEMP_0_MOSI) #define SW_SPI_MOSI_PIN TEMP_0_MOSI_PIN #endif - #else + #elif TEMP_SENSOR_1_USES_SW_SPI #define SW_SPI_SCK_PIN TEMP_1_SCK_PIN #define SW_SPI_MISO_PIN TEMP_1_MISO_PIN #if PIN_EXISTS(TEMP_1_MOSI) #define SW_SPI_MOSI_PIN TEMP_1_MOSI_PIN #endif + #elif TEMP_SENSOR_2_USES_SW_SPI + #define SW_SPI_SCK_PIN TEMP_2_SCK_PIN + #define SW_SPI_MISO_PIN TEMP_2_MISO_PIN + #if PIN_EXISTS(TEMP_2_MOSI) + #define SW_SPI_MOSI_PIN TEMP_2_MOSI_PIN + #endif #endif #ifndef SW_SPI_MOSI_PIN #define SW_SPI_MOSI_PIN SD_MOSI_PIN @@ -256,6 +265,9 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED); #if TEMP_SENSOR_IS_MAX(1, 6675) MAXTC_INIT(1, 6675); #endif + #if TEMP_SENSOR_IS_MAX(2, 6675) + MAXTC_INIT(2, 6675); + #endif #endif #if HAS_MAX31855_LIBRARY @@ -265,12 +277,16 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED); #if TEMP_SENSOR_IS_MAX(1, 31855) MAXTC_INIT(1, 31855); #endif + #if TEMP_SENSOR_IS_MAX(2, 31855) + MAXTC_INIT(2, 31855); + #endif #endif // MAX31865 always uses a library, unlike '55 & 6675 #if HAS_MAX31865 #define _MAX31865_0_SW TEMP_SENSOR_0_USES_SW_SPI #define _MAX31865_1_SW TEMP_SENSOR_1_USES_SW_SPI + #define _MAX31865_2_SW TEMP_SENSOR_2_USES_SW_SPI #if TEMP_SENSOR_IS_MAX(0, 31865) MAXTC_INIT(0, 31865); @@ -278,9 +294,13 @@ PGMSTR(str_t_heating_failed, STR_T_HEATING_FAILED); #if TEMP_SENSOR_IS_MAX(1, 31865) MAXTC_INIT(1, 31865); #endif + #if TEMP_SENSOR_IS_MAX(2, 31865) + MAXTC_INIT(2, 31865); + #endif #undef _MAX31865_0_SW #undef _MAX31865_1_SW + #undef _MAX31865_2_SW #endif #undef MAXTC_INIT @@ -541,6 +561,7 @@ volatile bool Temperature::raw_temps_ready = false; #endif #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1 + #define MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR 1 uint8_t Temperature::consecutive_low_temperature_error[HOTENDS] = { 0 }; #endif @@ -1866,6 +1887,10 @@ void Temperature::task() { if (degHotend(1) > _MIN(HEATER_1_MAXTEMP, TEMP_SENSOR_1_MAX_TC_TMAX - 1.0)) max_temp_error(H_E1); if (degHotend(1) < _MAX(HEATER_1_MINTEMP, TEMP_SENSOR_1_MAX_TC_TMIN + .01)) min_temp_error(H_E1); #endif + #if TEMP_SENSOR_IS_MAX_TC(2) + if (degHotend(2) > _MIN(HEATER_2_MAXTEMP, TEMP_SENSOR_2_MAX_TC_TMAX - 1.0)) max_temp_error(H_E2); + if (degHotend(2) < _MAX(HEATER_2_MINTEMP, TEMP_SENSOR_2_MAX_TC_TMIN + .01)) min_temp_error(H_E2); + #endif #if TEMP_SENSOR_IS_MAX_TC(REDUNDANT) if (degRedundant() > TEMP_SENSOR_REDUNDANT_MAX_TC_TMAX - 1.0) max_temp_error(H_REDUNDANT); if (degRedundant() < TEMP_SENSOR_REDUNDANT_MAX_TC_TMIN + .01) min_temp_error(H_REDUNDANT); @@ -2112,6 +2137,15 @@ void Temperature::task() { case 2: #if TEMP_SENSOR_2_IS_CUSTOM return user_thermistor_to_deg_c(CTI_HOTEND_2, raw); + #elif TEMP_SENSOR_IS_MAX_TC(2) + #if TEMP_SENSOR_0_IS_MAX31865 + return TERN(LIB_INTERNAL_MAX31865, + max31865_2.temperature(raw), + max31865_2.temperature(MAX31865_SENSOR_OHMS_2, MAX31865_CALIBRATION_OHMS_2) + ); + #else + return (int16_t)raw * 0.25; + #endif #elif TEMP_SENSOR_2_IS_AD595 return TEMP_AD595(raw); #elif TEMP_SENSOR_2_IS_AD8495 @@ -2281,6 +2315,8 @@ void Temperature::task() { return TERN(TEMP_SENSOR_REDUNDANT_IS_MAX31865, max31865_0.temperature(raw), (int16_t)raw * 0.25); #elif TEMP_SENSOR_IS_MAX_TC(REDUNDANT) && REDUNDANT_TEMP_MATCH(SOURCE, E1) return TERN(TEMP_SENSOR_REDUNDANT_IS_MAX31865, max31865_1.temperature(raw), (int16_t)raw * 0.25); + #elif TEMP_SENSOR_IS_MAX_TC(REDUNDANT) && REDUNDANT_TEMP_MATCH(SOURCE, E2) + return TERN(TEMP_SENSOR_REDUNDANT_IS_MAX31865, max31865_2.temperature(raw), (int16_t)raw * 0.25); #elif TEMP_SENSOR_REDUNDANT_IS_THERMISTOR SCAN_THERMISTOR_TABLE(TEMPTABLE_REDUNDANT, TEMPTABLE_REDUNDANT_LEN); #elif TEMP_SENSOR_REDUNDANT_IS_AD595 @@ -2316,6 +2352,9 @@ void Temperature::updateTemperaturesFromRawValues() { #if TEMP_SENSOR_IS_MAX_TC(1) temp_hotend[1].setraw(READ_MAX_TC(1)); #endif + #if TEMP_SENSOR_IS_MAX_TC(2) + temp_hotend[2].setraw(READ_MAX_TC(2)); + #endif #if TEMP_SENSOR_IS_MAX_TC(REDUNDANT) temp_redundant.setraw(READ_MAX_TC(HEATER_ID(TEMP_SENSOR_REDUNDANT_SOURCE))); #endif @@ -2347,9 +2386,14 @@ void Temperature::updateTemperaturesFromRawValues() { #else , TEMPDIR(1) #endif - #if HOTENDS > 2 + #if TEMP_SENSOR_IS_ANY_MAX_TC(2) + , 0 + #else + , TEMPDIR(2) + #endif + #if HOTENDS > 3 #define _TEMPDIR(N) , TEMPDIR(N) - REPEAT_S(2, HOTENDS, _TEMPDIR) + REPEAT_S(3, HOTENDS, _TEMPDIR) #endif #endif }; @@ -2362,15 +2406,12 @@ void Temperature::updateTemperaturesFromRawValues() { const bool heater_on = temp_hotend[e].target > 0; if (heater_on && ((neg && r > temp_range[e].raw_min) || (pos && r < temp_range[e].raw_min))) { - #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1 - if (++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED) - #endif - min_temp_error((heater_id_t)e); + if (TERN1(MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR, ++consecutive_low_temperature_error[e] >= MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED)) + min_temp_error((heater_id_t)e); + } + else { + TERN_(MULTI_MAX_CONSECUTIVE_LOW_TEMP_ERR, consecutive_low_temperature_error[e] = 0); } - #if MAX_CONSECUTIVE_LOW_TEMPERATURE_ERROR_ALLOWED > 1 - else - consecutive_low_temperature_error[e] = 0; - #endif } #endif // HAS_HOTEND @@ -2432,6 +2473,9 @@ void Temperature::init() { #if TEMP_SENSOR_IS_ANY_MAX_TC(1) && PIN_EXISTS(TEMP_1_CS) OUT_WRITE(TEMP_1_CS_PIN, HIGH); #endif + #if TEMP_SENSOR_IS_ANY_MAX_TC(2) && PIN_EXISTS(TEMP_2_CS) + OUT_WRITE(TEMP_2_CS_PIN, HIGH); + #endif // Setup objects for library-based polling of MAX TCs #if HAS_MAXTC_LIBRARIES @@ -2459,6 +2503,18 @@ void Temperature::init() { OPTARG(LIB_INTERNAL_MAX31865, MAX31865_SENSOR_OHMS_1, MAX31865_CALIBRATION_OHMS_1, MAX31865_WIRE_OHMS_1) ); #endif + + #if TEMP_SENSOR_IS_MAX(2, 6675) && HAS_MAX6675_LIBRARY + max6675_2.begin(); + #elif TEMP_SENSOR_IS_MAX(2, 31855) && HAS_MAX31855_LIBRARY + max31855_2.begin(); + #elif TEMP_SENSOR_IS_MAX(2, 31865) + max31865_2.begin( + MAX31865_WIRES(MAX31865_SENSOR_WIRES_2) // MAX31865_2WIRE, MAX31865_3WIRE, MAX31865_4WIRE + OPTARG(LIB_INTERNAL_MAX31865, MAX31865_SENSOR_OHMS_2, MAX31865_CALIBRATION_OHMS_2, MAX31865_WIRE_OHMS_2) + ); + #endif + #undef MAX31865_WIRES #undef _MAX31865_WIRES #endif @@ -2491,6 +2547,15 @@ void Temperature::init() { #endif )); #endif + #if PIN_EXISTS(TEMP_2_TR_ENABLE) + OUT_WRITE(TEMP_2_TR_ENABLE_PIN, ( + #if TEMP_SENSOR_IS_ANY_MAX_TC(2) + HIGH + #else + LOW + #endif + )); + #endif #if ENABLED(MPCTEMP) HOTEND_LOOP() temp_hotend[e].modeled_block_temp = NAN; @@ -3009,25 +3074,29 @@ void Temperature::disable_all_heaters() { // Needed to return the correct temp when this is called between readings static raw_adc_t max_tc_temp_previous[MAX_TC_COUNT] = { 0 }; #define THERMO_TEMP(I) max_tc_temp_previous[I] - #define THERMO_SEL(A,B) (hindex ? (B) : (A)) - #define MAXTC_CS_WRITE(V) do{ switch (hindex) { case 1: WRITE(TEMP_1_CS_PIN, V); break; default: WRITE(TEMP_0_CS_PIN, V); } }while(0) + #define THERMO_SEL(A,B,C) (hindex > 1 ? (C) : hindex == 1 ? (B) : (A)) + #define MAXTC_CS_WRITE(V) do{ switch (hindex) { case 1: WRITE(TEMP_1_CS_PIN, V); break; case 2: WRITE(TEMP_2_CS_PIN, V); break; default: WRITE(TEMP_0_CS_PIN, V); } }while(0) #else // When we have only 1 max tc, THERMO_SEL will pick the appropriate sensor // variable, and MAXTC_*() macros will be hardcoded to the correct CS pin. constexpr uint8_t hindex = 0; #define THERMO_TEMP(I) max_tc_temp #if TEMP_SENSOR_IS_ANY_MAX_TC(0) - #define THERMO_SEL(A,B) A + #define THERMO_SEL(A,B,C) A #define MAXTC_CS_WRITE(V) WRITE(TEMP_0_CS_PIN, V) - #else - #define THERMO_SEL(A,B) B + #elif TEMP_SENSOR_IS_ANY_MAX_TC(1) + #define THERMO_SEL(A,B,C) B #define MAXTC_CS_WRITE(V) WRITE(TEMP_1_CS_PIN, V) + #elif TEMP_SENSOR_IS_ANY_MAX_TC(2) + #define THERMO_SEL(A,B,C) C + #define MAXTC_CS_WRITE(V) WRITE(TEMP_2_CS_PIN, V) #endif #endif static TERN(HAS_MAX31855, uint32_t, uint16_t) max_tc_temp = THERMO_SEL( TEMP_SENSOR_0_MAX_TC_TMAX, - TEMP_SENSOR_1_MAX_TC_TMAX + TEMP_SENSOR_1_MAX_TC_TMAX, + TEMP_SENSOR_2_MAX_TC_TMAX ); static uint8_t max_tc_errors[MAX_TC_COUNT] = { 0 }; @@ -3062,17 +3131,17 @@ void Temperature::disable_all_heaters() { MAXTC_CS_WRITE(HIGH); // Disable MAXTC #else #if HAS_MAX6675_LIBRARY - MAX6675 &max6675ref = THERMO_SEL(max6675_0, max6675_1); + MAX6675 &max6675ref = THERMO_SEL(max6675_0, max6675_1, max6675_2); max_tc_temp = max6675ref.readRaw16(); #endif #if HAS_MAX31855_LIBRARY - MAX31855 &max855ref = THERMO_SEL(max31855_0, max31855_1); + MAX31855 &max855ref = THERMO_SEL(max31855_0, max31855_1, max31855_2); max_tc_temp = max855ref.readRaw32(); #endif #if HAS_MAX31865 - MAX31865 &max865ref = THERMO_SEL(max31865_0, max31865_1); + MAX31865 &max865ref = THERMO_SEL(max31865_0, max31865_1, max31865_2); max_tc_temp = TERN(LIB_INTERNAL_MAX31865, max865ref.readRaw(), max865ref.readRTD_with_Fault()); #endif #endif @@ -3117,7 +3186,7 @@ void Temperature::disable_all_heaters() { #endif // Set thermocouple above max temperature (TMAX) - max_tc_temp = THERMO_SEL(TEMP_SENSOR_0_MAX_TC_TMAX, TEMP_SENSOR_1_MAX_TC_TMAX) << (MAX_TC_DISCARD_BITS + 1); + max_tc_temp = THERMO_SEL(TEMP_SENSOR_0_MAX_TC_TMAX, TEMP_SENSOR_1_MAX_TC_TMAX, TEMP_SENSOR_2_MAX_TC_TMAX) << (MAX_TC_DISCARD_BITS + 1); } } else { @@ -3155,6 +3224,10 @@ void Temperature::update_raw_temperatures() { temp_hotend[1].update(); #endif + #if HAS_TEMP_ADC_2 && !TEMP_SENSOR_IS_MAX_TC(2) + temp_hotend[2].update(); + #endif + #if HAS_TEMP_ADC_REDUNDANT && !TEMP_SENSOR_IS_MAX_TC(REDUNDANT) temp_redundant.update(); #endif