ds3231.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #pragma once
  2. #ifndef DS3231_H
  3. #define DS3231_H
  4. /**
  5. * @brief Clock sructure.
  6. * @note structure of ds3231 data.
  7. */
  8. typedef struct {
  9. /**
  10. * @brief 00h: Seconds
  11. */
  12. uint8_t Sec;
  13. /**
  14. * @brief 01h: Minutes
  15. */
  16. uint8_t Min;
  17. /**
  18. * @brief 02h: Hours
  19. */
  20. uint8_t Hr;
  21. /**
  22. * @brief 03h: Week Day
  23. */
  24. uint8_t WD;
  25. /**
  26. * @brief 04h: Day of Month
  27. */
  28. uint8_t Day;
  29. /**
  30. * @brief 05h: Month
  31. */
  32. uint8_t Mon;
  33. /**
  34. * @brief 06h: Year
  35. */
  36. uint8_t Year;
  37. /**
  38. * @brief 07h: Alarm 1 Seconds
  39. */
  40. uint8_t A1SS;
  41. /**
  42. * @brief 08h: Alarm 1 Minutes
  43. */
  44. uint8_t A1MM;
  45. /**
  46. * @brief 09h: Alarm 1 Hours
  47. */
  48. uint8_t A1HH;
  49. /**
  50. * @brief 0Ah: Alarm 1 Day / Date
  51. */
  52. uint8_t A1DD;
  53. /**
  54. * @brief 0Bh: Alarm 2 Minutes
  55. */
  56. uint8_t A2MM;
  57. /**
  58. * @brief 0Ch: Alarm 2 Hours
  59. */
  60. uint8_t A2HH;
  61. /**
  62. * @brief 0Dh: Alarm 2 Day / Date
  63. */
  64. uint8_t A2DD;
  65. /**
  66. * @brief 0Eh: Control
  67. */
  68. uint8_t Ctrl;
  69. /**
  70. * @brief 0Fh: Control/Status
  71. */
  72. uint8_t CtSt;
  73. /**
  74. * @brief 10h: Aging Offset
  75. */
  76. uint8_t AgOffset;
  77. /**
  78. * @brief 11h: MSB of Temp
  79. */
  80. uint8_t TempH;
  81. /**
  82. * @brief 12h: LSB of Temp
  83. */
  84. uint8_t TempL;
  85. } rtc_t;
  86. i2c_status_t RTC_Init(void);
  87. i2c_status_t RTC_ReadAll(rtc_t * data);
  88. i2c_status_t RTC_ReadTime(rtc_t * data);
  89. i2c_status_t RTC_WriteTimeCalendar(rtc_t * data);
  90. i2c_status_t RTC_WriteTime(rtc_t * data);
  91. i2c_status_t RTC_WriteHHMM(rtc_t * data);
  92. i2c_status_t RTC_WriteCalendar(rtc_t * data);
  93. uint8_t bcd2bin(uint8_t bcd);
  94. uint8_t bin2bcd(uint8_t bin);
  95. #endif // DS3231_H