打印

stm32 PWR 停止模式后出不来 请大家帮看看

[复制链接]
2659|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
lu150|  楼主 | 2011-3-28 09:56 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
大家好  这是我配置的PWR 停止低功耗模式 现在问题是进了停止模式 但是中断(EXTI PB.9) 退不出来  请帮我看看那里有问题 ?

   #include "stm32f10x_lib.h"
#include "GLCD.h"
ErrorStatus HSEStartUpStatus;
u8 ascii[13];
u8 flag=0x00,ka=0x00,hao=0x00;
void RCC_Configuration(void);
void NVIC_Configuration(void);
void Timer_Configuration(void);
void EXTI_Configuration(void);
void GPIO_Configuration(void);
void SysTick_Configuration(void);
void SYSCLKConfig_STOP(void);
void delay(u8 time);
int main(void)
{
#ifdef debug
   debug();
#endif
  RCC_Configuration();
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR | RCC_APB1Periph_BKP, ENABLE);
  
  Timer_Configuration();
  EXTI_Configuration();
  
  NVIC_Configuration();
  GPIO_Configuration();
   
  SysTick_Configuration();
  /* Turn on led connected to PC.06 */
  GPIO_SetBits(GPIOD, GPIO_Pin_8);
  /* Turn off led connected to PC.09 */
  GPIO_ResetBits(GPIOD, GPIO_Pin_11);
  GLCD_init();  //初始化
  GLCD_clear(White);
  GLCD_setTextColor(Red);
  GLCD_displayStringLn(Line1,"  ***************");
  GLCD_displayStringLn(Line8,"  ***************");
  while(1)
    {
   delay(200);
   if(flag==0x01)
     {
      flag=0x00;
   ka++;
   ascii[0]=' ';
   ascii[1]=' ';
   ascii[2]=' ';
   ascii[3]=' ';
   ascii[4]=' ';
   ascii[5]='T';
   ascii[6]='I';
   ascii[7]='M';
   ascii[8]='E';
   ascii[9]=' ';
   ascii[10]=ka/100+0x30;
   ascii[11]=ka%100/10+0x30;
   ascii[12]=ka%100%10+0x30;
      GLCD_displayStringLn(Line3,(u8*)ascii);
  
  }
  delay(200);
  if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7)==0)
    {
   GPIO_SetBits(GPIOD, GPIO_Pin_11);
      /* Turn off led connected to PC.06 */
      GPIO_ResetBits(GPIOD, GPIO_Pin_8);
      /* Request to enter STOP mode with regulator ON */
  //  __WFI();
     // PWR_WakeUpPinCmd(ENABLE);
      /* At this stage the system has resumed from STOP mode -------------------*/   
      PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFI);
      /* Turn on led connected to PC.06 */
      GPIO_SetBits(GPIOD, GPIO_Pin_9);
      /* 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();
      /* Turn off led connected to PC.09 */
      GPIO_ResetBits(GPIOD, GPIO_Pin_9);
    }
    }
}

void RCC_Configuration(void)
{
   
  /*恢复时钟寄存器为默认值 */
  RCC_DeInit();
  /*外部时钟使能*/
  RCC_HSEConfig(RCC_HSE_ON);
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
  if(HSEStartUpStatus == SUCCESS)
   {
     /* Enable Prefetch Buffer */
     FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
     /* Flash 2 wait state */
     FLASH_SetLatency(FLASH_Latency_2);
     /* HCLK = SYSCLK */
     RCC_HCLKConfig(RCC_SYSCLK_Div1);  
     /* PCLK2 = HCLK */
     RCC_PCLK2Config(RCC_HCLK_Div1);
     /* PCLK1 = HCLK/2 */
     RCC_PCLK1Config(RCC_HCLK_Div2);
     /* PLLCLK = 8MHz * 9 = 72 MHz */
     RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);  //8X2MHz
     /* Enable PLL */
     RCC_PLLCmd(ENABLE);
     /* Wait till PLL is ready */
     while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
      {
      }
     /* Select PLL as system clock source */
     RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
     /* Wait till PLL is used as system clock source */
     while(RCC_GetSYSCLKSource() != 0x08)
      {
      }
    }
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);      //使能GPIOD TIM2
}
void NVIC_Configuration(void)
{
    NVIC_InitTypeDef  NVIC_InitStructure;
#ifdef  VECT_TAB_RAM  
    /* Set the Vector Table base location at 0x20000000 */
NVIC_SetVectorTable(NVIC_VectTab_RAM, 0x0);  
#else  /* VECT_TAB_FLASH  */
    /* Set the Vector Table base location at 0x08000000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);  
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel;  //TIM2全局中断 通道
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; //
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
    NVIC_Init(&NVIC_InitStructure);
}
void EXTI_Configuration(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;
  /* Connect EXTI Line9 to PB.09 */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);
  /* Configure EXTI Line9 to generate an interrupt on falling edge */
  EXTI_ClearITPendingBit(EXTI_Line9);
  EXTI_InitStructure.EXTI_Line = EXTI_Line9;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  /* Configure EXTI Line17(RTC Alarm) to generate an interrupt on rising edge
  EXTI_ClearITPendingBit(EXTI_Line17);
  EXTI_InitStructure.EXTI_Line = EXTI_Line17;
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
  EXTI_Init(&EXTI_InitStructure);           */
}
void Timer_Configuration(void)
{
    TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period=2000; //自动重装载寄存器的值     1s
TIM_TimeBaseStructure.TIM_Prescaler= (36000 - 1); //时钟预分频数
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; //时钟分割0x00
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数模式
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ClearFlag(TIM2, TIM_FLAG_Update); //清除溢出中断标志
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);//标志位 当TIM_IT_Update,ENABLE 定时时间到
TIM_Cmd(TIM2, ENABLE);   
}
void SYSCLKConfig_STOP(void)
{
  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);
  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();
  if(HSEStartUpStatus == SUCCESS)
  {
    /* Enable PLL */
    RCC_PLLCmd(ENABLE);
    /* Wait till PLL is ready */
    while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
    {
    }
    /* Select PLL as system clock source */
    RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
    /* Wait till PLL is used as system clock source */
    while(RCC_GetSYSCLKSource() != 0x08)
    {
    }
  }
}
void SysTick_Configuration(void)
{
  /* Select AHB clock(HCLK) as SysTick clock source */
  SysTick_CLKSourceConfig(SysTick_CLKSource_HCLK);
  /* Set SysTick Priority to 3 */
  NVIC_SystemHandlerPriorityConfig(SystemHandler_SysTick, 3, 0);
   
  /* SysTick interrupt each 1ms with HCLK equal to 72MHz */
  SysTick_SetReload(72000);
  /* Enable the SysTick Interrupt */
  SysTick_ITConfig(ENABLE);
}
void GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA |RCC_APB2Periph_GPIOB | RCC_APB2Periph_GPIOD
                                              |RCC_APB2Periph_AFIO, ENABLE);
  /* Configure PC.06, PC.07, PC.08 and PC.09 as Output push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_9 | GPIO_Pin_10 | GPIO_Pin_11;  //LED
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
  GPIO_Init(GPIOD, &GPIO_InitStructure);
  /* Configure PB9 as input floating (EXTI Line9) */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;       //EXTI
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);
  /* Configure PA7 as input floating  */       //GPIO
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
}


void delay(u8 time)
{
u8 a;
u16 b;
for(a=time;a>0;a--)
   for(b=1000;b>0;b--);
}


void TIM2_IRQHandler(void)
{
  if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET)
  {
   TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);
   flag=0x01;
}
}

void EXTI9_5_IRQHandler(void)
{
  if(EXTI_GetITStatus(EXTI_Line9) != RESET)
  {   
    /* Toggle Led connected to PC.07 */
    GPIO_WriteBit(GPIOD, GPIO_Pin_8, (BitAction)(1-GPIO_ReadOutputDataBit(GPIOD, GPIO_Pin_8)));
    /* Clear EXTI line9 pending bit */
    EXTI_ClearITPendingBit(EXTI_Line9);
  }
}
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

个人签名:无里头!

3

主题

249

帖子

1

粉丝