我使用STM8L152C6的disovery开发板,想要在Low power下,使用TIM2的Update事件唤醒CPU。我初始化了TIM2,只更改了官方工程中的LPR_Ram函数,但是不能够唤醒,代码如下(使用IAR开发):
定时器2初始化部分:
void ext_TIM2_Config(uint8_t mode)
{
CLK->PCKENR1 |= 0x1; // tim2
TIM2->CR1 = 0x00;
if(mode == 0)
{
//CLK:8MHz 1Hz
TIM2->PSCR = 0x7;
TIM2->CNTRH = 0;
TIM2->CNTRL = 0;
TIM2->ARRH = 62500u >> 8;
TIM2->ARRL = 62500u & 0xFF;
TIM2->IER |= 0x1; //允许中断
}
else
{
//CLK:38K 1Hz
TIM2->PSCR = 0x0;
TIM2->CNTRH = 0;
TIM2->CNTRL = 0;
TIM2->ARRH = 38000u >> 8;
TIM2->ARRL = 38000u & 0xFF;
TIM2->IER &= ~0x1; //不允许中断
//TIM2->IER |= 0x1;
}
#ifdef _COSMIC_
#pragma section (LPRUN)
void LPR_Ram(void)
#endif
#ifdef _RAISONANCE_
void LPR_Ram(void) inram
#endif
#ifdef _IAR_
#pragma location="MY_RAM_FUNC"
void LPR_Ram(void)
#endif
{
#if 0
uint8_t i = 0;
/* To reduce consumption to minimal
Swith off the Flash */
FLASH->CR1 = 0x08;
while(((CLK->REGCSR)&0x80)==0x80);
/* Swith off the Regulator*/
CLK->REGCSR = 0x02;
while(((CLK->REGCSR)&0x01)==0x01);
/* Set trigger on GPIOE pin6*/
WFE->CR2 = 0x04;
GPIOE->CR2 = 0x44;
for (i=0; i<100; i++);
/* To start counter on falling edge*/
GPIO_LOW(CTN_GPIO_PORT,CTN_CNTEN_GPIO_PIN);
/*Wait for end of counter */
wfe();
GPIOC->ODR ^= 0x80;
EXTI->SR1 |= 0x40;
WFE->CR2 = 0x00;
//Switch on the regulator
CLK->REGCSR = 0x00;
while(((CLK->REGCSR)&0x1) != 0x1);
#else
uint8_t i;
FLASH->CR1 = 0x08;
while(((CLK->REGCSR)&0x80)==0x80);
CLK->REGCSR = 0x02;
while(((CLK->REGCSR)&0x01)==0x01);
// -------------------------------------------------------
WFE->CR1 = 0x01; // tim2 wakeup update
CLK->PCKENR1 |= 0x1;
TIM2->CR1 |= 0x1;
//使能唤醒
//for(i = 0;i < 100;i++);
wfe();
GPIOC->ODR ^= 0x80;
//禁止唤醒
TIM2->SR1 &= ~0x1;
WFE->CR1 = 0x00;
//---------------------------------------------------------
//Switch on the regulator
CLK->REGCSR = 0x00;
while(((CLK->REGCSR)&0x1) != 0x1);
#endif
} |