普誠創智(成都)科技有限公司-论坛
标题:
PT32U301进入Standby后,使用RTC唤醒和WAKEUP PIN唤醒
[打印本页]
作者:
James_Jiang
时间:
2017-5-12 16:06
标题:
PT32U301进入Standby后,使用RTC唤醒和WAKEUP PIN唤醒
/*功能:
PT32U301
进入STANDBY后,将被RTC以3秒为周期循环唤醒,也可被WAKEUP PIN的下降沿立即唤醒
*/
uLONG intrRTC=0,intrWAKEUP=0;
int main(void)
{
/*............................时钟初始化(略).........................................*/
NVIC_EnableIRQ((IRQn_Type) WAKEUP_IRQn);
NVIC_EnableIRQ((IRQn_Type) RTC_IRQn);
SysAPBClkEnable(gCLK_UART0 | gCLK_RTC);
SysAHBClkEnable(gCLK_GPIOD | gCLK_GPIOC | gCLK_GPIOB | gCLK_GPIOA);
SysIntoDSleepAPBClkEnable(gCLK_RTC); //Enable into sleep gate clock
UartInit();
TICKConfig();
GPIOAfr(GPIOD,BIT10,AF8);
//Set PD10 as WAKEUP(AF8)
if(pSYSCtrl->SC_BK_CTRL & 0x2) // WakeUp from standby detection
{
pSYSCtrl->SC_BK_CTRL = 1; //Enable BackUp Register Setting
pSYSCtrl->SC_BKSLP_CTRL|=((uLONG)1<<31); //Clear Wakeup Flag
printf("Hi!! I am Wakeup!!\r\n");
}
else //Power On.Configure standby mode
{
pSYSCtrl->SC_BK_CTRL = 1; //Enable BackUp Register Setting
pSYSCtrl->SC_BKSLP_CTRL =
(0<<30)|(
1<<28)|(1<<27)|(1<<26) |
(1<<25) | (0<<24) |(3);
pSYSCtrl->SC_BKRTC_CTRL |= (0xFF<<16)|(0x7F<<8)|(2<<2) |(1<<1)| 1;
pSYSCtrl->SC_BKRTC_CTRL&= ~(1<<1); // Clear Reset Request RTC Counter
}
pRTCCtrl->RTC_ALMEN = (1<<1)|1;
//Enable RTC Alarm
pRTCCtrl->RTC_IER
= (1<<17)|(1<<9) |
(1<<1) |(1);
//
TICKWaitms(10,1);
SCB->SCR = (1UL << 2); //Into DeepSleep
__WFI(); //Wait For Interrupt
while(1);
}
//--------------
void WAKEUP_IRQHandler(void)//irq 31
{
pSYSCtrl->SC_BK_CTRL = 1; //Enable Access Backup Register
pSYSCtrl->SC_BKSLP_CTRL =((uLONG)1<<31); //Clear Wakeup Flag
intrWAKEUP =1;
}
//--------------
void RTC_IRQHandler(void) //irq 8
{
intrRTC = pRTCCtrl->RTC_RIS;
pRTCCtrl->RTC_ISC = intrRTC;
}
欢迎光临 普誠創智(成都)科技有限公司-论坛 (https://princeton.com.cn/)
Powered by Discuz! X3.2