resetForFlashing.ino 1.1 KB

1234567891011121314151617181920212223242526
  1. void resetForFlashing(int afterms) {
  2. // this can be used to flash new firmware even when serial DTS line is not connected, so no auto-reset on serial connect is performed
  3. // this schematic does not use a DTS line in order not to purge unsafed data accidentially
  4. // also it is normally not connected via USB directly, but over RS-232 with some metres of cable in between
  5. // called from serial routine, so that a serial command, iE "reset 1000" calls this function with value given
  6. // tested OK with a 1000ms delay before starting avrdude to upload the new binary
  7. saveAllCurrentData(false);
  8. Serial.print(F("saved all data, resetting in "));
  9. Serial.print(afterms);
  10. Serial.println("ms...");
  11. Serial.end();
  12. delay(afterms);
  13. //Serial.println(F("RESETTING NOW"));
  14. doHardreset();
  15. // WDT reset DOES NOT put bootloader in flash mode!!
  16. //wdt_disable();
  17. //wdt_enable(WDTO_4S);
  18. //while (1) {delay(500); Serial.print(".");}
  19. }
  20. void doHardreset() {
  21. pinMode(PIN_OUT_HARDRESET, OUTPUT);
  22. digitalWrite(PIN_OUT_HARDRESET, LOW); // pull a pin low that is connected to /RESET as WDT reset DOES NOT put bootloader in flash mode!!
  23. }