ds1302 - Driver for DS1302 RTC module

group ds1302

ESP-IDF driver for DS1302 RTC.

Ported from esp-open-rtos

Copyright (C) 2016, 2019 Ruslan V. Uss unclerus@gmail.com

Copyright (C) 2016 Pavel Merzlyakov

merzlyakovpavel@gmail.com

BSD Licensed as described in the file LICENSE

Defines

DS1302_RAM_SIZE

Functions

esp_err_t ds1302_init(ds1302_t *dev)

Initialize device.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t ds1302_start(ds1302_t *dev, bool start)

Start/stop clock.

Parameters
  • dev – Device descriptor

  • start – Start clock if true

Returns

ESP_OK on success

esp_err_t ds1302_is_running(ds1302_t *dev, bool *running)

Get current clock state.

Parameters
  • dev – Device descriptor

  • [out] running – true if clock running

Returns

ESP_OK on success

esp_err_t ds1302_set_write_protect(ds1302_t *dev, bool wp)

Enable/disable write protection.

Parameters
  • dev – Device descriptor

  • wp – Set RTC write-protected if true

Returns

ESP_OK on success

esp_err_t ds1302_get_write_protect(ds1302_t *dev, bool *wp)

Get write protection status.

Parameters
  • dev – Device descriptor

  • [out] wp – true if RTC write-protected

Returns

ESP_OK on success

esp_err_t ds1302_get_time(ds1302_t *dev, struct tm *time)

Get current time.

Parameters
  • dev – Device descriptor

  • [out] time – Current time

Returns

ESP_OK on success

esp_err_t ds1302_set_time(ds1302_t *dev, const struct tm *time)

Set time to RTC.

Parameters
  • dev – Device descriptor

  • time – Time

Returns

ESP_OK on success

esp_err_t ds1302_read_sram(ds1302_t *dev, uint8_t offset, void *buf, uint8_t len)

Read RAM contents into the buffer.

Parameters
  • dev – Device descriptor

  • offset – Start byte, 0..55

  • [out] buf – Buffer

  • len – Bytes to read, 1..56

Returns

ESP_OK on success

esp_err_t ds1302_write_sram(ds1302_t *dev, uint8_t offset, void *buf, uint8_t len)

Write buffer to RTC RAM.

Parameters
  • dev – Device descriptor

  • offset – Start byte, 0..55

  • buf – Buffer

  • len – Bytes to write, 1..56

Returns

ESP_OK on success

struct ds1302_t
#include <ds1302.h>

Device descriptor.