关于STM32的休眠与Systick如何共用的问题,跪求大侠帮忙??
在做休眠时,采用的是RTC Alarm方式唤醒MCU,但是系统又同时使用了Systick作为时钟基准计数器。如何避免休眠时被Systick唤醒,但是同时可以让Systick正常运转计数。
求帮忙,谢谢?
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* 2 bits for Preemption Priority and 2 bits for Sub Priority */
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
NVIC_InitStructure.NVIC_IRQChannel = RTCAlarm_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
//系统滴答计数器
void SysTick_Configuration(void)
{
/* Setup SysTick Timer for 1 msec interrupts */
if (SysTick_Config(SystemFrequency / 1000))
{
/* Capture error */
while (1);
}
/* Set SysTick Priority to 3 */
NVIC_SetPriority(SysTick_IRQn, 0x0C);
}
main函数主循环如下
while (1)
{
/* Insert 1.5 second delay */
Delay(1500);
/* Wait till RTC Second event occurs */
RTC_ClearFlag(RTC_FLAG_SEC);
while(RTC_GetFlagStatus(RTC_FLAG_SEC) == RESET);
/* Alarm in 3 second */
RTC_SetAlarm(RTC_GetCounter()+ 3);
/* Wait until last write operation on RTC registers has finished */
RTC_WaitForLastTask();
/* Turn off led connected to GPIO_LED Pin9 */
LED_OFF(GPIO_Pin_10);
/* Request to enter STOP mode with regulator in low power mode*/
PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
/* At this stage the system has resumed from STOP mode -------------------*/
/* Configures system clock after wake-up from STOP: enable HSE, PLL and select
PLL as system clock source (HSE and PLL are disabled in STOP mode) */
SYSCLKConfig_STOP();
}
//延时函数
void Delay(__IO uint32_t nTime)
{
TimingDelay = nTime;
while(TimingDelay != 0){};
}
//中断响应
void SysTick_Handler(void)
{
TimingDelay--;
}
RE:关于STM32的休眠与Systick如何共用的问题,跪求大侠帮忙??
用systick做时钟计数不好吧,不直接用RTC吗。RE:关于STM32的休眠与Systick如何共用的问题,跪求大侠帮忙??
楼主在RTC时钟上设置下,选择系统时钟,不用SYSTICK作为时钟。这样系统休眠时,可以让RTC唤醒,而不影响SYSTICK了。这个SYSTICK一般用作嵌入式系统的时钟,用作RTC时钟不合适呢RE:关于STM32的休眠与Systick如何共用的问题,跪求大侠帮忙??
Systick唤醒的里面判断一下,如果是,那就继续睡眠不过这方法属于治标不治本了
页:
[1]