AnsweredAssumed Answered

Time count and display by RTC using up/down press key

Question asked by Md Mubdiul Hasan on Oct 20, 2016
Latest reply on Oct 21, 2016 by Md Mubdiul Hasan
Dear All,

I have implemented stm32f0 rtc application for spending some time in a operation system, kindly take a look and figure-out my mistake, 



      static void MX_RTC_Init(void)
      {


        RTC_TimeTypeDef sTime;
        RTC_DateTypeDef sDate;
        RTC_AlarmTypeDef sAlarm;


           /**Initialize RTC and set the Time and Date
           */
        hrtc.Instance = RTC;
        hrtc.Init.HourFormat = RTC_HOURFORMAT_24;
        hrtc.Init.AsynchPrediv = 127;
        hrtc.Init.SynchPrediv = 255;
        hrtc.Init.OutPut = RTC_OUTPUT_DISABLE;
        hrtc.Init.OutPutPolarity = RTC_OUTPUT_POLARITY_HIGH;
        hrtc.Init.OutPutType = RTC_OUTPUT_TYPE_OPENDRAIN;
        if (HAL_RTC_Init(&hrtc) != HAL_OK)
        {
           Error_Handler();
        }


        sTime.Hours = 0x0;
        sTime.Minutes = 0x0;
        sTime.Seconds = 0x0;
        sTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
        sTime.StoreOperation = RTC_STOREOPERATION_RESET;
        if (HAL_RTC_SetTime(&hrtc, &sTime, RTC_FORMAT_BCD) != HAL_OK)
        {
           Error_Handler();


        }


           /**Enable the Alarm A
           */
        sAlarm.AlarmTime.Hours = 0x0;
        sAlarm.AlarmTime.Minutes = 0x0;
        sAlarm.AlarmTime.Seconds = 0x0;
        sAlarm.AlarmTime.SubSeconds = 0x0;
        sAlarm.AlarmTime.DayLightSaving = RTC_DAYLIGHTSAVING_NONE;
        sAlarm.AlarmTime.StoreOperation = RTC_STOREOPERATION_RESET;
        sAlarm.AlarmMask = RTC_ALARMMASK_NONE;
        sAlarm.AlarmSubSecondMask = RTC_ALARMSUBSECONDMASK_ALL;
        sAlarm.AlarmDateWeekDaySel = RTC_ALARMDATEWEEKDAYSEL_DATE;
        sAlarm.AlarmDateWeekDay = 1;
        sAlarm.Alarm = RTC_ALARM_A;
        if (HAL_RTC_SetAlarm_IT(&hrtc, &sAlarm, RTC_FORMAT_BCD) != HAL_OK)
        {
           Error_Handler();
        }


           /**Enable the WakeUp
           */
        if (HAL_RTCEx_SetWakeUpTimer_IT(&hrtc, 0, RTC_WAKEUPCLOCK_RTCCLK_DIV8) != HAL_OK)
        {
           Error_Handler();
        }


      }


     void EXTI0_IRQHandler(void)
     {


          int i;
          i = 1;
     }
         if (EXTI_GetITStatus(EXTI_Line17) != RESET){
         }
                        for (GPIO_KEY_SW2==1) {// pressed for enter stand bay state 1
                         HAL_GPIO_TogglePin (GPIOB, BCD_A_Pin, BCD_B_Pin, BCD_C_Pin, BCD_D_Pin );
                         HAL_Delay(100);
                         }


                   for (GPIO_KEY_SW4==0) {// pressing SW4 key in rising step




                      (db_count = 16)
                      EXTI->PR = 0x00000200;
                      RTC->WPR = 0xCA; 
                      GPIOC ->IDR & GPIO_IDR_0
                      GPIOC ->ODR |= (1<<14)
                      {
                                i=0;
                                while(i<16)   //
                                {
                                   i++;
                                }


     /* Clear interrupt flag */
    RTC->WPR = 0xFE;
     EXTI_ClearITPendingBit(EXTI_Line17);
                        }
                    }


void EXTI19_IRQHandler(void) {
               /* Make sure that interrupt flag is set */
               if (EXTI_GetITStatus(EXTI_Line19) != RESET) {
               for (GPIO_KEY_SW3==0) {// pressing SW4 key in falling step
                           (db_count = 16)
                          EXTI->PR = 0x00000200;
                          GPIOC ->IDR & GPIO_IDR_0
                          RTC->WPR = 0xCA; 
                          GPIOC ->ODR |= (1<<14)
             {
                    i=0; 
                while(i<16)   //
               {
               i--;


                    /* Clear interrupt flag */
                   RTC->WPR = 0xFE;
                    EXTI_ClearITPendingBit(EXTI_Line19);
               }
          }


     static void RTC_TimeShow(uint8_t* showtime)
            {
               
                  RTC_TimeTypeDef sTime;


               /* Get the RTC current Time */
               HAL_RTC_GetTime(&hrtc, & sTime, RTC_FORMAT_BCD);


               /* Display time Format : hh:mm:ss */
               sprintf((char*)showtime,"%02d:%02d:%02d",sTime.Hours, sTime.Minutes, sTime.Seconds);
           }

Outcomes