RTC.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * RTC.h
  3. *
  4. * Created on: 14 janv. 2019
  5. * Author: e_rcluze
  6. *
  7. * Penser a ajouter les fonction de lecture ecriture dans le fichier i2c.c "générer"
  8. *
  9. *
  10. *
  11. void readRTC(uint8_t add, uint8_t *tab, int len){
  12. uint8_t ad[1];
  13. ad[0]=add;
  14. HAL_StatusTypeDef res;
  15. res = HAL_I2C_Master_Transmit(&hi2c?,RTC_ADD,ad,1,1000);
  16. res = HAL_I2C_Master_Receive(&hi2c?,RTC_ADD,tab,len,1000);
  17. }
  18. void writeRTC(uint8_t add, uint8_t *tab, int len){
  19. uint8_t ad[len+1];
  20. ad[0]=add;
  21. for (int i = 0; i< len;i++){
  22. ad[i+1]=tab[i];
  23. }
  24. HAL_StatusTypeDef res;
  25. res = HAL_I2C_Master_Transmit(&hi2c3,RTC_ADD,ad,len+1,1000);
  26. }
  27. *
  28. */
  29. #ifndef RTC_H
  30. #define RTC_H
  31. #include <stdint.h>
  32. #define RTC_ADD 0XD0
  33. #define CENTIEM 0X00
  34. #define SECOND 0X01
  35. #define MINUTES 0X02
  36. #define HOURS 0X03
  37. #define DAYWEEK 0X04
  38. #define DAY 0X05
  39. #define MONTHS 0X06
  40. #define YEAR 0X07
  41. #define CALIBRATION 0X08
  42. #define WATCHDOG 0X09
  43. #define ALARM_MONTH 0X0A
  44. #define ALARM_DAY 0X0B
  45. #define ALARM_HOURS 0X0C
  46. #define ALARM_MINUTES 0X0D
  47. #define ALARM_SECOND 0X0E
  48. #define FLAGS 0X0F
  49. #define TIMER_VALUE 0X10
  50. #define TIMER_CONTROL 0X11
  51. #define ANALOG_CALIBRATION 0X12
  52. #define SQW 0X13
  53. typedef struct {
  54. uint8_t second;
  55. uint8_t minute;
  56. uint8_t heure;
  57. uint8_t jour;
  58. uint8_t joursemaine;
  59. uint8_t mois;
  60. uint8_t annee;
  61. }Date;
  62. typedef struct {
  63. uint8_t minute;
  64. uint8_t heure;
  65. }Heure;
  66. extern void readRTC(uint8_t add, uint8_t *tab, int len);
  67. extern void writeRTC(uint8_t add, uint8_t *tab, int len);
  68. void readHeure(Heure *heure);
  69. void readDate(Date *date);
  70. void redemareRTC();
  71. void writeDate(Date *date);
  72. /**
  73. * Fonction qui permet de tester le matériel
  74. */
  75. void testRTC();
  76. void testBatteryRTC();
  77. #endif /* RTC_H */