summaryrefslogtreecommitdiff
path: root/examples/burst.c
diff options
context:
space:
mode:
Diffstat (limited to 'examples/burst.c')
-rw-r--r--examples/burst.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/burst.c b/examples/burst.c
new file mode 100644
index 0000000..e8c166e
--- /dev/null
+++ b/examples/burst.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include "ds1302.h"
+
+int main(int argc, char ** argv) {
+ if(!bcm2835_init()) {
+ printf("Unable to init bcm2835\n");
+ return 0;
+ }
+
+ struct tm *now, rtc;
+ time_t rawTime;
+ time(&rawTime);
+ struct ds1302_spi_session session = {RPI_GPIO_P1_23, RPI_GPIO_P1_24, RPI_GPIO_P1_21 };
+
+ ds1302_spi_session_start(&session);
+
+ ds1302_getCalendarTime(&session, &rtc);
+ printf("DS1302 Time:\t %s", asctime(&rtc));
+
+ now = gmtime(&rawTime);
+ printf("Host Time:\t %s", asctime(now));
+
+ printf("Setting ds1302 time to host time\n");
+ ds1302_setCalendarTime(&session, now);
+
+ ds1302_getCalendarTime(&session, &rtc);
+ printf("DS1302 Time:\t %s", asctime(&rtc));
+
+ ds1302_spi_session_end(&session);
+ return 0;
+}