add time readout with error handling
This commit is contained in:
parent
e26b2108ca
commit
f6f69479a5
18
main.c
18
main.c
|
@ -173,7 +173,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
|
||||
|
@ -228,10 +227,15 @@ void main(void)
|
|||
// verify is external RTC is running
|
||||
if (rtc_ds1307_oscillator_disabled()) {
|
||||
printf("/!\\ RTC oscillator is disabled: the battery may be empty\n");
|
||||
rtc_ds1307_oscillator_enable(); // enable oscillator again
|
||||
}
|
||||
// display date
|
||||
uint8_t* rtc_ds1307_time = rtc_ds1307_read_time(); // get time/date from external RTC
|
||||
printf("current date: 20%02u-%02u-%02u %02u:%02u:%02u\n", rtc_ds1307_time[6], rtc_ds1307_time[5], rtc_ds1307_time[4], rtc_ds1307_time[2], rtc_ds1307_time[1], rtc_ds1307_time[0]);
|
||||
if (rtc_ds1307_time==NULL) {
|
||||
fprintf(stderr,"could not get time from DS1307\n");
|
||||
} else {
|
||||
printf("current date: 20%02u-%02u-%02u %02u:%02u:%02u\n", rtc_ds1307_time[6], rtc_ds1307_time[5], rtc_ds1307_time[4], rtc_ds1307_time[2], rtc_ds1307_time[1], rtc_ds1307_time[0]);
|
||||
}
|
||||
|
||||
// setup TM1637
|
||||
printf("setup 7-segment display: ");
|
||||
|
@ -307,8 +311,14 @@ void main(void)
|
|||
if ((ticks_time%(60))==0) { // one minute passed
|
||||
printf("uptime: %lu.%02lu:%02lu:%02lu\n", ticks_time/(60*60*24), (ticks_time/(60*60))%24, (ticks_time%(60*60))/60, (ticks_time%60)); // display uptime
|
||||
}
|
||||
if (!led_tm1637_time(rtc_ds1307_read_minutes(), rtc_ds1307_read_seconds())) {
|
||||
fprintf(stderr,"could not set time on TM1637\n");
|
||||
rtc_ds1307_time = rtc_ds1307_read_time(); // get time/date from external RTC
|
||||
if (rtc_ds1307_time==NULL) {
|
||||
fprintf(stderr,"could not get time from DS1307: resetting\n");
|
||||
rtc_ds1307_setup(); // resetting periph
|
||||
} else {
|
||||
if (!led_tm1637_time(rtc_ds1307_time[1], rtc_ds1307_time[0])) {
|
||||
fprintf(stderr,"could not set time on TM1637\n");
|
||||
}
|
||||
}
|
||||
if (!led_tm1637_on()) { // switch on display
|
||||
fprintf(stderr,"could not switch on TM1637\n");
|
||||
|
|
Loading…
Reference in New Issue