RTC not ticking?

28 Dec 2009

I tried the following example from the RTC page on MBED LPC1768:

 

 

#include "mbed.h"

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

 

 

and all I'm getting is:
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
Seconds since January 1, 1970: -1
...
Am I missing something? I only plugged in USB cable, no breakout on any of the pins. Do I need to supply VB?
28 Dec 2009

You need to initialise the RTC using set_time:

You need to do this after powerup before using the RTC, but the RTC will then continue running over resets and as long as some power is connected (which could be a 3v battery on Vb).

Simon 

28 Dec 2009

Thanks! Using set_time() fixed it. This was not at all obvious from the API page you referred to:

Simon Ford wrote:
http://mbed.org/projects/libraries/api/mbed/trunk/rtc_time#set_time

Maybe it makes sense to mention it there for others.

 

--

Ilya