/** * @brief This function handles External lines 15 to 10 interrupt request. * @param None * @retval None */ void EXTI15_10_IRQHandler(void) { /* TimeStamp Event detected */ if(EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET) { /* Turn LED4 ON */ STM_EVAL_LEDOn(LED4); printf("\r\n******************** TimeStamp Event Occurred ********************"); /* Clear the TAMPER Button EXTI line pending bit */ EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE); } /* To display Current RTC Time and Date Calendar */ if(EXTI_GetITStatus(KEY_BUTTON_EXTI_LINE) != RESET) { /* Turn LED4 ON */ STM_EVAL_LEDOn(LED4); /* Clear the KEY Button EXTI line pending bit */ EXTI_ClearITPendingBit(KEY_BUTTON_EXTI_LINE); /* Display the Time */ RTC_TimeShow(); /* Display the date */ RTC_DateShow(); /* Display the TimeStamp */ RTC_TimeStampShow(); } }
/** * @brief This function handles External lines 15 to 10 interrupt request. * @param None * @retval None */ void EXTI15_10_IRQHandler(void) { /* TimeStamp Event detected */ if(EXTI_GetITStatus(TAMPER_BUTTON_EXTI_LINE) != RESET) { count++; /* Turn on LED2 and off LED1 */ STM_EVAL_LEDOn(LED2); STM_EVAL_LEDOff(LED1); /* LCD display */ LCD_ClearLine(LCD_LINE_2); LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) "TimeStamp Event Occurred " ); /* Display the TimeStamp */ RTC_TimeStampShow(); /* Display the date */ RTC_DateShow(); /* Display the Time */ RTC_TimeShow(); /* Clear the TAMPER Button EXTI line pending bit */ EXTI_ClearITPendingBit(TAMPER_BUTTON_EXTI_LINE); } }
/** * @brief Main program. * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f0xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f0xx.c file */ /* USARTx configured as follow: - BaudRate = 115200 baud - Word Length = 8 Bits - One Stop Bit - No parity - Hardware flow control disabled (RTS and CTS signals) - Receive and transmit enabled */ USART_InitStructure.USART_BaudRate = 115200; USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_1; USART_InitStructure.USART_Parity = USART_Parity_No; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; STM_EVAL_COMInit(COM1, &USART_InitStructure); /* GPIOC Periph clock enable */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Output a message on Hyperterminal using printf function */ printf("\n\r *********************** RTC Time Stamp Example ***********************\n\r"); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; /* Check on RTC init */ if (RTC_Init(&RTC_InitStructure) == ERROR) { printf("\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n\r"); } /* Configure the time register */ RTC_TimeRegulate(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n Power On Reset occurred....\n\r"); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n External Reset occurred....\n\r"); } printf("\r\n No need to configure RTC....\n\r"); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time/Date and TimeStamp Time/Date */ RTC_TimeShow(); RTC_DateShow(); RTC_TimeStampShow(); } /* Configure the external interrupt "TAMPER" and "Joystick SEL" buttons */ STM_EVAL_PBInit(BUTTON_TAMPER, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_KEY, BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL, BUTTON_MODE_EXTI); /* Configure LED1 */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDOn(LED1); /* Infinite loop */ while (1) { } }
/** * @brief Returns the time entered by user, using Hyperterminal. * @param None * @retval None */ void RTC_TimeRegulate(void) { uint32_t tmp_hh = 0xFF, tmp_mm = 0xFF, tmp_ss = 0xFF; printf("\n\r==============Time Settings=====================================\n\r"); RTC_TimeStructure.RTC_H12 = RTC_H12_AM; printf(" Please Set Hours\n\r"); while (tmp_hh == 0xFF) { tmp_hh = USART_Scanf(0, 23); RTC_TimeStructure.RTC_Hours = tmp_hh; } printf(": %0.2d\n\r", tmp_hh); printf(" Please Set Minutes\n\r"); while (tmp_mm == 0xFF) { tmp_mm = USART_Scanf(0, 59); RTC_TimeStructure.RTC_Minutes = tmp_mm; } printf(": %0.2d\n\r", tmp_mm); printf(" Please Set Seconds\n\r"); while (tmp_ss == 0xFF) { tmp_ss = USART_Scanf(0, 59); RTC_TimeStructure.RTC_Seconds = tmp_ss; } printf(": %0.2d\n\r", tmp_ss); /* Configure the RTC time register */ if(RTC_SetTime(RTC_Format_BIN, &RTC_TimeStructure) == ERROR) { printf("\n\r>> !! RTC Set Time failed. !! <<\n\r"); } else { printf("\n\r>> !! RTC Set Time success. !! <<\n\r"); RTC_TimeShow(); /* Indicator for the RTC configuration */ RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2); } tmp_hh = 0xFF; tmp_mm = 0xFF; tmp_ss = 0xFF; printf("\n\r==============Date Settings=====================================\n\r"); printf(" Please Set WeekDay (01-07)\n\r"); while (tmp_hh == 0xFF) { tmp_hh = USART_Scanf(1, 7); RTC_DateStructure.RTC_WeekDay = tmp_hh; } printf(": %0.2d\n\r", tmp_hh); tmp_hh = 0xFF; printf(" Please Set Date (01-31)\n\r"); while (tmp_hh == 0xFF) { tmp_hh = USART_Scanf(1, 31); RTC_DateStructure.RTC_Date = tmp_hh; } printf(": %0.2d\n\r", tmp_hh); printf(" Please Set Month (01-12)\n\r"); while (tmp_mm == 0xFF) { tmp_mm = USART_Scanf(1, 12); RTC_DateStructure.RTC_Month = tmp_mm; } printf(": %0.2d\n\r", tmp_mm); printf(" Please Set Year (00-99)\n\r"); while (tmp_ss == 0xFF) { tmp_ss = USART_Scanf(0, 99); RTC_DateStructure.RTC_Year = tmp_ss; } printf(": %0.2d\n\r", tmp_ss); /* Configure the RTC date register */ if(RTC_SetDate(RTC_Format_BIN, &RTC_DateStructure) == ERROR) { printf("\n\r>> !! RTC Set Date failed. !! <<\n\r"); } else { printf("\n\r>> !! RTC Set Date success. !! <<\n\r"); RTC_DateShow(); /* Indicator for the RTC configuration */ RTC_WriteBackupRegister(RTC_BKP_DR0, 0x32F2); } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup files (startup_stm32f40xx.s/startup_stm32f427x.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ /* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */ STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_WAKEUP , BUTTON_MODE_EXTI); /* Initialize LEDs and LCD available on EVAL board */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); /* Initialize the LCD */ LCD_Init(); LCD_Clear(LCD_COLOR_WHITE); /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_BLUE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_WHITE); LCD_DisplayStringLine(LCD_LINE_0,(uint8_t *) " TimeStamp Example " ); LCD_SetFont(&Font12x12); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the time&date register */ RTC_TimeRegulate(); /* Display the Date and Time */ RTC_DateShow(); RTC_TimeShow(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_WHITE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "Power On Reset occurred " ); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_WHITE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) "External Reset occurred " ); } /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_WHITE); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_GREEN); LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) "No need to configure RTC " ); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time/Date and TimeStamp Time/Date */ RTC_DateShow(); RTC_TimeShow(); } while (1) { } }
/** * @brief Main program * @param None * @retval None */ void RTCTime_Test(void) { uart_init(); /* Output a message on Hyperterminal using printf function */ printf("\n\r *********************** RTC Time Stamp Example ***********************\n\r"); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the RTC data register and RTC prescaler */ RTC_InitStructure.RTC_AsynchPrediv = AsynchPrediv; RTC_InitStructure.RTC_SynchPrediv = SynchPrediv; RTC_InitStructure.RTC_HourFormat = RTC_HourFormat_24; /* Check on RTC init */ if (RTC_Init(&RTC_InitStructure) == ERROR) { printf("\n\r /!\\***** RTC Prescaler Config failed ********/!\\ \n\r"); } /* Configure the time register */ RTC_TimeRegulate(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { printf("\r\n Power On Reset occurred....\n\r"); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { printf("\r\n External Reset occurred....\n\r"); } printf("\r\n No need to configure RTC....\n\r"); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time/Date and TimeStamp Time/Date */ RTC_TimeShow(); RTC_DateShow(); RTC_TimeStampShow(); } PUTOUT_KeyInit(); while (1) { } }
/** * @brief Main program * @param None * @retval None */ int main(void) { /*!< At this stage the microcontroller clock setting is already configured, this is done through SystemInit() function which is called from startup file (startup_stm32f4xx.s) before to branch to application main. To reconfigure the default setting of SystemInit() function, refer to system_stm32f4xx.c file */ #if defined (RTC_CLOCK_SOURCE_LSI) /* Enable the LSI OSC */ RCC_LSICmd(ENABLE); #endif /* RTC_CLOCK_SOURCE_LSI */ /* Configure the external interrupt "WAKEUP" and "TAMPER" buttons */ STM_EVAL_PBInit(BUTTON_TAMPER , BUTTON_MODE_EXTI); STM_EVAL_PBInit(BUTTON_SEL , BUTTON_MODE_EXTI); /* Configure LEDs */ STM_EVAL_LEDInit(LED1); STM_EVAL_LEDInit(LED2); STM_EVAL_LEDOn(LED1); /* Initialize the LCD */ #ifdef USE_STM320518_EVAL STM320518_LCD_Init(); #else STM32072B_LCD_Init(); #endif /* USE_STM320518_EVAL */ /* Clear the LCD */ LCD_Clear(White); /* Enable The Display */ LCD_DisplayOn(); /* Set the LCD Back Color and Text Color*/ LCD_SetBackColor(Blue); LCD_SetTextColor(White); LCD_DisplayStringLine(LCD_LINE_0,(uint8_t *) " TimeStamp Example " ); /* Set the LCD Text size */ LCD_SetFont(&Font16x24); if (RTC_ReadBackupRegister(RTC_BKP_DR0) != 0x32F2) { /* RTC configuration */ RTC_Config(); /* Configure the time&date register */ RTC_TimeRegulate(); /* Display the Date */ RTC_DateShow(); /* Display the Time */ RTC_TimeShow(); } else { /* Check if the Power On Reset flag is set */ if (RCC_GetFlagStatus(RCC_FLAG_PORRST) != RESET) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_BLACK); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) " Power On Reset occurred " ); } /* Check if the Pin Reset flag is set */ else if (RCC_GetFlagStatus(RCC_FLAG_PINRST) != RESET) { /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_BLACK); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_2,(uint8_t *) " External Reset occurred " ); } /* Set the Back Color */ LCD_SetBackColor(LCD_COLOR_CYAN); /* Set the Text Color */ LCD_SetTextColor(LCD_COLOR_BLACK); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_3,(uint8_t *) " No need to configure RTC " ); /* Enable the PWR clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE); /* Allow access to RTC */ PWR_BackupAccessCmd(ENABLE); /* Wait for RTC APB registers synchronisation */ RTC_WaitForSynchro(); /* Clear the RTC Alarm Flag */ RTC_ClearFlag(RTC_FLAG_ALRAF); /* Clear the EXTI Line 17 Pending bit (Connected internally to RTC Alarm) */ EXTI_ClearITPendingBit(EXTI_Line17); /* Display the RTC Time/Date and TimeStamp Time/Date */ RTC_DateShow(); RTC_TimeShow(); } while (1) { if (Button_State == TAMPER_ON) { /* Turn LED4 ON */ STM_EVAL_LEDOn(LED2); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t *) " TimeStamp Event Occurred " ); LCD_SetFont(&Font16x24); LCD_ClearLine(LCD_LINE_4); LCD_ClearLine(LCD_LINE_5); LCD_ClearLine(LCD_LINE_6); LCD_ClearLine(LCD_LINE_7); LCD_ClearLine(LCD_LINE_8); /* Display the TimeStamp */ RTC_TimeStampShow(); Button_State = 0; } else if (Button_State == SEL_ON) { /* Turn LED1 ON and LED2 OFF */ STM_EVAL_LEDOn(LED1); STM_EVAL_LEDOff(LED2); /* Clear The TSF Flag (Clear TimeStamp Registers) */ RTC_ClearFlag(RTC_FLAG_TSF); LCD_SetFont(&Font12x12); LCD_ClearLine(LCD_LINE_5); LCD_SetFont(&Font12x12); LCD_DisplayStringLine(LCD_LINE_5,(uint8_t *) " TimeStamp Event Cleared " ); Button_State = 0; } } }