Datasheet

Table Of Contents
85 tight_loop_contents();
86 }
87
88 return 0;
89 }
4.9.5.3. Get the time
Pico SDK: https://github.com/raspberrypi/pico-sdk/tree/pre_release/src/rp2_common/hardware_rtc/rtc.c Lines 91 - 107
Ê91 int rtc_get_datetime(datetime_t *t) {
Ê92 // Make sure RTC is running
Ê93 if (!rtc_running()) {
Ê94 return -1;
Ê95 }
Ê96
Ê97 // Note: RTC_0 should be read before RTC_1
Ê98 t->dotw = (rtc_hw->rtc_0 & RTC_RTC_0_DOTW_BITS ) >> RTC_RTC_0_DOTW_LSB;
Ê99 t->hour = (rtc_hw->rtc_0 & RTC_RTC_0_HOUR_BITS ) >> RTC_RTC_0_HOUR_LSB;
100 t->min = (rtc_hw->rtc_0 & RTC_RTC_0_MIN_BITS ) >> RTC_RTC_0_MIN_LSB;
101 t->sec = (rtc_hw->rtc_0 & RTC_RTC_0_SEC_BITS ) >> RTC_RTC_0_SEC_LSB;
102 t->year = (rtc_hw->rtc_1 & RTC_RTC_1_YEAR_BITS ) >> RTC_RTC_1_YEAR_LSB;
103 t->month = (rtc_hw->rtc_1 & RTC_RTC_1_MONTH_BITS) >> RTC_RTC_1_MONTH_LSB;
104 t->day = (rtc_hw->rtc_1 & RTC_RTC_1_DAY_BITS ) >> RTC_RTC_1_DAY_LSB;
105
106 return 0;
107 }
4.9.5.4. Set an alarm
Pico SDK: https://github.com/raspberrypi/pico-sdk/tree/pre_release/src/rp2_common/hardware_rtc/rtc.c Lines 115 - 147
115 void rtc_set_alarm(datetime_t *t, rtc_callback_t user_callback) {
116 rtc_disable_alarm();
117
118 rtc_hw->irq_setup_0 = (t->year << RTC_IRQ_SETUP_0_YEAR_LSB ) |
119 (t->month << RTC_IRQ_SETUP_0_MONTH_LSB) |
120 (t->day << RTC_IRQ_SETUP_0_DAY_LSB);
121 rtc_hw->irq_setup_1 = (t->dotw << RTC_IRQ_SETUP_1_DOTW_LSB) |
122 (t->hour << RTC_IRQ_SETUP_1_HOUR_LSB) |
123 (t->min << RTC_IRQ_SETUP_1_MIN_LSB ) |
124 (t->sec << RTC_IRQ_SETUP_1_SEC_LSB);
125
126 // Set the match enable bits for things we care about
127 if (t->year != -1) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_YEAR_ENA_BITS);
128 if (t->month != -1) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_MONTH_ENA_BITS);
129 if (t->day != -1) hw_set_bits(&rtc_hw->irq_setup_0, RTC_IRQ_SETUP_0_DAY_ENA_BITS);
130 if (t->dotw != -1) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_DOTW_ENA_BITS);
131 if (t->hour != -1) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_HOUR_ENA_BITS);
132 if (t->min != -1) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_MIN_ENA_BITS);
133 if (t->sec != -1) hw_set_bits(&rtc_hw->irq_setup_1, RTC_IRQ_SETUP_1_SEC_ENA_BITS);
134
135 // Store function pointer we can call later
136 _callback = user_callback;
137
138 // Enable the IRQ at the peri
139 rtc_hw->inte = RTC_INTE_RTC_BITS;
RP2040 Datasheet
4.9. RTC 577