Initialize clock chip to compile time the first time the program runs after that it will read the time from the clock chip. I find this easy since a quick recompile and load of utility sets the clock chip then we reload with the normal firmware. OK for use in low volume testing.
Dependencies: DS1302 compile_time_to_system_time mbed
Fork of DS1302_HelloWorld by
Initialize Clock To Compile Time
Initialize clock chip to compile time the first time the program runs after that it will read the time from the clock chip.
I find this an easy way to initialize my clock chip and then it stays set for as long as the battery lasts. I use a quick recompile then copy this utility to the mbed board where it sets the time and date. After than reload the mbed board with normal firmware and the clock remains set.
I use it for low volume testing.
Underlying library for parsing DATE and TIME is as follows:
The time supplied by compiler is UMT so you need to adjust for local time if needed.
Referenced
- https://developer.mbed.org/users/petereiso/notebook/cc-time-functions/
- http://stackoverflow.com/questions/1765014/convert-string-from-date-into-a-time-t
Revision 0:5e6107966aba, committed 2014-03-31
- Comitter:
- Sissors
- Date:
- Mon Mar 31 20:54:17 2014 +0000
- Child:
- 1:e747c4ea86e0
- Commit message:
- v1.0
;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/DS1302.lib Mon Mar 31 20:54:17 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/Sissors/code/DS1302/#c7cea2a415c3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Mon Mar 31 20:54:17 2014 +0000 @@ -0,0 +1,27 @@ +#define SCLK PTC5 +#define IO PTC4 +#define CE PTC3 + +//Comment this line if the DS1302 is already running +#define INITIAL_RUN + +#include "mbed.h" +#include "DS1302.h" + +DS1302 clk(SCLK, IO, PTC3); + +int main() { + #ifdef INITIAL_RUN + clk.set_time(1256729737); + #endif + + char storedByte = clk.recallByte(0); + printf("\r\nStored byte was %d, now increasing by one\r\n", storedByte); + clk.storeByte(0, storedByte + 1); + + while(1) { + time_t seconds = clk.time(NULL); + printf("Time as a basic string = %s\r", ctime(&seconds)); + wait(1); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Mon Mar 31 20:54:17 2014 +0000 @@ -0,0 +1,1 @@ +http://world3.dev.mbed.org/users/mbed_official/code/mbed/builds/824293ae5e43 \ No newline at end of file