   trace << PSTR("control:") << bin << control << endl;
   trace.flush();
 
+  // Set calibration (from error measurement)
+#if defined(RTC_CALIBRATION_MS)
+  RTC::clock.calibration(RTC_CALIBRATION_MS);
+#endif
+#if defined(WATCHDOG_CALIBRATION_MS)
+  Watchdog::clock.calibration(WATCHDOG_CALIBRATION_MS);
+#endif
+
   // Synchronize clocks
   while (clkPin.is_set()) yield();
   ASSERT(rtc.get_time(now));
   now.to_binary();
   RTC::clock.time(now);
   Watchdog::clock.time(now);
-
-  // Set calibration (from error measurement)
-#if defined(RTC_CALIBRATION_MS)
-  RTC::clock.calibration(RTC_CALIBRATION_MS);
-#endif
-#if defined(WATCHDOG_CALIBRATION_MS)
-  Watchdog::clock.calibration(WATCHDOG_CALIBRATION_MS);
-#endif
 }
 
 void loop()

#include "Cosa/Watchdog.hh"
#include "Cosa/Trace.hh"
#include "Cosa/IOStream/Driver/UART.hh"
#include "Cosa/Memory.h"

// Set the real-time clock
// #define SET_TIME

// Example calibration values for internal clocks
// 1. Pro-Mini Clone (white reset button)
#define RTC_CALIBRATION_MS 0
#define WATCHDOG_CALIBRATION_MS 25
// 2. Pro-Mini Clone (red reset button)
// #define RTC_CALIBRATION_MS 0
// #define WATCHDOG_CALIBRATION_MS 0

// The real-time device, latest start and sample time in ram
DS1307 rtc;

  uart.begin(57600);
  trace.begin(&uart, PSTR("CosaDS1307: started"));

  // Print calibration
#if defined(RTC_CALIBRATION_MS)
  trace << PSTR("RTC:calibration:") << RTC_CALIBRATION_MS << endl;
#endif
#if defined(WATCHDOG_CALIBRATION_MS)
  trace << PSTR("Watchdog:calibration:") << WATCHDOG_CALIBRATION_MS << endl;
#endif

  // Start the watchdog and internal real-time clock
  Watchdog::begin();
