我写了一段STM32低功耗的程序,采用RTC唤醒,但是发现总是不会醒来。而我一旦只要打开了DEBUG,在KEIL 调试时,如果我设置一下或是停止一下断点,就能够醒过来,奇怪:
我的代码如下:
/**
* @brief Main program.
* @param None
* @retval : None
*/
int main(void)
{
INT8U i;
//看门狗初始化
// IWDogInit();
RCC_Init();
TIM_Setup();
uartInit();
RTC_Configuration();
EnablePheriperalsRCC(TRUE);
/* Keep the default configuration HSI 8MHz */
// DBGMCU_Config(DBGMCU_STOP,ENABLE);
while(1)
{
PWR_ClearFlag(PWR_FLAG_WU);
//使能外设
EnablePheriperals(TRUE);
//配置输入测试引脚
SetupTestPin();
//检查,如果被拉低,复位,进入bootloader
if(ReadTestPin() == RESET)
{
NVIC_GenerateSystemReset();
}
//-----------stop 模式后,继续在这里执行---------
//如果串口连接的,那么配置串口准备输出调试信息
RedLedOn();
GreenLedOff();
if(sysConfig.mDebug )
{
//开一个LED 显示正在工作
}
//配置TN100,包括配置GPIO,配置SPI,配置RCC,配置vector
RadioInit();
//休眠32ms,等待TN100启动成功
//启动TN100
NtrxInit();
//
PA_Init();
//启动PA电源
PA_PowerOn();
//启动定位
//startLocate
if(tagStartLocate(0) != 0)
{
while(range_time_out)
{
for(i= 0; i < MAX_RECV_BUF; i++)
{
if(recv_bufs[i].new_data == 1)
{
//处理新接收到的数据
OnRangeFrameCallBack(&recv_bufs[i].msdu,&recv_bufs[i].packet_info);
recv_bufs[i].new_data = 0;
}
}
//sleep休眠
__WFI();
// PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFI);
//重新设置外部时钟等信息
}
//定位结束,发送定位结果
DoRangeTimeOut();
}
//时钟到了,停止射频
//关闭PA
PA_Shutdown();
/**
* TN100低功耗
*/
NTRXPowerdownMode(0,0);
while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);
RTC_SetAlarm(RTC_GetCounter()+ (sysConfig.interval));
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
//等待串口发送完毕
while(!isUartIdle() )
__WFI();
//关闭所有的外设
EnablePheriperals(FALSE);
/* Select the RTC Clock Source */
RedLedOff();
GreenLedOn();
/* Request to enter STANDBY mode (Wake Up flag is cleared in PWR_EnterSTANDBYMode function) */
PWR_EnterSTOPMode(PWR_Regulator_LowPower,PWR_STOPEntry_WFE);
/* Wait till RTC Second event occurs */
RTC_ClearFlag(RTC_FLAG_SEC);
//启动后,重新配置时钟
SYSCLKConfig_STOP();
}
}
/**
* @brief Configures RTC clock source and prescaler.
* @param None
* @retval : None
*/
void RTC_Configuration(void)
{
/* Enable PWR and BKP clocks */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
/* Allow access to BKP Domain */
PWR_BackupAccessCmd(ENABLE);
/* Reset Backup Domain */
BKP_DeInit();
/* Enable LSE */
RCC_LSEConfig(RCC_LSE_ON);
/* Wait till LSE is ready */
while (RCC_GetFlagStatus(RCC_FLAG_LSERDY) == RESET)
{}
/* Select LSE as RTC Clock Source */
RCC_RTCCLKConfig(RCC_RTCCLKSource_LSE);
/* Enable RTC Clock */
RCC_RTCCLKCmd(ENABLE);
/* Wait for RTC registers synchronization */
RTC_WaitForSynchro();
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Enable the RTC Second */
// RTC_ITConfig(RTC_IT_SEC, ENABLE);
/* Wait until last write operation on RTC registers has finished */
// RTC_WaitForLastTask();
/* Set RTC prescaler: set RTC period to 0.5sec */
RTC_SetPrescaler(16383); /* RTC period = RTCCLK/RTC_PR = (32.768 KHz)/(32767+1) */
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
}
请高手指导。 |