Skip to content

Commit

Permalink
Improve the dormant rtc example a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
peterharperuk committed May 24, 2024
1 parent b95c6c2 commit 2a42bf2
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions sleep/hello_dormant_rtc/hello_dormant_rtc.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
#include "hardware/rtc.h"
#include "hardware/clocks.h"

// This example needs an external clock fed into the GP20
// Note: Only GP20 and GP22 can be used for clock input, See the GPIO function table in the RP2040 datasheet.
// You can use another Pico to generate this. See the clocks/hello_gpout example for more details.
// clock_gpio_init(25, CLOCKS_CLK_GPOUT3_CTRL_AUXSRC_VALUE_CLK_RTC, 1);
#define EXTERNAL_CLOCK_INPUT_PIN 20
#define RTC_FREQ_HZ 46875

Expand Down Expand Up @@ -58,27 +62,30 @@ int main() {

stdio_init_all();
printf("Hello Dormant GPIO!\n");
printf("Switching to XOSC\n");
uart_default_tx_wait_blocking();
while(true) {
printf("Awake for 10s\n");
sleep_ms(10000);

/*Set the crystal oscillator as the dormant clock source, UART will be reconfigured from here
This is necessary before sending the pico to sleep*/
sleep_run_from_xosc();
printf("Switching to XOSC\n");
uart_default_tx_wait_blocking();

printf("Running from XOSC\n");
uart_default_tx_wait_blocking();
/*Set the crystal oscillator as the dormant clock source, UART will be reconfigured from here
This is necessary before sending the pico to sleep*/
sleep_run_from_xosc();

printf("XOSC going dormant\n");
uart_default_tx_wait_blocking();
printf("Running from XOSC\n");
uart_default_tx_wait_blocking();

// Go to sleep until the RTC interrupt is generated after 10 seconds
rtc_sleep();
printf("XOSC going dormant\n");
uart_default_tx_wait_blocking();

//Re-enabling clock sources and generators.
sleep_power_up();
// Go to sleep until the RTC interrupt is generated after 10 seconds
rtc_sleep();

printf("ROSC restarted!\n");
//Re-enabling clock sources and generators.
sleep_power_up();

printf("ROSC restarted!\n");
}
return 0;
}

0 comments on commit 2a42bf2

Please sign in to comment.