| BlueNRG-1 Peripherals drivers Examples

- Main Page
- Modules
- Classes
- Files

- File List
- File Members

RTC_Clockwatch_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : RTC_Clockwatch_main.c
4 * Author : VMA DIVISION
5 * Version : 1.0.0
6 * Date : 21-September-2015
7 * Description : Code demostrating the RTC clockwatch functionality
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
164 /* Includes ------------------------------------------------------------------*/
165 #include "BlueNRG1.h"
166 #include "BlueNRG1_conf.h"
167 #include "SDK_EVAL_Config.h"
168
181 /* Private typedef -----------------------------------------------------------*/
182 /* Private define ------------------------------------------------------------*/
183
185 #define SET_HOUR 23 /*< Set hour to the RTC */
186 #define SET_MINUTE 59 /*< Set minute to the RTC */
187 #define SET_SECOND 31 /*< Set second to the RTC */
188 #define SET_WEEKDAY 7 /*< Set weekday to the RTC */
189 #define SET_DAY 1 /*< Set day to the RTC */
190 #define SET_MONTH 12 /*< Set month to the RTC */
191 #define SET_YEAR 2014 /*< Set year to the RTC */
192
193 /* Match event set to: 2nd of December 2014, 0 hour 0 min and 1 seconds */
194 #define MATCH_HOUR 00 /*< Match hour to generate interrupt */
195 #define MATCH_MINUTE 00 /*< Match minute to generate interrupt */
196 #define MATCH_SECOND 01 /*< Match second to generate interrupt */
197 #define MATCH_WEEKDAY 01 /*< Match weekday to generate interrupt */
198 #define MATCH_DAY 02 /*< Match day to generate interrupt */
199 #define MATCH_MONTH 12 /*< Match month to generate interrupt */
200 #define MATCH_YEAR 2014 /*< Match year to generate interrupt */
201
202 /* 500 ms period setting */
203 #define RTC_PERIOD_500ms ((32768-1)/2)
204
205 /* Private macro -------------------------------------------------------------*/
206 /* Private variables ---------------------------------------------------------*/
207 /* Private function prototypes -----------------------------------------------*/
208 void RTC_Timer_Configuration(void);
209 void RTC_Clockwatch_Configuration(void);
210
211 /* Private functions ---------------------------------------------------------*/
212
218 int main(void)
219 {
220 /* System initialization function */
221 SystemInit();
222
223 /* Identify BlueNRG1 platform */
224 SdkEvalIdentification();
225
226 /* LED initialization */
227 SdkEvalLedInit(LED1);
228 SdkEvalLedInit(LED2);
229
230 /* Configure RTC in timer mode to generate interrupt each 0.5s */
231 RTC_Timer_Configuration();
232
233 /* Configure RTC in clockwatch mode to generate interrupt on time and date match */
234 RTC_Clockwatch_Configuration();
235
236 /* Infinite loop */
237 while(1);
238 }
239
240
246 void RTC_Timer_Configuration(void)
247 {
248 RTC_InitType RTC_Init_struct;
249 NVIC_InitType NVIC_InitStructure;
250
251 SysCtrl_PeripheralClockCmd(CLOCK_PERIPH_RTC, ENABLE);
252
253 RTC_Init_struct.RTC_operatingMode = RTC_TIMER_PERIODIC;
254 RTC_Init_struct.RTC_PATTERN_SIZE = 1 - 1;
255 RTC_Init_struct.RTC_TLR1 = RTC_PERIOD_500ms;
256 RTC_Init_struct.RTC_PATTERN1 = 0x00;
257 RTC_Init(&RTC_Init_struct);
258
259 /* Enable RTC Timer interrupt*/
260 RTC_IT_Config(RTC_IT_TIMER, ENABLE);
261 RTC_IT_Clear(RTC_IT_TIMER);
262
267 for (volatile uint16_t i=0; i<300; i++) {
268 __asm("NOP");
269 }
270
271 /* Set the RTC_IRQn interrupt priority and enable it */
272 NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
273 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = LOW_PRIORITY;
274 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
275 NVIC_Init(&NVIC_InitStructure);
276
277 /* Enable RTC */
278 RTC_Cmd(ENABLE);
279 }
280
286 void RTC_Clockwatch_Configuration(void)
287 {
288 RTC_DateTimeType RTC_DateTime;
289
290 /* Set the present time and date */
291 RTC_DateTime.Second = SET_SECOND;
292 RTC_DateTime.Minute = SET_MINUTE;
293 RTC_DateTime.Hour = SET_HOUR;
294 RTC_DateTime.WeekDay = SET_WEEKDAY;
295 RTC_DateTime.MonthDay = SET_DAY;
296 RTC_DateTime.Month = SET_MONTH;
297 RTC_DateTime.Year = SET_YEAR;
298 RTC_SetTimeDate(&RTC_DateTime);
299
300 /* Set the present time and date match */
301 RTC_DateTime.Second = MATCH_SECOND;
302 RTC_DateTime.Minute = MATCH_MINUTE;
303 RTC_DateTime.Hour = MATCH_HOUR;
304 RTC_DateTime.WeekDay = MATCH_WEEKDAY;
305 RTC_DateTime.MonthDay = MATCH_DAY;
306 RTC_DateTime.Month = MATCH_MONTH;
307 RTC_DateTime.Year = MATCH_YEAR;
308 RTC_SetMatchTimeDate(&RTC_DateTime);
309
310 /* Enable RTC clock watch interrupt */
311 RTC_IT_Config( RTC_IT_CLOCKWATCH, ENABLE);
312 RTC_IT_Clear(RTC_IT_CLOCKWATCH);
313
314 /* Enable RTC clockwatch */
315 RTC_ClockwatchCmd(ENABLE);
316 }
317
318
319
320 #ifdef USE_FULL_ASSERT
321
328 void assert_failed(uint8_t* file, uint32_t line)
329 {
330 /* User can add his own implementation to report the file name and line number,
331 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
332
333 /* Infinite loop */
334 while (1)
335 {
336 }
337 }
338
339 #endif
340
353 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
RTC_PERIOD_500ms
#define RTC_PERIOD_500ms
Definition: RTC_Clockwatch_main.c:203
MATCH_SECOND
#define MATCH_SECOND
Definition: RTC_Clockwatch_main.c:196
SET_HOUR
#define SET_HOUR
Definition: RTC_Clockwatch_main.c:185
main
int main(void)
Main program code.
Definition: RTC_Clockwatch_main.c:218
RTC_Clockwatch_Configuration
void RTC_Clockwatch_Configuration(void)
RTC clockwatch configuration.
Definition: RTC_Clockwatch_main.c:286
SET_MONTH
#define SET_MONTH
Definition: RTC_Clockwatch_main.c:190
MATCH_WEEKDAY
#define MATCH_WEEKDAY
Definition: RTC_Clockwatch_main.c:197
SET_SECOND
#define SET_SECOND
Definition: RTC_Clockwatch_main.c:187
SET_MINUTE
#define SET_MINUTE
Definition: RTC_Clockwatch_main.c:186
SET_YEAR
#define SET_YEAR
Definition: RTC_Clockwatch_main.c:191
SET_WEEKDAY
#define SET_WEEKDAY
Definition: RTC_Clockwatch_main.c:188
MATCH_DAY
#define MATCH_DAY
Definition: RTC_Clockwatch_main.c:198
RTC_Timer_Configuration
void RTC_Timer_Configuration(void)
RTC Configuration.
Definition: RTC_Clockwatch_main.c:246
MATCH_MINUTE
#define MATCH_MINUTE
Definition: RTC_Clockwatch_main.c:195
MATCH_HOUR
#define MATCH_HOUR
Definition: RTC_Clockwatch_main.c:194
MATCH_MONTH
#define MATCH_MONTH
Definition: RTC_Clockwatch_main.c:199
SET_DAY
#define SET_DAY
Definition: RTC_Clockwatch_main.c:189
MATCH_YEAR
#define MATCH_YEAR
Definition: RTC_Clockwatch_main.c:200