Real-time clock

28 Apr 2012

Hello

I am trying to get the real-time clock to work with the LPC1768, according to the examples at

http://mbed.org/blog/entry/103/

time(NULL) returns -1 in all cases. Is this an issue with the mbed, or something I am doing wrong? Relatedly, how does the mbed actually get these times (when it is working)?

For convenience, the code I ran is

#include "mbed.h"

int main() {
    while(1) {
        time_t seconds = time(NULL);
        printf("Seconds since January 1, 1970: %d\r\n", seconds);
        wait(1);
    }
}

with output

Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
...

As background, I am trying send data taken over a long period time from sensors with Unix timestamps. I feel that the cleanest way to do this would be for the mbed to generate these timestamps instead of the host.

Thank you

-Frank

28 Apr 2012

My bad! I forgot to set the time. I thought it would default to something, like 0.

the set_time() function is necessary

http://mbed.org/forum/helloworld/topic/2554/?page=1#comment-13207

edit:

Is there some way to sync up the time with the host, or is this a whole other project? I'd like time stamps on certain sensor values, and I want them to be accurate down to minutes at the very least. Similarly, if I sent an initial time down to the mbed from my computer - how long would this real-time clock remain accurate/synced?

thanks

28 Apr 2012

There has been a recent post, LCD clock, That gets the 'real' time from the internet.

As for the accuracy of the MBED RTC, I left a board run, With backup battery for two or three weeks, And it was within 5 or so seconds. but temperature will have quite an effect.

Hope that helps.

ceri.

30 Apr 2012

The accuracy of the clock is great news and that project is what I was looking for. Thank you very much!

01 Jun 2012

Hi do you know should i code to automatically detect a connection to the ethernet?