Reference

Last revision 2025/12/08

This article is a comprehensive reference for the DFRobot_SD3031 library, offering detailed API descriptions for managing time and alarms in RTC modules.

Library

API Description

  /**
   * @struct sTimeData_t
   * @brief Structure for storing time data
   */
  typedef struct{
    uint16_t year;
    uint8_t  month;
    uint8_t  day;
    String   week;
    uint8_t  hour;
    uint8_t minute;
    uint8_t second;
  }sTimeData_t;

  /**
   * @fn getRTCTime
   * @brief Get information of year in RTC module
   * @return Return the obtained year 
   */
  sTimeData_t getRTCTime(void);

  /**
   * @fn getAMorPM
   * @brief output AM or PM of time
   * @return AM or PM, 24 hours mode return empty string
   */
  String getAMorPM();

  /**
   * @brief Set clock as 24-hour or 12-hour format
   * @param mode Clock calculation method
   */
  void setHourSystem(eHours_t mode){ _mode = mode; };

  /**
   * @fn setTime
   * @brief Set time into RTC and take effect immediately
   * @param year 2000~2099
   * @param month 1~12
   * @param day 1~31
   * @param week 0~6
   * @param hour 0~23
   * @param minute 0~59
   * @param second 0~59
   * @return None
   */
  void setTime(uint16_t year, uint8_t month, uint8_t day, uint8_t hour, uint8_t minute, uint8_t second);

  /**
   * @fn setAlarm
   * @brief Set the data for triggering alarm
   * @param year 2000~2099
   * @param month 1~12
   * @param day 1~31
   * @return None
   */
  void setAlarm(uint16_t year, uint8_t month, uint8_t day);

  /**
   * @enum eWeek_t
   * @brief The day of week enumeration
   */
  typedef enum{
    eSunday    = 0x01,
    eMonday    = 0x02,
    eTuesday   = 0x04,
    eWednesday = 0x08,
    eThursday  = 0x10,
    eFriday    = 0x20,
    eSaturday  = 0x40,
    eEveryDay  = 0x7f,
    eWorkday   = 0x3e,
  }eWeek_t;

  /**
   * @fn setAlarm
   * @brief Set the Alarmnumber object
   * @param week 
   * @n ---------------------------------------------------------------------------------------------------------
   * @n |    bit7    |    bit6    |    bit5    |    bit4    |    bit3    |    bit2    |    bit1    |    bit0    |
   * @n ---------------------------------------------------------------------------------------------------------
   * @n |            |  Saturday  |  Friday    |  Thursday  | Wednesday  |  Tuesday   |  Monday    |  Sunday    |
   * @n ---------------------------------------------------------------------------------------------------------                  
   * @param hour 0~23
   * @param minute 0~59
   * @param second 0~59
   */
  void setAlarm(uint8_t week,uint8_t hour, uint8_t minute, uint8_t second);

Was this article helpful?

ON THIS PAGE

TOP