Datasheet

Table Of Contents
NOTE
While it is possible to change the CLKDIV_M1 on the fly, it is not recommended.
4.9.4.2. Setting up the clock
Write a near-future time to RTC setup registers. Write a 1 to the LOAD bit in the CTRL register, (this bit is self-clearing).
Then, at the appropriate time, enable the RTC using the ENABLE bit in the CTRL register. The RTC_ACTIVE bit in CTRL can
be read to confirm the RTC is running.
4.9.4.2.1. Adjusting the clock while running
It is possible to change the current time while the RTC is running. Write the desired values, then set the LOAD bit in the
CTRL register.
4.9.4.3. Reading the current time
TO DO: LIAM/ANDRAS: Sample code? Not all the time fields fit into one register read. To ensure a consistent value, we
need to read register RTC_0 first and RTC_1 after, in this order. Reading RTC_0 will read the live value and save a copy of
the data needed for RTC_1.
4.9.4.4. One-off alarm
TO DO: LIAM/ANDRAS: Sample code? Let’s say we want to set up an alarm for the 2026 solar eclipse
(https://moonblink.info/Eclipse/eclipse/2026_08_12). The total eclipse begins at 16:57:54 UT on 12 August, 2026. Write
the desired value into the setup_irq registers. No need to write the day of the week, it is redundant in this case. Enable
matching on all fields except for the day of the week, and enable global matching. Obviously, the RTC interrupt should be
enabled in the processor as well (outside the scope of this note)
Disable matching with an atomic write:
IRQ_SETUP_0.MATCH_ENA = 0
and wait until the status confirms that the matching became inactive
IRQ_SETUP_0.MATCH_ACTIVE = 0
Now it is safe to program the registers:
IRQ_SETUP_1.DOTW_ENA = 0
IRQ_SETUP_1.HOUR_ENA = 1
IRQ_SETUP_1.MIN_ENA = 1
IRQ_SETUP_1.SEC_ENA = 1
IRQ_SETUP_1.HOUR = 16
IRQ_SETUP_1.MIN = 57
IRQ_SETUP_1.SEC = 54
IRQ_SETUP_0.YEAR_ENA = 1
IRQ_SETUP_0.MONTH_ENA = 1
IRQ_SETUP_0.DAY_ENA = 1
IRQ_SETUP_0.YEAR = 2026
IRQ_SETUP_0.MONTH = 8
IRQ_SETUP_0.DAY = 12
Now, enable matching with an atomic write
IRQ_SETUP_0.MATCH_ENA = 1
and wait until the status confirms that the matching became active
RP2040 Datasheet
4.9. RTC 574