Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: cobaLCDJoyMotor_Thread odometry_omni_3roda_v3 odometry_omni_3roda_v1 odometry_omni_3roda_v2 ... more
Diff: features/unsupported/tests/KL25Z/rtc/main.cpp
- Revision:
- 0:b74591d5ab33
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/features/unsupported/tests/KL25Z/rtc/main.cpp Mon Dec 11 17:54:04 2017 +0000
@@ -0,0 +1,72 @@
+#include "mbed.h"
+
+DigitalOut status_led(LED_BLUE);
+DigitalOut error_led(LED_RED);
+
+extern "C" void RTC_IRQHandler(void) {
+ error_led = 0;
+}
+
+extern "C" void RTC_Seconds_IRQHandler(void) {
+ error_led = 0;
+}
+
+extern "C" void HardFault_Handler(void) {
+ error_led = 0;
+}
+
+extern "C" void NMI_Handler_Handler(void) {
+ error_led = 0;
+}
+
+void rtc_init(void) {
+ // enable the clock to SRTC module register space
+ SIM->SCGC6 |= SIM_SCGC6_RTC_MASK;
+ SIM->SOPT1 = (SIM->SOPT1 & ~SIM_SOPT1_OSC32KSEL_MASK) | SIM_SOPT1_OSC32KSEL(0);
+
+ // disable interrupts
+ NVIC_DisableIRQ(RTC_Seconds_IRQn);
+ NVIC_DisableIRQ(RTC_IRQn);
+
+ // Reset
+ RTC->CR = RTC_CR_SWR_MASK;
+ RTC->CR &= ~RTC_CR_SWR_MASK;
+
+ // Allow write
+ RTC->CR = RTC_CR_UM_MASK | RTC_CR_SUP_MASK;
+
+ NVIC_EnableIRQ(RTC_Seconds_IRQn);
+ NVIC_EnableIRQ(RTC_Seconds_IRQn);
+
+ printf("LR: 0x%x\n", RTC->LR);
+ printf("CR: 0x%x\n", RTC->CR);
+ wait(1);
+ if (RTC->SR & RTC_SR_TIF_MASK){
+ RTC->TSR = 0;
+ }
+ RTC->TCR = 0;
+
+ // After setting this bit, wait the oscillator startup time before enabling
+ // the time counter to allow the clock time to stabilize
+ RTC->CR |= RTC_CR_OSCE_MASK;
+ for (volatile int i=0; i<0x600000; i++);
+
+ //enable seconds interrupts
+ RTC->IER |= RTC_IER_TSIE_MASK;
+
+ // enable time counter
+ RTC->SR |= RTC_SR_TCE_MASK;
+
+
+}
+
+int main() {
+ error_led = 1;
+ rtc_init();
+
+ while (true) {
+ wait(1);
+ status_led = !status_led;
+ printf("%u\n", RTC->TSR);
+ }
+}