[elektro] STM32L15 RTC / alarm ujrakonfig / IT problema

uprogc . uprogc at gmail.com
Mon Oct 3 19:34:43 CEST 2016


Meglett a megoldas,.........

Ez nem volt beallitva:

RTC_AlarmStructure.RTC_AlarmDateWeekDaySel

Emiatt az ebresztore vonatkozo ora, perc es masodperc ertekeket elszamolta
a RTC_SetAlarm( ), a regiszterbe valo iras elott. Viszont nem az elso
beallitastol kezdve, hanem nehany ciklus utan.

Bovebben lasd a RTC_SetAlarm( ) -ban.

On Fri, Sep 30, 2016 at 2:45 PM, uprogc . <uprogc at gmail.com> wrote:

> Sziasztok,
>
> Az STM RTC-jet hasznalom idozitesre; kulso 32768 kvarc,..
>
> A mainben felkonfiguralom az orat es az idozitojet, amikor az Alarm IT
> bejott jelzek a main-loopnak es ujrakonfiguralom az idozitot (RTC alarm)
>
> Ezt az egeszet ST Link Utility -ben online kovetem, hogy lassam hogy az
> aktualis ido es az ebreszto ideje rendben van-e.
>
> A problema az hogy nehany ciklus utan tobbet nem ad interruptot az rtc
> ebresztoje.
>
> Az periodusok kb egy percesek.
>
> Az interruptban is van egy flag amit online kovetek.
>
> Ez mar tobb napos szivas, sajnos.
>
> Igy nez ki az alarm config.
> Most csak az alarm_A-t hasznalom, egyeb kulso interruptok eseten hasznalom
> az alarm B-t, de az most nincs hasznalatban.
>
> Erdekesseg, hogy ha ezt bent hagyom:
>        // if(alarm_A == 1)
>         //    while (RTC_GetITStatus(RTC_IT_ALRA));
>
> akkor nem fut tovabb a program .
>
> -------------------------
> KOD:
>
> ErrorStatus RtcSetAlarmConfig( uint8_t en, uint8_t alarm_A, uint8_t
> alarm_B, uint8_t set_alarm_A_time, uint32_t alarm_A_time_sec)
> {
>     EXTI_InitTypeDef EXTI_InitStructure;
>     RTC_AlarmTypeDef RTC_AlarmStructure;
>     NVIC_InitTypeDef NVIC_InitStructure;
>
>     static uint8_t init = 0;
>
>     if( init == 0)
>     {
>         /* EXTI configuration */
>         EXTI_ClearITPendingBit( EXTI_Line17 );
>         EXTI_InitStructure.EXTI_Line = EXTI_Line17;
>         EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
>         EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
>         EXTI_InitStructure.EXTI_LineCmd = ENABLE;
>         EXTI_Init( &EXTI_InitStructure );
>
>         /* Enable the RTC Alarm Interrupt */
>         NVIC_InitStructure.NVIC_IRQChannel = RTC_Alarm_IRQn;
>         NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
>         NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
>         NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
>         NVIC_Init( &NVIC_InitStructure );
>
>         init = 1;
>     }
>
>     ErrorStatus status = ERROR;
>
>     if(set_alarm_A_time != 1)
>     {
>         RTC_TimeStruct_tmp.RTC_H12 = RTC_HourFormat_24;
>         RTC_TimeStruct_tmp.RTC_Seconds = 0;
>         RTC_TimeStruct_tmp.RTC_Minutes = 0;
>         RTC_TimeStruct_tmp.RTC_Hours = 0;
>
>         RTC_AlarmStructure.RTC_AlarmTime = RTC_TimeStruct_tmp;         //
> Assign recalculated time to Alarm time structure.
>         // Turn on alarm mask, RTC will make an event every 1 second.
>         RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_All;   // For 1
> sec alarm IT
>     }
>     else
>     {
>
>         alrm_cnf ^= 1;
>
>             uint32_t current_time = RTC_TimeStruct_2.RTC_Hours*3600 + //
> Go all to the seconds.
>                                     RTC_TimeStruct_2.RTC_Minutes*60 +
>                                     RTC_TimeStruct_2.RTC_Seconds    +
>                                     alarm_A_time_sec ;
> //  Add rtc_period seconds.
>
>             if(  current_time>86400 )                             // If
> current time with addition seconds more then seconds in a one day:
>             {
>                 RTC_TimeStruct_tmp.RTC_H12     = RTC_HourFormat_24;     //
> New day begins, so count from current_time - 86400
>                 RTC_TimeStruct_tmp.RTC_Hours   = (current_time - 86400) /
> 3600;
>                 RTC_TimeStruct_tmp.RTC_Minutes = ( ( (current_time -
> 86400) / 60 ) ) % 60 ;
>                 RTC_TimeStruct_tmp.RTC_Seconds = (current_time - 86400) %
> 60;
>                 /*
>                 RTC_TimeStruct_tmp.RTC_H12     = RTC_HourFormat_24;     //
> Still the same day, let's convert time in seconds back to
> hours:minutes:seconds.
>                 RTC_TimeStruct_tmp.RTC_Hours   = (current_time - 86400)
> /3600;
>                 RTC_TimeStruct_tmp.RTC_Minutes = ((current_time - 86400) -
> RTC_TimeStruct_tmp.RTC_Hours*3600)/60;
>                 RTC_TimeStruct_tmp.RTC_Seconds = ((current_time - 86400) -
> RTC_TimeStruct_tmp.RTC_Hours*3600 - RTC_TimeStruct_tmp.RTC_Minutes*60);
>             */
>             }else{
> /*
>                 RTC_TimeStruct_tmp.RTC_H12     = RTC_HourFormat_24;     //
> Still the same day, let's convert time in seconds back to
> hours:minutes:seconds.
>                 RTC_TimeStruct_tmp.RTC_Hours   = current_time / 3600;
>                 RTC_TimeStruct_tmp.RTC_Minutes = (current_time -
> (RTC_TimeStruct_tmp.RTC_Hours*3600) ) / 60;
>                 RTC_TimeStruct_tmp.RTC_Seconds = (current_time -
> (RTC_TimeStruct_tmp.RTC_Hours*3600) - (RTC_TimeStruct_tmp.RTC_
> Minutes*60));
> */
>                 RTC_TimeStruct_tmp.RTC_H12     = RTC_HourFormat_24;
>                 RTC_TimeStruct_tmp.RTC_Hours   = current_time / 3600;
>                 RTC_TimeStruct_tmp.RTC_Minutes = ( current_time  / 60 )  %
> 60 ;
>                 RTC_TimeStruct_tmp.RTC_Seconds = current_time % 60;
>
>                 hr = RTC_TimeStruct_tmp.RTC_Hours;
>                 min = RTC_TimeStruct_tmp.RTC_Minutes;
>                 sec = RTC_TimeStruct_tmp.RTC_Seconds;
>             }
>
>         RTC_AlarmStructure.RTC_AlarmTime = RTC_TimeStruct_tmp;         //
> Assign recalculated time to Alarm time structure.
>         // Turn on alarm mask for 1 hour alarm
>         RTC_AlarmStructure.RTC_AlarmMask = RTC_AlarmMask_DateWeekDay
> |RTC_AlarmMask_Seconds ; // |RTC_AlarmMask_Seconds
>     }
>
>     if(en == ENABLE && alarm_A == 1)
>     {
>         //RTC_ITConfig(RTC_IT_ALRA, DISABLE);// @@@ ADDED
>
>         //RTC_WriteProtectionCmd(DISABLE);
>         alrm_dis = RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
> // Disable alarm a peripheral, need to make available SetAlarm function.
>         RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); //
> SetAlarm with predefined parameters.
>
>         RTC_ITConfig(RTC_IT_ALRA, ENABLE);                      // Make
> RTC alarm B interrupt available.
>
>         //if(alarm_A == 1)
>         //    while (!RTC_GetITStatus(RTC_IT_ALRA));
>
>         alrm_en = status = RTC_AlarmCmd(RTC_Alarm_A,
> ENABLE);                      // Make alarm available.
>         RTC_ClearFlag(RTC_FLAG_ALRAF);                          // Clear
> alarm flag.
>        // RTC_WriteProtectionCmd(ENABLE);
>     }
>     else if(en == DISABLE && alarm_A == 1)
>     {        //RTC_WriteProtectionCmd(DISABLE);
>         RTC_AlarmCmd(RTC_Alarm_A, DISABLE);                     // Disable
> alarm a peripherial, need to make available SetAlarm function.
>         RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_A, &RTC_AlarmStructure); //
> SetAlarm with predefined parameters.
>
>         RTC_ITConfig(RTC_IT_ALRA, DISABLE);                      // Make
> RTC alarm B interrupt available.
>
>        // if(alarm_A == 1)
>         //    while (RTC_GetITStatus(RTC_IT_ALRA));
>
>         status = RTC_AlarmCmd(RTC_Alarm_A, DISABLE);
> // Make alarm available.
>         RTC_ClearFlag(RTC_FLAG_ALRAF);                          // Clear
> alarm flag.
>        // RTC_WriteProtectionCmd(ENABLE);
>     }
>
>     else if(en == ENABLE && alarm_B == 1)
>     {
>         //RTC_ITConfig(RTC_IT_ALRB, DISABLE);// @@@ ADDED
>
>         //RTC_WriteProtectionCmd(DISABLE);
>         RTC_AlarmCmd(RTC_Alarm_B, DISABLE);                     // Disable
> alarm b peripherial, need to make available SetAlarm function.
>         RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure); //
> SetAlarm with predefined parameters.
>
>         RTC_ITConfig(RTC_IT_ALRB, ENABLE);                      // Make
> RTC alarm B interrupt available.
>
>        // if(alarm_B == 1)
>        //     while (!RTC_GetITStatus(RTC_IT_ALRB));
>
>         status = RTC_AlarmCmd(RTC_Alarm_B, ENABLE);
> // Make alarm available.
>         RTC_ClearFlag(RTC_FLAG_ALRAF);                          // Clear
> alarm flag.
>        // RTC_WriteProtectionCmd(ENABLE);
>     }
>     else if(en == DISABLE && alarm_B == 1)
>     {        //RTC_WriteProtectionCmd(DISABLE);
>         RTC_AlarmCmd(RTC_Alarm_B, DISABLE);                     // Disable
> alarm b peripherial, need to make available SetAlarm function.
>         RTC_SetAlarm(RTC_Format_BIN, RTC_Alarm_B, &RTC_AlarmStructure); //
> SetAlarm with predefined parameters.
>
>         RTC_ITConfig(RTC_IT_ALRB, DISABLE);                      // Make
> RTC alarm B interrupt available.
>
>         //if(alarm_A == 1)
>         //    while (RTC_GetITStatus(RTC_IT_ALRB));
>
>         status = RTC_AlarmCmd(RTC_Alarm_B, DISABLE);
> // Make alarm available.
>         RTC_ClearFlag(RTC_FLAG_ALRAF);                          // Clear
> alarm flag.
>        // RTC_WriteProtectionCmd(ENABLE);
>     }
>
>     return status;
> }
>
>
>
>
>


More information about the Elektro mailing list