Struct stm32f1xx_hal::rtc::Rtc
source · pub struct Rtc<CS = RtcClkLse> { /* private fields */ }
Expand description
Real time clock
A continuously running clock that counts seconds¹. It is part of the backup domain which means that the counter is not affected by system resets or standby mode. If Vbat is connected, it is not reset even if the rest of the device is powered off. This allows it to be used to wake the CPU when it is in low power mode.
See examples/rtc.rs and examples/blinky_rtc.rs for usage examples.
1: Unless configured to another frequency using select_frequency
Implementations§
source§impl Rtc<RtcClkLse>
impl Rtc<RtcClkLse>
sourcepub fn new(regs: RTC, bkp: &mut BackupDomain) -> Self
pub fn new(regs: RTC, bkp: &mut BackupDomain) -> Self
Initialises the RTC. The BackupDomain
struct is created by
Rcc.bkp.constrain()
.
The frequency is set to 1 Hz.
Since the RTC is part of the backup domain, The RTC counter is not reset by normal resets or power cycles where (VBAT) still has power. Use set_time if you want to reset the counter.
source§impl Rtc<RtcClkHseDiv128>
impl Rtc<RtcClkHseDiv128>
pub fn new_hse(regs: RTC, bkp: &mut BackupDomain, hse: Hertz) -> Self
source§impl<CS> Rtc<CS>
impl<CS> Rtc<CS>
sourcepub fn select_frequency(&mut self, frequency: Hertz)
pub fn select_frequency(&mut self, frequency: Hertz)
Selects the frequency of the RTC Timer NOTE: Maximum frequency of 16384 Hz using the internal LSE
sourcepub fn set_time(&mut self, counter_value: u32)
pub fn set_time(&mut self, counter_value: u32)
Set the current RTC counter value to the specified amount
sourcepub fn set_alarm(&mut self, counter_value: u32)
pub fn set_alarm(&mut self, counter_value: u32)
Sets the time at which an alarm will be triggered
This also clears the alarm flag if it is set
sourcepub fn listen_alarm(&mut self)
pub fn listen_alarm(&mut self)
Enables the RTC interrupt to trigger when the counter reaches the alarm value. In addition, if the EXTI controller has been set up correctly, this function also enables the RTCALARM interrupt.
sourcepub fn unlisten_alarm(&mut self)
pub fn unlisten_alarm(&mut self)
Stops the RTC alarm from triggering the RTC and RTCALARM interrupts
sourcepub fn current_time(&self) -> u32
pub fn current_time(&self) -> u32
Reads the current counter
sourcepub fn listen_seconds(&mut self)
pub fn listen_seconds(&mut self)
Enables triggering the RTC interrupt every time the RTC counter is increased
sourcepub fn unlisten_seconds(&mut self)
pub fn unlisten_seconds(&mut self)
Disables the RTC second interrupt
sourcepub fn clear_second_flag(&mut self)
pub fn clear_second_flag(&mut self)
Clears the RTC second interrupt flag
sourcepub fn clear_alarm_flag(&mut self)
pub fn clear_alarm_flag(&mut self)
Clears the RTC alarm interrupt flag
sourcepub fn wait_alarm(&mut self) -> Result<(), Infallible>
pub fn wait_alarm(&mut self) -> Result<(), Infallible>
Return Ok(())
if the alarm flag is set, Err(nb::WouldBlock)
otherwise.
use nb::block;
rtc.set_alarm(rtc.read_counts() + 5);
// NOTE: Safe unwrap because Infallible can't be returned
block!(rtc.wait_alarm()).unwrap();