ds1307 - Driver for DS1307 RTC module

group ds1307

ESP-IDF driver for DS1307 real-time clock.

Ported from esp-open-rtos

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

BSD Licensed as described in the file LICENSE

Defines

DS1307_ADDR

I2C address.

Enums

enum ds1307_squarewave_freq_t

Squarewave frequency.

Values:

enumerator DS1307_1HZ

1 Hz

enumerator DS1307_4096HZ

4096 Hz

enumerator DS1307_8192HZ

8192 Hz

enumerator DS1307_32768HZ

32768 Hz

Functions

esp_err_t ds1307_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Parameters
  • dev – Device descriptor

  • port – I2C port

  • sda_gpio – SDA GPIO

  • scl_gpio – SCL GPIO

Returns

ESP_OK on success

esp_err_t ds1307_free_desc(i2c_dev_t *dev)

Free device descriptor.

Parameters

dev – Device descriptor

Returns

ESP_OK on success

esp_err_t ds1307_start(i2c_dev_t *dev, bool start)

Start/stop clock.

Parameters
  • dev – Device descriptor

  • start – Start clock if true

Returns

ESP_OK on success

esp_err_t ds1307_is_running(i2c_dev_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 ds1307_get_time(i2c_dev_t *dev, struct tm *time)

Get current time.

Parameters
  • dev – Device descriptor

  • [out] time – Pointer to the time struct to fill

Returns

ESP_OK on success

esp_err_t ds1307_set_time(i2c_dev_t *dev, const struct tm *time)

Set time to RTC.

Parameters
  • dev – Device descriptor

  • [in] time – Pointer to the time struct

Returns

ESP_OK on success

esp_err_t ds1307_enable_squarewave(i2c_dev_t *dev, bool enable)

Enable or disable square-wave oscillator output.

Parameters
  • dev – Device descriptor

  • enable – Enable oscillator if true

Returns

ESP_OK on success

esp_err_t ds1307_is_squarewave_enabled(i2c_dev_t *dev, bool *sqw_en)

Get square-wave oscillator output.

Parameters
  • dev – Device descriptor

  • [out] sqw_en – true if square-wave oscillator enabled

Returns

ESP_OK on success

esp_err_t ds1307_set_squarewave_freq(i2c_dev_t *dev, ds1307_squarewave_freq_t freq)

Set square-wave oscillator frequency.

Parameters
  • dev – Device descriptor

  • freq – Frequency

Returns

ESP_OK on success

esp_err_t ds1307_get_squarewave_freq(i2c_dev_t *dev, ds1307_squarewave_freq_t *sqw_freq)

Get current square-wave oscillator frequency.

Parameters
  • dev – Device descriptor

  • [out] sqw_freq – Frequency

Returns

ESP_OK on success

esp_err_t ds1307_get_output(i2c_dev_t *dev, bool *out)

Get current output level of the SQW/OUT pin.

Parameters
  • dev – Device descriptor

  • [out] out – current output level of the SQW/OUT pin, true if high

Returns

ESP_OK on success

esp_err_t ds1307_set_output(i2c_dev_t *dev, bool value)

Set output level of the SQW/OUT pin.

Set output level if square-wave output is disabled

Parameters
  • dev – Device descriptor

  • value – High level if true

Returns

ESP_OK on success

esp_err_t ds1307_read_ram(i2c_dev_t *dev, uint8_t offset, uint8_t *buf, uint8_t len)

Read RAM contents into the buffer.

Parameters
  • dev – Device descriptor

  • offset – Start byte, 0..55

  • [out] buf – Buffer to store data

  • len – Bytes to read, 1..56

Returns

ESP_OK on success

esp_err_t ds1307_write_ram(i2c_dev_t *dev, uint8_t offset, uint8_t *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