DS1307 Real-Time Clock driver for STM32
This repository contains a driver for the popular DS1307 real-time clock by Maxim Integrated, written in C. From the DS1307 datasheet:
The DS1307 serial real-time clock (RTC) is a lowpower, full binary-coded decimal (BCD) clock/calendar plus 56 bytes of NV SRAM. Address and data are transferred serially through an I2C, bidirectional bus. The clock/calendar provides seconds, minutes, hours, day, date, month, and year information. The end of the month date is automatically adjusted for months with fewer than 31 days, including corrections for leap year.
The driver implements allows for easy use of all essential DS1307 functions, including setting and retrieving time and date, configuring square wave output, and writing and reading from the RAM registers.
This driver works with any STM32F4 (Arm Cortex M4) out-of-the-box, and was tested on an STM32 Black Pill board (STM32F401CDU6). Making this driver compatible with other STM32Fx-series MCUs can be achieved by simply changing the included HAL support header in Inc/ds1307.h.
Add Inc/ds1307.h and Src/ds1307.c to your STM32 project in the corresponding folders. main.c provides a usage example of the driver on an STM32F4xx MCU, where UART serial output is set up to initialize the driver, set a time and date, and write the time and date to the serial port every 5 seconds. Note that main.c will not build on its own; it depends on MCU-specific code generated via STM32CubeMX.