From 58b6823627eb43233904af4cc069ac7847526d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?King=20K=C3=A9vin?= Date: Fri, 13 Oct 2017 15:50:25 +0200 Subject: [PATCH] application: use new DCF77 interface --- application.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/application.c b/application.c index 5e45835..d42a1ff 100644 --- a/application.c +++ b/application.c @@ -382,7 +382,6 @@ void main(void) { rcc_clock_setup_in_hse_8mhz_out_72mhz(); // use 8 MHz high speed external clock to generate 72 MHz internal clock - #if DEBUG // enable functionalities for easier debug DBGMCU_CR |= DBGMCU_CR_IWDG_STOP; // stop independent watchdog counter when code is halted @@ -524,19 +523,11 @@ void main(void) while (rtc_dcf77_time_flag) { // the DCF77 module received a new time rtc_dcf77_time_flag = false; // reset flag action = true; // action has been performed - uint8_t* dcf77_time = rtc_dcf77_time(); // get time - if (dcf77_time) { // ensure it's valid - ticks_time = dcf77_time[1]*TICKS_HOUR+dcf77_time[0]*TICKS_MINUTE; // calculate new time -#if defined(EXTERNAL_RTC) && EXTERNAL_RTC - rtc_ds1307_ticks = ticks_time; // set new time - rtc_ds1307_write_time(0, dcf77_time[0], dcf77_time[1], ((dcf77_time[3]+1)%8)+1, dcf77_time[2], dcf77_time[4], dcf77_time[5]); // set date and time - rtc_ds1307_oscillator_enable(); // be sure the oscillation is enabled -#else + if (rtc_dcf77_time.valid) { // ensure decoded time is valid + ticks_time = rtc_dcf77_time.hours*TICKS_HOUR+rtc_dcf77_time.minutes*TICKS_MINUTE+rtc_dcf77_time.seconds*TICKS_SECOND+(rtc_dcf77_time.milliseconds*TICKS_SECOND)/1000; // calculate new time rtc_set_counter_val(ticks_time); // set new time to internal RTC -#endif - printf("DCF77 time: 20%02u-%02u-%02u %02u:%02u:00\n", dcf77_time[5], dcf77_time[4], dcf77_time[2], dcf77_time[1], dcf77_time[0]); // display time - rtc_dcf77_off(); // switch DCF77 off since we have correct time - printf("DCF77 receiver switched off\n"); // notify user + printf("DCF77 time: 20%02u-%02u-%02u %02u:%02u:%02u\n", rtc_dcf77_time.year, rtc_dcf77_time.month, rtc_dcf77_time.day, rtc_dcf77_time.hours, rtc_dcf77_time.minutes, rtc_dcf77_time.seconds); // display time + // never switch of DCF77 receiver since the signal gets better demodulated with time, we always have power, we can always get correct the time } else { printf("DCF77 time: error\n"); } @@ -554,10 +545,11 @@ void main(void) if ((ticks_time%TICKS_MINUTE)==0) { // one minute passed printf("%02u:%02u:%02u\n", ticks_time/TICKS_HOUR, (ticks_time%TICKS_HOUR)/TICKS_MINUTE, (ticks_time%TICKS_MINUTE)/TICKS_SECOND); // display external time } + if ((ticks_time%(TICKS_MINUTE*5))==0) { // five minutes passed + rtc_dcf77_on(); // ensure the module is on in case it switched off because of decoding issues + } if ((ticks_time%TICKS_HOUR)==0) { // one hours passed clock_hours(); // show hour markers - rtc_dcf77_on(); // switch DCF77 on to update/correct time - printf("DCF77 receiver switched on\n"); // notify user } if (ticks_time>=TICKS_MIDDAY*2) { // one day passed rtc_set_counter_val(rtc_get_counter_val()%TICKS_MIDDAY); // reset time counter