有哪位 可以发一份 RTC唤醒的 STOP模式的 代码给我吗?我调试的代码始终有问题,唤醒后 串口打印是始终有问题;/*************************************************************/
void RTC_Config(void)
{
/* Enable the PWR clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
/* Allow access to RTC */
PWR_BackupAccessCmd(ENABLE);
RCC_LSICmd( ENABLE); //Æô¶¯LSI
while (RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET)
{ } /* Wait
till LSi is ready */
/* Select the RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSI);//Ñ¡ÔñLSI×÷ΪRTCʱÖÓÔ´
/* Enable the RTC Clock */
RCC_RTCCLKCmd(ENABLE);//Æô¶¯RTC
RTC_WakeUpCmd(DISABLE); //¹Ø±ÕRTC »½ÐѶ¨Ê±Æ÷!!!
/* µÈ´ýRTC¼Ä´æÆ÷ͬ²½ µÈ´ýдRTC¼Ä´æÆ÷Íê³É */
RTC_WaitForSynchro();
RTC_WakeUpClockConfig(RTC_WakeUpClock_RTCCLK_Div16);//»½ÐѶ¨Ê±Æ÷ʱÖÓ
RTC_SetWakeUpCounter( 0x9c4); //¸øRTC WAKE UP TIMER¸³ÖØ×°Öµ
RTC_WakeUpCmd( ENABLE); //Æô¶¯RTC »½ÐѶ¨Ê±Æ÷
}
/********RTC wake up interrupt NVIC ********/
void WKUP_NVIC_Config(void)
{
EXTI_InitTypeDef EXTI_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Configure EXTI line 20 (connected to the RTC wakeup event) */
EXTI_ClearITPendingBit(EXTI_Line20);
EXTI_InitStructure.EXTI_Line = EXTI_Line20;
EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStructure.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStructure);
/* NVIC configuration */
NVIC_InitStructure.NVIC_IRQChannel = RTC_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
/* Enable peirodic wakeup interrupt */
RTC_ITConfig(RTC_IT_WUT, ENABLE); //
/* Clear the wakeup Pending Bit */
RTC_ClearITPendingBit(RTC_IT_WUT);
}
/****** RTC periodic wake up interrupt service routine*******/
void RTC_IRQHandler(void)
{
//printf("R ");
if (RTC_GetITStatus(RTC_IT_WUT) != RESET)
{
/* Clear RTC wake up interrupt pending bit */
RTC_ClearITPendingBit(RTC_IT_WUT);
/* Clear EXTI line20 pending bit */
EXTI_ClearITPendingBit(EXTI_Line20);
}
if (PWR_GetFlagStatus(PWR_FLAG_WU) != RESET)
{
PWR_ClearFlag(PWR_FLAG_WU);
}
}
/**
* @brief Main program
* @param None
* @retval None
*/
int main(void)
{
u32 cnt=0;
u32 i=0;
USART_Config();
for(i=0;i<10;i++)
{
printf("
OS Æô¶¯ ¿ªÊ¼
");
delay_ms(500);
}
printf("
¿ªÊ¼ÅäÖÃ
");
RTC_Config(); /* RTC Configuration */
WKUP_NVIC_Config(); /* EXTI LINE 20 CONFIG */
printf("
RTC STOP ģʽ ÅäÖÃÍê³É
");
while(1)
{
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
SystemInit();
printf("d ");
}
for(;;);
}
一周热门 更多>