GlobLib
HAL and API libraries for MCUs and hardware.
|
This module contains functions for working with the real time clock. More...
Files | |
file | stm32f103cb_rtc.h |
Header file for stm32f103cb real time clock (RTC) | |
Functions | |
mcu_error | RTC_setup (uint32_t resolution) |
Initialize the Real time clock. More... | |
mcu_error | RTC_calibrate (uint32_t resolution) |
Calibrate the RTC to a given resolution in milliseconds. More... | |
mcu_error | RTC_setPrescaler (uint32_t resolution) |
Set the raw prescaler value of the RTC. More... | |
uint8_t | RTC_isAlarmEnabled (void) |
Determine if the alarm interrupt is enabled. More... | |
uint8_t | RTC_isOverflowEnabled (void) |
Determine if the overflow interrupt is enabled. More... | |
uint8_t | RTC_isResolutionEnabled (void) |
Determine if the resolution (second) interrupt is enabled. More... | |
uint32_t | RTC_getCount (void) |
Get the current count value. More... | |
void | RTC_setCount (uint32_t count) |
Set the current count value. More... | |
void | RTC_enableResolutionISR (void(*res_isr)(void)) |
Enables the resolution ISR. More... | |
void | RTC_enableAlarmISR (uint32_t count, void(*al_isr)(void)) |
Enables the alarm ISR. More... | |
void | RTC_enableOverflowISR (void(*ov_isr)(void)) |
Enables the overflow ISR. More... | |
void | RTC_disableResolutionISR (void) |
disables the resolution ISR. | |
void | RTC_disableAlarmISR (void) |
disables the alarm ISR. | |
void | RTC_disableOverflowISR (void) |
disables the overflow ISR. | |
void | RTC_clockEnable (void) |
Enable the RTC clock. More... | |
This module contains functions for working with the real time clock.
The real time clock works with the internal LSI oscillator, this runs at approximately 40kHz. This clock functions seperate from the main clock and can be used in standby mode to wake the core from sleep state. This is acheived by setting the alarm to the desired wakeup time.
Both the counter and alarm registers are 32 bits wide, for a 1 second tick this is approximately 136 years before an overflow event occurs! At 1ms it is 7 weeks. The prescaler is 20 bits wide, giving a meer 3600 years as a maximum value.
The accuracy of the RTC increases with increasing resolution approximated as
and so on. These values assume RTC_calibrate() was used to determine the preload value.
There are three interrupts which can be generated with the RTC
mcu_error RTC_calibrate | ( | uint32_t | resolution | ) |
Calibrate the RTC to a given resolution in milliseconds.
This function uses SYSTICK to calculate the required RTC prescaler. SYSTICK must not be used for any other function while this is being called. After complete SYSTICK can be utalised again.
This function will take as long as the resultion to complete!
resolution | The required resolution of the RTC in milliseconds. |
Definition at line 64 of file stm32f103cb_rtc.c.
void RTC_clockEnable | ( | void | ) |
Enable the RTC clock.
This can be used to renable the clock after system has been in stop mode.
Definition at line 96 of file stm32f103cb_rtc.c.
void RTC_enableAlarmISR | ( | uint32_t | count, |
void(*)(void) | al_isr | ||
) |
Enables the alarm ISR.
This interrupt occurs when the counter value matches the alarm value.
count | The value at which the count register triggers the interrupt. |
al_isr | The function to call on interrupt. |
Definition at line 133 of file stm32f103cb_rtc.c.
void RTC_enableOverflowISR | ( | void(*)(void) | ov_isr | ) |
Enables the overflow ISR.
This interrupt occurs when the counter register overflows (never)
ov_isr | The function to call on interrupt. |
Definition at line 155 of file stm32f103cb_rtc.c.
void RTC_enableResolutionISR | ( | void(*)(void) | res_isr | ) |
Enables the resolution ISR.
This interrupt occurs each resoultion time value.
res_isr | The function to call on interrupt. |
Definition at line 111 of file stm32f103cb_rtc.c.
uint32_t RTC_getCount | ( | void | ) |
Get the current count value.
Definition at line 101 of file stm32f103cb_rtc.c.
uint8_t RTC_isAlarmEnabled | ( | void | ) |
Determine if the alarm interrupt is enabled.
Definition at line 147 of file stm32f103cb_rtc.c.
uint8_t RTC_isOverflowEnabled | ( | void | ) |
Determine if the overflow interrupt is enabled.
Definition at line 168 of file stm32f103cb_rtc.c.
uint8_t RTC_isResolutionEnabled | ( | void | ) |
Determine if the resolution (second) interrupt is enabled.
Definition at line 124 of file stm32f103cb_rtc.c.
void RTC_setCount | ( | uint32_t | count | ) |
Set the current count value.
count | The current value to set the count to |
Definition at line 90 of file stm32f103cb_rtc.c.
mcu_error RTC_setPrescaler | ( | uint32_t | resolution | ) |
Set the raw prescaler value of the RTC.
This value determines the period of the count incrementation. Usage of RTC_calabrate() superseeds the need for this function.
resolution | The value written the the RTC prescaler register. |
Definition at line 49 of file stm32f103cb_rtc.c.
mcu_error RTC_setup | ( | uint32_t | resolution | ) |
Initialize the Real time clock.
This must be called before any other feature is used.
The resolution here is loaded directly to the prescalar register. The final period of the clock can be estimated using
period (ms) = (resolution/4)
This doesn't produce a very accurate result, and if possible RTC_calibrate should be called following this funcition. This automatically sets the period to the desired value.
resolution | The value written to the prescaler register |
Definition at line 33 of file stm32f103cb_rtc.c.