Skip to content

b-andreoni/rtc-driver

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DS1307 RTC Driver for ESP-IDF

This is a component for the DS1307 Real-Time Clock designed for the ESP-IDF framework.

The driver is implemented as a singleton and uses the modern i2c_master API. It provides a straightforward, function-pointer-based interface to initialize the RTC, set the time, get the time, and control other hardware features. This component also includes a full suite of unit tests.


Features ✨

  • Initialize and Deinitialize the I2C bus and RTC device.
  • Set and Get Time using a simple rtc_time_t struct (24-hour format).
  • Check Oscillator Status to ensure the clock is running.
  • Configure Square-Wave Output pin (SQW/OUT).
  • Singleton Pattern for a single, globally accessible driver instance.
  • Configurable GPIO pins and I2C settings via header definitions.
  • Includes Unit Tests using the Unity framework to validate functionality.

Hardware Connection 🔌

You need to connect the DS1307 module to the I2C pins of your ESP32. The default pins are configured in the header file, but you can change them easily.

DS1307 Module Pin ESP32 Pin
VCC 5V or 3.3V (check module)
GND GND
SDA GPIO 8 (Default, configurable)
SCL GPIO 9 (Default, configurable)

Configuration ⚙️

All main hardware configurations can be adjusted directly in the mlr_rtc.h header file.

// File: components/mlr_rtc/include/mlr_rtc.h

/** Default I2C port index (ESP-IDF modular I2C uses an index). */
#ifndef DS1307_I2C_PORT_INDEX
#define DS1307_I2C_PORT_INDEX        (0)
#endif

/** Default SDA/SCL GPIOs for the bus (adjust to your board). */
#ifndef DS1307_I2C_SDA_GPIO
#define DS1307_I2C_SDA_GPIO          (8)
#endif

#ifndef DS1307_I2C_SCL_GPIO
#define DS1307_I2C_SCL_GPIO          (9)
#endif

/** DS1307 supports Standard-Mode only (100 kHz). */
#ifndef DS1307_I2C_FREQ_HZ
#define DS1307_I2C_FREQ_HZ           (100000UL)
#endif

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published