DS1307 RTC driver + example

This commit is contained in:
UncleRus 2016-10-09 14:14:17 +05:00
parent 29bd8d832a
commit 8ded673ec3
5 changed files with 335 additions and 0 deletions

3
examples/ds1307/Makefile Normal file
View file

@ -0,0 +1,3 @@
PROGRAM = ds1307
EXTRA_COMPONENTS = extras/i2c extras/ds1307
include ../../common.mk

45
examples/ds1307/main.c Normal file
View file

@ -0,0 +1,45 @@
/*
* Example of using DS1307 RTC driver
*
* Part of esp-open-rtos
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#include <esp/uart.h>
#include <espressif/esp_common.h>
#include <i2c/i2c.h>
#include <ds1307/ds1307.h>
#include <stdio.h>
#define SCL_PIN 5
#define SDA_PIN 4
void user_init (void)
{
uart_set_baud (0, 115200);
printf ("SDK version:%s\n", sdk_system_get_sdk_version ());
i2c_init (SCL_PIN, SDA_PIN);
ds1307_start (true);
// setup datetime: 2016-10-09 13:50:10
struct tm time = {
.tm_year = 2016,
.tm_mon = 10,
.tm_mday = 9,
.tm_hour = 13,
.tm_min = 50,
.tm_sec = 10
};
ds1307_set_time (&time);
while (true)
{
ds1307_get_time (&time);
printf ("%04d-%02d-%02d %02d:%02d:%02d\n", time.tm_year, time.tm_mon, time.tm_mday, time.tm_hour, time.tm_min, time.tm_sec);
for (uint32_t i = 0; i < 1000; i ++)
sdk_os_delay_us (500);
}
}