repetier / Repetier-Firmware

Firmware for Arduino based RepRap 3D printer.
812 stars 734 forks source link

Startup Sequence for I2C LCDs to prevent LCD from not initialising #215

Closed ghost closed 10 years ago

ghost commented 10 years ago

Modified setup() to work with our I2C LCDs a bit better, also provides a bit more detail logging during startup to help troubleshoot where it gets stuck

void setup() {

if defined(ENABLE_POWER_ON_STARTUP) && PS_ON_PIN>-1

out.println_P(PSTR("Initialise PSU")); SET_OUTPUT(PS_ON_PIN); //GND WRITE(PS_ON_PIN, LOW); delay(1000); out.println_P(PSTR("Turned on PSU")); UI_INITIALIZE;

endif

ifdef ANALYZER

// Channel->pin assignments

if ANALYZER_CH0>=0

SET_OUTPUT(ANALYZER_CH0);

endif

if ANALYZER_CH1>=0

SET_OUTPUT(ANALYZER_CH1);

endif

if ANALYZER_CH2>=0

SET_OUTPUT(ANALYZER_CH2);

endif

if ANALYZER_CH3>=0

SET_OUTPUT(ANALYZER_CH3);

endif

if ANALYZER_CH4>=0

SET_OUTPUT(ANALYZER_CH4);

endif

if ANALYZER_CH5>=0

SET_OUTPUT(ANALYZER_CH5);

endif

if ANALYZER_CH6>=0

SET_OUTPUT(ANALYZER_CH6);

endif

if ANALYZER_CH7>=0

SET_OUTPUT(ANALYZER_CH7);

endif

endif

if defined(ENABLE_POWER_ON_STARTUP) && PS_ON_PIN>-1

out.println_P(PSTR("Initialise PSU")); SET_OUTPUT(PS_ON_PIN); //GND WRITE(PS_ON_PIN, LOW); out.println_P(PSTR("Turned on PSU"));

endif

//Initialize Step Pins SET_OUTPUT(X_STEP_PIN); SET_OUTPUT(Y_STEP_PIN); SET_OUTPUT(Z_STEP_PIN);

//Initialize Dir Pins

if X_DIR_PIN>-1

SET_OUTPUT(X_DIR_PIN);

endif

if Y_DIR_PIN>-1

SET_OUTPUT(Y_DIR_PIN);

endif

if Z_DIR_PIN>-1

SET_OUTPUT(Z_DIR_PIN);

endif

//Steppers default to disabled.

if X_ENABLE_PIN > -1

if(!X_ENABLE_ON) WRITE(X_ENABLE_PIN,HIGH); SET_OUTPUT(X_ENABLE_PIN);

endif

if Y_ENABLE_PIN > -1

if(!Y_ENABLE_ON) WRITE(Y_ENABLE_PIN,HIGH); SET_OUTPUT(Y_ENABLE_PIN);

endif

if Z_ENABLE_PIN > -1

if(!Z_ENABLE_ON) WRITE(Z_ENABLE_PIN,HIGH); SET_OUTPUT(Z_ENABLE_PIN);

endif

//endstop pullups

if X_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_X

SET_INPUT(X_MIN_PIN);

if ENDSTOP_PULLUP_X_MIN

WRITE(X_MIN_PIN,HIGH);

endif

endif

if Y_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Y

SET_INPUT(Y_MIN_PIN);

if ENDSTOP_PULLUP_Y_MIN

WRITE(Y_MIN_PIN,HIGH);

endif

endif

if Z_MIN_PIN>-1 && MIN_HARDWARE_ENDSTOP_Z

SET_INPUT(Z_MIN_PIN);

if ENDSTOP_PULLUP_Z_MIN

WRITE(Z_MIN_PIN,HIGH);

endif

endif

if X_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_X

SET_INPUT(X_MAX_PIN);

if ENDSTOP_PULLUP_X_MAX

WRITE(X_MAX_PIN,HIGH);

endif

endif

if Y_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Y

SET_INPUT(Y_MAX_PIN);

if ENDSTOP_PULLUP_Y_MAX

WRITE(Y_MAX_PIN,HIGH);

endif

endif

if Z_MAX_PIN>-1 && MAX_HARDWARE_ENDSTOP_Z

SET_INPUT(Z_MAX_PIN);

if ENDSTOP_PULLUP_Z_MAX

WRITE(Z_MAX_PIN,HIGH);

endif

endif

if FAN_PIN>-1

SET_OUTPUT(FAN_PIN); WRITE(FAN_PIN,LOW);

endif

if FAN_BOARD_PIN>-1

SET_OUTPUT(FAN_BOARD_PIN); WRITE(FAN_BOARD_PIN,LOW);

endif

if EXT0_HEATER_PIN>-1

SET_OUTPUT(EXT0_HEATER_PIN); WRITE(EXT0_HEATER_PIN,LOW);

endif

if defined(EXT1_HEATER_PIN) && EXT1_HEATER_PIN>-1

SET_OUTPUT(EXT1_HEATER_PIN); WRITE(EXT1_HEATER_PIN,LOW);

endif

if defined(EXT2_HEATER_PIN) && EXT2_HEATER_PIN>-1

SET_OUTPUT(EXT2_HEATER_PIN); WRITE(EXT2_HEATER_PIN,LOW);

endif

if defined(EXT3_HEATER_PIN) && EXT3_HEATER_PIN>-1

SET_OUTPUT(EXT3_HEATER_PIN); WRITE(EXT3_HEATER_PIN,LOW);

endif

if defined(EXT4_HEATER_PIN) && EXT4_HEATER_PIN>-1

SET_OUTPUT(EXT4_HEATER_PIN); WRITE(EXT4_HEATER_PIN,LOW);

endif

if defined(EXT5_HEATER_PIN) && EXT5_HEATER_PIN>-1

SET_OUTPUT(EXT5_HEATER_PIN); WRITE(EXT5_HEATER_PIN,LOW);

endif

ifdef XY_GANTRY

printer_state.motorX = 0; printer_state.motorY = 0;

endif

if STEPPER_CURRENT_CONTROL!=CURRENT_CONTROL_MANUAL

current_control_init(); // Set current if it is firmware controlled

endif

microstep_init();

if USE_OPS==1

printer_state.opsMode = OPS_MODE; printer_state.opsMinDistance = OPS_MIN_DISTANCE; printer_state.opsRetractDistance = OPS_RETRACT_DISTANCE; printer_state.opsRetractBacklash = OPS_RETRACT_BACKLASH; printer_state.filamentRetracted = false;

endif

printer_state.feedrate = 50; ///< Current feedrate in mm/s. printer_state.feedrateMultiply = 100; printer_state.extrudeMultiply = 100;

ifdef USE_ADVANCE

ifdef ENABLE_QUADRATIC_ADVANCE

printer_state.advance_executed = 0;

endif

printer_state.advance_steps_set = 0; printer_state.advance_lin_set = 0;

endif

for(byte i=0;i<NUM_EXTRUDER+3;i++) pwm_pos[i]=0; printer_state.currentPositionSteps[0] = printer_state.currentPositionSteps[1] = printer_state.currentPositionSteps[2] = printer_state.currentPositionSteps[3] = 0;

if DRIVE_SYSTEM==3

calculate_delta(printer_state.currentPositionSteps, printer_state.currentDeltaPositionSteps);

endif

printer_state.maxJerk = MAX_JERK; printer_state.maxZJerk = MAX_ZJERK; printer_state.interval = 5000; printer_state.stepper_loops = 1; printer_state.msecondsPrinting = 0; printer_state.filamentPrinted = 0; printer_state.flag0 = PRINTER_FLAG0_STEPPER_DISABLED; printer_state.xLength = X_MAX_LENGTH; printer_state.yLength = Y_MAX_LENGTH; printer_state.zLength = Z_MAX_LENGTH; printer_state.xMin = X_MIN_POS; printer_state.yMin = Y_MIN_POS; printer_state.zMin = Z_MIN_POS; printer_state.waslasthalfstepping = 0;

if ENABLE_BACKLASH_COMPENSATION

printer_state.backlashX = X_BACKLASH; printer_state.backlashY = Y_BACKLASH; printer_state.backlashZ = Z_BACKLASH; printer_state.backlashDir = 0;

endif

epr_init_baudrate(); RFSERIAL.begin(baudrate); UI_STATUS_UPD_RAM("Lets Make Awesome.."); out.println_P(PSTR("----------------------------------")); out.println_P(PSTR(" Lets Make Awesome... ")); out.println_P(PSTR("----------------------------------")); out.println_P(PSTR(" Firmware modified by "));
out.println_P(PSTR(" OpenHardware.co.za ")); out.println_P(PSTR("----------------------------------")); out.println_P(PSTR(" ")); out.println_P(PSTR("SYSTEM STARTUP PROCEDURE AND SANITY CHECK")); out.println_P(PSTR(" ")); out.println_P(PSTR("Starting User Interface")); out.println_P(PSTR(" ")); delay(1000); UI_INITIALIZE; out.println_P(PSTR("UI started. LCD should now be up if connected")); out.println_P(PSTR(" ")); out.println_P(PSTR("Reason for last powerdown:"));

// Check startup - does nothing if bootloader sets MCUSR to 0 byte mcu = MCUSR; if(mcu & 1) out.println_P(PSTR("PowerUp")); if(mcu & 2) out.println_P(PSTR("External Reset")); if(mcu & 4) out.println_P(PSTR("Brown out Reset")); if(mcu & 8) out.println_P(PSTR("Watchdog Reset")); if(mcu & 32) out.println_P(PSTR("Software Reset")); MCUSR=0; out.println_P(PSTR(" "));

out.println_P(PSTR("Initialise Extruder")); out.println_P(PSTR(" "));

initExtruder(); out.println_P(PSTR("Read configuration from EEPROM")); out.println_P(PSTR(" ")); epr_init(); // Read settings from eeprom if wanted update_ramps_parameter();

if SDSUPPORT

out.println_P(PSTR("Checking if we have an SD card installed")); out.println_P(PSTR(" ")); sd.initsd(); out.println_P(PSTR(" "));

endif

if USE_OPS==1 || defined(USE_ADVANCE)

out.println_P(PSTR("Configuring OPS")); out.println_P(PSTR(" ")); EXTRUDER_TCCR = 0; // need Normal not fastPWM set by arduino init EXTRUDER_TIMSK |= (1<<EXTRUDER_OCIE); // Activate compa interrupt on timer 0

endif

out.println_P(PSTR("Checking PWM, Timers, Interrupts and Prescaler")); out.println_P(PSTR(" ")); PWM_TCCR = 0; // Setup PWM interrupt PWM_OCR = 64; PWM_TIMSK |= (1<<PWM_OCIE);

TCCR1A = 0; // Steup timer 1 interrupt to no prescale CTC mode TCCR1C = 0; TIMSK1 = 0; TCCR1B = (_BV(WGM12) | _BV(CS10)); // no prescaler == 0.0625 usec tick | 001 = clk/1 OCR1A=65500; //start off with a slow frequency. TIMSK1 |= (1<<OCIE1A); // Enable interrupt out.println_P(PSTR("Startup Completed...")); out.println_P(PSTR("----------------------------------")); out.println_P(PSTR(" ")); out.println_P(PSTR("start"));

}

repetier commented 10 years ago

Is the delay at the beginning the only thing you did to make I2C working?

ghost commented 10 years ago

Negative, theres two UI_INITIALIZEs. One in the usual spot and another after the delay. Agreed its a botch to address the symptom not the real issue.

Also, closing this as in latest version default seems to work OK now