From e770489f27b80dee2392746f71361baa16302df9 Mon Sep 17 00:00:00 2001 From: Scott Lahteine Date: Fri, 23 Jan 2015 10:37:39 -0800 Subject: [PATCH] Borrow from Ultimaker to fix MAX6675 SPI conflict Changes to temperature.cpp from Ultimaker fork, intended to address #1226 and #1227 --- Marlin/pins.h | 2 +- Marlin/temperature.cpp | 56 +++++++++++++++++++++++++++++------------- 2 files changed, 40 insertions(+), 18 deletions(-) diff --git a/Marlin/pins.h b/Marlin/pins.h index 57bed581a..8e084273a 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -904,7 +904,7 @@ #define SCK_PIN 52 #define MISO_PIN 50 #define MOSI_PIN 51 - #define MAX6675_SS 66// Do not use pin 53 if there is even the remote possibility of using Dsplay/SD card + #define MAX6675_SS 66// Do not use pin 53 if there is even the remote possibility of using Display/SD card #else #define MAX6675_SS 66// Do not use pin 49 as this is tied to the switch inside the SD card socket to detect if there is an SD card present #endif diff --git a/Marlin/temperature.cpp b/Marlin/temperature.cpp index f6eadaa48..22a93b646 100644 --- a/Marlin/temperature.cpp +++ b/Marlin/temperature.cpp @@ -177,6 +177,11 @@ unsigned long watchmillis[EXTRUDERS] = ARRAY_BY_EXTRUDERS(0,0,0); #ifdef FILAMENT_SENSOR static int meas_shift_index; //used to point to a delayed sample in buffer for filament width sensor #endif + +#ifdef HEATER_0_USES_MAX6675 + static int read_max6675(); +#endif + //=========================================================================== //============================= functions ============================ //=========================================================================== @@ -448,6 +453,15 @@ void manage_heater() updateTemperaturesFromRawValues(); + #ifdef HEATER_0_USES_MAX6675 + if (current_temperature[0] > 1023 || current_temperature[0] > HEATER_0_MAXTEMP) { + max_temp_error(0); + } + if (current_temperature[0] == 0 || current_temperature[0] < HEATER_0_MINTEMP) { + min_temp_error(0); + } + #endif //HEATER_0_USES_MAX6675 + for(int e = 0; e < EXTRUDERS; e++) { @@ -757,6 +771,9 @@ static float analog2tempBed(int raw) { and this function is called from normal context as it is too slow to run in interrupts and will block the stepper routine otherwise */ static void updateTemperaturesFromRawValues() { + #ifdef HEATER_0_USES_MAX6675 + current_temperature_raw[0] = read_max6675(); + #endif for(uint8_t e=0;e -1) SET_OUTPUT(HEATER_1_PIN); - #endif + #endif #if defined(HEATER_2_PIN) && (HEATER_2_PIN > -1) SET_OUTPUT(HEATER_2_PIN); #endif @@ -851,6 +868,7 @@ void tp_init() #endif #ifdef HEATER_0_USES_MAX6675 + #ifndef SDSUPPORT SET_OUTPUT(SCK_PIN); WRITE(SCK_PIN,0); @@ -860,15 +878,15 @@ void tp_init() SET_INPUT(MISO_PIN); WRITE(MISO_PIN,1); + #else + pinMode(SS_PIN, OUTPUT); + digitalWrite(SS_PIN, HIGH); #endif - /* Using pinMode and digitalWrite, as that was the only way I could get it to compile */ - //Have to toggle SD card CS pin to low first, to enable firmware to talk with SD card - pinMode(SS_PIN, OUTPUT); - digitalWrite(SS_PIN,0); - pinMode(MAX6675_SS, OUTPUT); - digitalWrite(MAX6675_SS,1); - #endif + SET_OUTPUT(MAX6675_SS); + WRITE(MAX6675_SS,1); + + #endif //HEATER_0_USES_MAX6675 // Set analog inputs ADCSRA = 1< -1) raw_temp_0_value += ADC; #endif - #ifdef HEATER_0_USES_MAX6675 // TODO remove the blocking - raw_temp_0_value = read_max6675(); - #endif temp_state = 2; break; case 2: // Prepare TEMP_BED @@ -1659,7 +1675,9 @@ ISR(TIMER0_COMPB_vect) { if (!temp_meas_ready) //Only update the raw values if they have been read. Else we could be updating them during reading. { +#ifndef HEATER_0_USES_MAX6675 current_temperature_raw[0] = raw_temp_0_value; +#endif #if EXTRUDERS > 1 current_temperature_raw[1] = raw_temp_1_value; #endif @@ -1690,14 +1708,18 @@ ISR(TIMER0_COMPB_vect) #else if(current_temperature_raw[0] >= maxttemp_raw[0]) { #endif +#ifndef HEATER_0_USES_MAX6675 max_temp_error(0); +#endif } #if HEATER_0_RAW_LO_TEMP > HEATER_0_RAW_HI_TEMP if(current_temperature_raw[0] >= minttemp_raw[0]) { #else if(current_temperature_raw[0] <= minttemp_raw[0]) { #endif +#ifndef HEATER_0_USES_MAX6675 min_temp_error(0); +#endif } #if EXTRUDERS > 1 #if HEATER_1_RAW_LO_TEMP > HEATER_1_RAW_HI_TEMP