RTC don't work

11 Sep 2012

I use this code a few times ago, to set the Real Time Clock with/from the mbed. It works well. But now I want to use it again and suddenly the time was set on 11:39, Wed, 28/10/2009 I don't know. What can I do to use the real time from mbed. Now it's 9:44, 11/09/2012. Please give me a code example. :)

That's the code:

#include "mbed.h"
#include "TextLCD.h"

TextLCD lcd(p26, p25, p24, p23, p22, p20, p19, TextLCD::LCD20x4);
Serial pc(USBTX,USBRX);

Ticker rhythm;

void myrhythm()

int main()

    while(1) {
        time_t seconds = time(NULL);

        void set_time(time_t t);

        char buffer[32];
        strftime(buffer, 32, "%H:%M:%S\n%a, %d/%m/%Y", localtime(&seconds));
        lcd.printf("%s", buffer);
        lcd.printf("BBR Verkehrstechnik\nFranziska Gerlich");

        rhythm.attach (&myrhythm, 1.0);
11 Sep 2012

You need to set the RTC to the current time, when the mbed has no power and no battery backup power its RTC won't run.

The reason you saw as date 28/10/2009 is probably because I guess you first experimented with the example code, which sets it to that date. See here: http://mbed.org/projects/libraries/api/mbed/trunk/rtc_time, I guess you will need mktime and set_time functions. Once you got the correct time in the mbed, and you make sure it always either has normal power or battery backup power, the RTC will stay correct.

11 Sep 2012

You could try this:

int Set_time_man(void) {

    struct tm t;

    t.tm_sec = 0;    // 0-59

    t.tm_min = 00;    // 0-59

    t.tm_hour = 21;   // 0-23

    t.tm_mday =3;   // 1-31

    t.tm_mon = 9;     // 0-11

    t.tm_year = 112;  // year since 1900




    LPC_RTC->CCR|=1;// active RTC