Check RTC LSE(External Xtal, 32.768kHz) mode
Please refer follow links.
My notebook
http://developer.mbed.org/users/kenjiArai/notebook/nucleo-series-clock-structure-and-xtal-oscillation/
Q&A for RTC Xtal
http://developer.mbed.org/questions/4531/RTC-External-Crystal-Nucleo/
Diff: main.cpp
- Revision:
- 3:921a09e41147
- Parent:
- 2:8b6a8cfa173a
- Child:
- 4:56a0cbad89b0
diff -r 8b6a8cfa173a -r 921a09e41147 main.cpp --- a/main.cpp Sat Nov 01 00:35:50 2014 +0000 +++ b/main.cpp Sat Nov 01 01:48:56 2014 +0000 @@ -16,6 +16,9 @@ //#define USE_TEXT_LCD +#define CHECK_RTC +//#define SET_RTC + // Include --------------------------------------------------------------------------------------- #include "mbed.h" #ifdef USE_TEXT_LCD @@ -29,6 +32,7 @@ #ifdef USE_TEXT_LCD TextLCD lcd(p22, p21, p8, p7, p6, p5,TextLCD::LCD40x2); // rs, e, d4-d7 #endif +Timer t; // RAM ------------------------------------------------------------------------------------------- @@ -66,17 +70,62 @@ //------------------------------------------------------------------------------------------------- // Control Program //------------------------------------------------------------------------------------------------- -// Help Massage -void msg_hlp (void) +#if defined(CHECK_RTC) +#if defined(TARGET_NUCLEO_F401RE) || defined(TARGET_NUCLEO_F411RE) || defined(TARGET_NUCLEO_L152RE) +int main() { - PRINTF("t - Check and set RTC"); - put_rn(); - PRINTF("/ - Show time every second (Esc -> hit any key)"); - put_rn(); - PRINTF("? - Help"); - put_rn(); + while(true) + { + while (!READABLE()){ + PRINTF("Please hit any key to start measure\r"); + } + PRINTF("\r\nSelect RTC clock source\r\n"); + t.reset(); + t.start(); + CheckRTC(); + t.stop(); + PRINTF("Use special function (extend time-out)\r\n"); + PRINTF("Start-up time was %f sec. (Time-out setting:%f sec.)\r\n", + t.read(), (float)(float)TIMEOUT/1000); + switch (get_RTCSEL()) { + case 0: // no clock + PRINTF("No clock"); + break; + case 1: // LSE + PRINTF("Use LSE"); + break; + case 2: // LSI + PRINTF("Use LSI"); + break; + case 3: // HSE + PRINTF("Use HSE"); + break; + default: // Not come here + PRINTF("?"); + break; + } + PRINTF("\r\n"); + CheckRTC(); + if (get_RTCSEL() == 2) { + PRINTF("Use LSI again"); + } + PRINTF("\r\nRepeat again? [y/n]\r\n"); + PRINTF(" If yes, please pusch [RESET] buttom.\r\n"); + PRINTF(" recomend to remove USB connecter then re-plug it.\r\n"); + PRINTF(" If no, please hit any key.\r\n"); + if (GETC()){ + break; + } + } + PRINTF("next\r\n"); + CheckRTC(); } +#else +#warning "Cannot use this function. Please comment out #define CHECK_RTC and use #define SET_RTC +#endif +#elif defined(SET_RTC) // defined(CHECK_RTC) + int main() { char *ptr; @@ -169,6 +218,19 @@ } } +#endif // defined(SET_RTC) + +// Help Massage +void msg_hlp (void) +{ + PRINTF("t - Check and set RTC"); + put_rn(); + PRINTF("/ - Show time every second (Esc -> hit any key)"); + put_rn(); + PRINTF("? - Help"); + put_rn(); +} + // Put \r\n void put_rn (void) {