I'm wrestling with my new STM32F411 nucleo board and the built-in RTC.
I've connected a lithium coin cell to the VBAT pin, so the RTC should keep time. After rebooting, however, the time has been reset to 1970.
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
time_t seconds = time(NULL);
printf("Time as seconds since January 1, 1970 = %d\n\r", seconds);
printf("RTC example\n\r");
set_time(1420070400);
printf("Date and time are set.\n\r");
while(1) {
time_t seconds = time(NULL);
printf("Time as seconds since January 1, 1970 = %d\n\r", seconds);
myled = !myled;
wait(1);
}
}
The output:
Time as seconds since January 1, 1970 = -1265437696
RTC example
Date and time are set.
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070401
Time as seconds since January 1, 1970 = 1420070402
Time as seconds since January 1, 1970 = 1420070403
Time as seconds since January 1, 1970 = 1420070404
Time as seconds since January 1, 1970 = 1420070405
Time as seconds since January 1, 1970 = 1420070406
Now I hit the reset button
Time as seconds since January 1, 1970 = -1265437696
RTC example
Date and time are set.
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070401
Time as seconds since January 1, 1970 = 1420070402
Time as seconds since January 1, 1970 = 1420070403
Time as seconds since January 1, 1970 = 1420070404
Time as seconds since January 1, 1970 = 1420070405
Time as seconds since January 1, 1970 = 1420070406
Time as seconds since January 1, 1970 = 1420070406
How can I get the RTC to cooperate?
I'm wrestling with my new STM32F411 nucleo board and the built-in RTC.
I've connected a lithium coin cell to the VBAT pin, so the RTC should keep time. After rebooting, however, the time has been reset to 1970.
<<code>>
#include "mbed.h"
DigitalOut myled(LED1);
int main() {
time_t seconds = time(NULL);
printf("Time as seconds since January 1, 1970 = %d\n\r", seconds);
printf("RTC example\n\r");
set_time(1420070400);
printf("Date and time are set.\n\r");
while(1) {
time_t seconds = time(NULL);
printf("Time as seconds since January 1, 1970 = %d\n\r", seconds);
myled = !myled;
wait(1);
}
}
<</code>>
The output:
<<code>>
Time as seconds since January 1, 1970 = -1265437696
RTC example
Date and time are set.
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070401
Time as seconds since January 1, 1970 = 1420070402
Time as seconds since January 1, 1970 = 1420070403
Time as seconds since January 1, 1970 = 1420070404
Time as seconds since January 1, 1970 = 1420070405
Time as seconds since January 1, 1970 = 1420070406
<</code>>
Now I hit the reset button
<<code>>
Time as seconds since January 1, 1970 = -1265437696
RTC example
Date and time are set.
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070400
Time as seconds since January 1, 1970 = 1420070401
Time as seconds since January 1, 1970 = 1420070402
Time as seconds since January 1, 1970 = 1420070403
Time as seconds since January 1, 1970 = 1420070404
Time as seconds since January 1, 1970 = 1420070405
Time as seconds since January 1, 1970 = 1420070406
Time as seconds since January 1, 1970 = 1420070406
<</code>>
How can I get the RTC to cooperate?
set_time(1420070400); < right here you are not setting the time to a constant? >
You will have to change it to set the time to the time of your boot up.
I think that is the issue.
Rob :)
set_time(1420070400); < right here you are not setting the time to a constant? >
You will have to change it to set the time to the time of your boot up.
I think that is the issue.
Rob :)
Hi Tom,\\
Please try my program. Before using the program, you need to change BAT pin hardware connection.\\
Please refer following link.\\
[[/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/]]\\
Kenji
I will try this tomorrow, and report my results here. Thanks!
Edit: Damn, used my private account for this post, instead of my work account. Oh well...
<<quote SPKRMAN15>>
set_time(1420070400); < right here you are not setting the time to a constant? >
You will have to change it to set the time to the time of your boot up.
I think that is the issue.
Rob :)
<</quote>>
I also print the time before setting this constant, which returns -1265437696.
<<quote kenjiArai>>
Hi Tom,\\
Please try my program. Before using the program, you need to change BAT pin hardware connection.\\
Please refer following link.\\
[[/users/kenjiArai/notebook/nucleo-series-rtc-control-under-power-onoff-and-re/]]\\
Kenji
<</quote>>
I will try this tomorrow, and report my results here. Thanks!
Edit: Damn, used my private account for this post, instead of my work account. Oh well...
Important Information for this Arm website
This site uses cookies to store information on your computer.
By continuing to use our site, you consent to our cookies.
If you are not happy with the use of these cookies, please review our
Cookie Policy
to learn how they can be disabled.
By disabling cookies, some features of the site will not work.
Access Warning
You do not have the correct permissions to perform this operation.
I'm wrestling with my new STM32F411 nucleo board and the built-in RTC. I've connected a lithium coin cell to the VBAT pin, so the RTC should keep time. After rebooting, however, the time has been reset to 1970.
#include "mbed.h" DigitalOut myled(LED1); int main() { time_t seconds = time(NULL); printf("Time as seconds since January 1, 1970 = %d\n\r", seconds); printf("RTC example\n\r"); set_time(1420070400); printf("Date and time are set.\n\r"); while(1) { time_t seconds = time(NULL); printf("Time as seconds since January 1, 1970 = %d\n\r", seconds); myled = !myled; wait(1); } }The output:
Now I hit the reset button
How can I get the RTC to cooperate?