CARME-M4 BSP  V1.5
rtc_ext.c
Go to the documentation of this file.
1 
73 #ifdef __cplusplus
74 extern "C"
75 {
76 #endif /* __cplusplus */
77 
78 /*----- Header-Files -------------------------------------------------------*/
79 #include <stm32f4xx.h> /* Processor STM32F407IG */
80 #include <i2c.h> /* CARME I2C definitions */
81 #include <rtc.h> /* CARME RTC definitions */
82 #include <rtc_ext.h> /* CARME RTC Ext definitions */
83 
84 /*----- Macros -------------------------------------------------------------*/
85 
86 /*----- Data types ---------------------------------------------------------*/
87 
88 /*----- Function prototypes ------------------------------------------------*/
89 
90 /*----- Data ---------------------------------------------------------------*/
91 
92 /*----- Implementation -----------------------------------------------------*/
100 void CARME_RTC_Ext_Init(void) {
101 
102  static uint8_t temp;
103 
105 
106  /* disable SQWE Output */
107  temp = 0x00;
109  0, &temp, 1);
110 }
111 
122 
123  static uint8_t temp;
124 
125  /* Write the seconds */
126  temp = time->sec % 10;
127  temp |= ((time->sec / 10) << 4);
128  temp &= ~(1 << 7); /* Clear the CH Bit */
130  &temp, 1);
131 
132  /* Write the minutes */
133  temp = time->min % 10;
134  temp |= ((time->min / 10) << 4);
136  &temp, 1);
137 
138  /* Write the hour */
139  temp = time->hour % 10;
140  if (time->hour / 20 > 0) {
141  temp |= (1 << 5);
142  }
143  else {
144  if (time->hour / 10 > 0) {
145  temp |= (1 << 4);
146  }
147  }
148  temp &= ~(1 << 6); /* Set the hour in 24h format */
150  0, &temp, 1);
151 
152  /* Write the day of the week */
153  temp = time->wday;
155  0, &temp, 1);
156 
157  /* Write the day */
158  temp = time->day % 10;
159  temp |= ((time->day / 10) << 4);
161  &temp, 1);
162 
163  /* Write the month */
164  temp = time->month % 10;
165  temp |= ((time->month / 10) << 4);
167  0, &temp, 1);
168 
169  /* Write the year */
170  temp = time->year % 10;
171  temp |= ((time->year / 10) << 4);
173  0, &temp, 1);
174 }
175 
185 
186  static uint8_t temp;
187 
188  /* Get the year */
190  &temp, 1);
191  time->year = temp & 0x0F;
192  time->year += ((temp & 0xF0) >> 4) * 10;
193 
194  /* Get the month */
196  0, &temp, 1);
197  time->month = temp & 0x0F;
198  time->month += ((temp & 0x10) >> 4) * 10;
199 
200  /* Get the day */
202  &temp, 1);
203  time->day = temp & 0x0F;
204  time->day += ((temp & 0x30) >> 4) * 10;
205 
206  /* Get the day of the week */
208  &temp, 1);
209  time->wday = temp & 0x07;
210 
211  /* Get the hour */
213  &temp, 1);
214  time->hour = temp & 0x0F;
215  if (temp & 0x10) {
216  time->hour += 10;
217  }
218  else {
219  if (temp & 0x20) {
220  time->hour += 20;
221  }
222  }
223 
224  /* Get the minute */
226  &temp, 1);
227  time->min = temp & 0x0F;
228  time->min += ((temp & 0x70) >> 4) * 10;
229 
230  /* Get the seconds */
232  &temp, 1);
233  time->sec = temp & 0x0F;
234  time->sec += ((temp & 0x70) >> 4) * 10;
235 }
236 
237 #ifdef __cplusplus
238 }
239 #endif /* __cplusplus */
240 
RTC interface. Communication interface to use the RTC from the CARME-M4.
#define CARME_RTC_REG_DAY
Definition: rtc_ext.h:87
uint8_t day
Definition: rtc.h:97
uint8_t month
Definition: rtc.h:98
void CARME_RTC_Ext_GetTime(CARME_RTC_TIME_t *time)
Get the Time from the external RTC on mainboard.
Definition: rtc_ext.c:184
#define CARME_I2C_BOARD
Definition: i2c.h:81
uint8_t min
Definition: rtc.h:95
uint8_t sec
Definition: rtc.h:94
#define CARME_RTC_REG_CTRL
Definition: rtc_ext.h:90
#define CARME_RTC_REG_YEAR
Definition: rtc_ext.h:89
#define CARME_RTC_I2C_ADDR
Definition: rtc_ext.h:92
uint8_t hour
Definition: rtc.h:96
ERROR_CODES CARME_I2C_Read(I2C_TypeDef *I2Cx, uint8_t addr, uint16_t reg, uint8_t twoByte, uint8_t *pdata, uint16_t count)
Read data from an I2C slave device on a specific register address.
Definition: i2c.c:312
void CARME_RTC_Ext_SetTime(CARME_RTC_TIME_t *time)
Set the Time of the external RTC on the mainboard.
Definition: rtc_ext.c:121
#define CARME_RTC_REG_MIN
Definition: rtc_ext.h:84
uint8_t wday
Definition: rtc.h:100
#define CARME_RTC_REG_SEC
Definition: rtc_ext.h:83
#define CARME_RTC_REG_HOUR
Definition: rtc_ext.h:85
void CARME_I2C_Init(I2C_TypeDef *I2Cx)
I2C initialization.
Definition: i2c.c:124
Structure to store a full date and time.
Definition: rtc.h:93
#define CARME_RTC_REG_MONTH
Definition: rtc_ext.h:88
void CARME_RTC_Ext_Init(void)
Initialize the RTC on the CARME mainboard.
Definition: rtc_ext.c:100
uint8_t year
Definition: rtc.h:99
ERROR_CODES CARME_I2C_Write(I2C_TypeDef *I2Cx, uint8_t addr, uint16_t reg, uint8_t twoByte, uint8_t *pdata, uint16_t count)
Write data to an I2C slave device on a specific register address.
Definition: i2c.c:226
Communication interface to use the RTC on the CARME mainboard.
#define CARME_RTC_REG_WDAY
Definition: rtc_ext.h:86
I2C board support package for the CARME module.