10 years, 7 months ago.

How to use RTC at STM32F401 EVB?

Hello,

I try to use the accurate RTC at this EVB but this example is not using the RTC because it is very inaccurate. How can I start the RTC?

Inaccurate example:

  1. include "mbed.h"

DigitalOut myled(LED1);

int main() {

printf("RTC example\n"); set_time(1387188323); Set RTC time to 16 December 2013 10:05:23 UTC printf("Date and time are set.\n");

while(1) {

time_t seconds = time(NULL);

printf("Time as seconds since January 1, 1970 = %d\n", seconds);

printf("Time as a basic string = %s\n", ctime(&seconds));

char buffer[32]; strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds)); printf("Time as a custom formatted string = %s", buffer);

myled = !myled; wait(1); } }

Regards, Martin

2 Answers

10 years, 7 months ago.

I just saw this question, there are some issues here.

If you fit the crystals and loading capacitors to the Nucleo boards, the RTC does work and keep time (on some boards).

HOWEVER, do not waste your time, the RTC function is useless with these boards as they reset the RTC time registers on a hard reset or power down with or without a back up RTC cell fitted.

Despite many requests to ST, they continue not to function correctly.

What is needed is a talented, top notch guy (that I do not believe ST have) to find the issue and make the necessary changes if that is possible of course without huge set up code changes.

If you want true RTC functionality, the Freescale KL22F and K20D50M (and Teensy3.1 if it ever makes the platform page) do work properly along with the Mbed LPC1768. Others may work as well but have not tried them.

Accepted Answer
10 years, 7 months ago.

It is using the RTC, but no RTC crystal is populated, so it instead uses an internal oscillator which is of course nowhere near as accurate as an external crystal.

If you populate an RTC crystal at the relevant location (the Nucleo manual should tell you where that is I think), it should automatically switch to RTC crystal.

Hi Erik, thanks for your answer. But there is an external 32.768kHz crystal X2 populated, with all Cs and Rs connected to uC.

posted by Martin Baumbach 19 Aug 2015