summaryrefslogtreecommitdiff
path: root/examples/burst.c
blob: e8c166e811921e55351e3ea56d37eec3d2e24186 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}