esp-open-rtos/examples/ds3231_test/ds3231_test.c

48 lines
1.1 KiB
C
Raw Permalink Normal View History

2017-09-01 09:29:32 +00:00
/* Test code for DS3231 high precision RTC module
*
* Part of esp-open-rtos
* Copyright (C) 2016 Bhuvanchandra DV <bhuvanchandra.dv@gmail.com>
* MIT Licensed as described in the file LICENSE
*/
#include "espressif/esp_common.h"
#include "esp/uart.h"
#include "FreeRTOS.h"
#include "task.h"
#include "i2c/i2c.h"
#include "ds3231/ds3231.h"
2017-09-01 09:29:32 +00:00
#define ADDR DS3231_ADDR
#define I2C_BUS 0
void task1(void *pvParameters)
{
struct tm time;
float tempFloat;
2017-09-01 09:29:32 +00:00
i2c_dev_t dev = {
.addr = ADDR,
.bus = I2C_BUS,
};
while(1) {
vTaskDelay(100);
2017-09-01 09:29:32 +00:00
ds3231_getTime(&dev, &time);
ds3231_getTempFloat(&dev, &tempFloat);
printf("TIME:%d:%d:%d, TEMPERATURE:%.2f DegC\r\n", time.tm_hour, time.tm_min, time.tm_sec, tempFloat);
}
}
void user_init(void)
{
const int scl = 5, sda = 4;
uart_set_baud(0, 115200);
printf("\n");
printf("SDK version : %s\n", sdk_system_get_sdk_version());
printf("GIT version : %s\n", GITSHORTREV);
2017-10-25 07:58:00 +00:00
i2c_init(0, scl, sda, I2C_FREQ_400K);
2016-10-21 09:40:36 +00:00
xTaskCreate(task1, "tsk1", 256, NULL, 2, NULL);
}