cdm 发表于 2021-8-31 17:21:48

stm8 定时唤醒时第一次运行有延时

各位大佬好!我最近就做一个STM8L定时唤醒,STM8L050程序调用RTC_WakeUpCmd(DISABLE)语句,就进WUTWF标志超时,导致上电第一次有一个很大延时后面程序能正常运行,用的官方STM8的函数库
程序卡在下面这个while里面超时后退出导致第一次运行有一个很大的延时
    /* Wait until WUTWF flag is set */
    while (((RTC->ISR1 & RTC_ISR1_WUTWF) == RESET) && ( wutwfcount != WUTWF_TIMEOUT))
    {
      //wutwfstatus = (uint8_t)(RTC->ISR1 & RTC_ISR1_WUTWF);
      wutwfcount++;
    }

以下是部分代码:
void RTC_Config(void)
{   
    //RTC_DeInit();
    /* Enable RTC clock */
    CLK_RTCClockConfig(CLK_RTCCLKSource_LSI,CLK_RTCCLKDiv_1);//RTC Clock Source Selection
    /* Enable RTC clock */      
    CLK_PeripheralClockConfig(CLK_Peripheral_RTC, ENABLE);//使能RTC的时钟   
    /* Configures the RTC wakeup timer_step = RTCCLK/16 = 1/38K/16 = 1644.7368 us */
    RTC_WakeUpClockConfig(RTC_WakeUpClock_CK_SPRE_16bits);
    /* Enable wake up unit Interrupt */
    RTC_ITConfig(RTC_IT_WUT, ENABLE);
    /* Enable general Interrupt*/
    enableInterrupts();
}


void Delay(__IO uint16_t nCount)
{
/* Decrement nCount value */
while (nCount != 0)
{
    nCount--;
    nop();nop();nop(); nop();nop();nop();
}

}
void main(void)
{
   CLK_Config();   
   Delay(10000);   
Begin:
   /* CLK configuration -------------------------------------------*/
   CLK_Config();
   PWR_UltraLowPowerCmd(ENABLE);/* */
/* RTC configuration -------------------------------------------*/                  
   RTC_Config();   
   //RTC_ClearFlag(RTC_FLAG_WUTWF);
   /* TIM2 configuration -------------------------------------------*/
    //TIM2_Config();   
   GPIO_Init(GPIOB, GPIO_Pin_6, GPIO_Mode_Out_PP_Low_Fast);
while (1)
{
/* Enter Wait for interrupt mode*/   
   //wfi();
    //GPIO_ToggleBits(GPIOB, GPIO_Pin_6);
   GPIO_SetBits(GPIOB, GPIO_Pin_6);
   Delay(1000);//500ms
   GPIO_ResetBits(GPIOB, GPIO_Pin_6);

   RTC_SetWakeUpCounter(1);//
   RTC_WakeUpCmd(ENABLE);
   //GPIO_Init(GPIOA, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
   //GPIO_ResetBits(GPIOA, GPIO_Pin_All);
   //GPIO_Init(GPIOB, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
// GPIO_ResetBits(GPIOB, GPIO_Pin_All);   
// GPIO_Init(GPIOC, GPIO_Pin_0 , GPIO_Mode_Out_PP_Low_Fast);//| GPIO_Pin_6
// GPIO_ResetBits(GPIOC, GPIO_Pin_0 | GPIO_Pin_6);
// GPIO_Init(GPIOD, GPIO_Pin_All, GPIO_Mode_Out_PP_Low_Fast);
// GPIO_ResetBits(GPIOD, GPIO_Pin_All);   

   /* 4. Configure Flash & EEPROM in IDDQ mode while WAIT mode */
   //FLASH_PowerWaitModeConfig(FLASH_Power_IDDQ);   

    halt();
    RTC_WakeUpCmd(DISABLE);
   goto Begin;
}
}

magee 发表于 2021-8-31 23:03:05

学习

butterflyspring 发表于 2021-9-1 11:36:09

建议在RTC_Config(); 前面加上一行 RTC_WakeUpCmd(DISABLE);试试。

cdm 发表于 2021-9-2 14:52:23

butterflyspring 发表于 2021-9-1 11:36
建议在RTC_Config(); 前面加上一行 RTC_WakeUpCmd(DISABLE);试试。

试了,还是有延时
页: [1]
查看完整版本: stm8 定时唤醒时第一次运行有延时