[求助] stm32 待机模式后出不来 请大家帮看看?

lu150   2011-4-8 20:11 楼主
各位朋友晚上好  我是一名接触STM32 不久的新手,对32的配置不是很在行 由于项目需要用32的片子做低功耗 这是我的配置  不知道什地方有问题 进入待机模式后用外部中断 usart都无法唤醒 请高手指点  拜托了
       #include "stm32f10x_lib.h"
//#include
//#include
extern u8 SCII[5];
extern u8 ret;
extern u8 k,dat;
u8 xi=0;
ErrorStatus HSEStartUpStatus;

void RCC_Configuration(void);
void NVIC_Configuration(void);
void EXTI_Configuration(void);
void GPIO_Configuration(void);
void USART_Configuration(void);
void Sys_Standby(void);
void SYSCLKConfig_STOP(void);
void delay(u8 time);
int main (void)
{
u8 i;

#ifdef DEBUG
  debug();
#endif
  RCC_Configuration();
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR,ENABLE);  // RCC_APB1Periph_BKP
  NVIC_Configuration();
  EXTI_Configuration();
  USART_Configuration();
  GPIO_Configuration();
  while(1)
  {
//   delay(50);
    if(GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_7)==0)
          {
             /* Turn off led connected to PC.06 */
             k=1;
                 GPIO_SetBits(GPIOD, GPIO_Pin_10);
             /* Request to enter STOP mode with regulator ON */       
                 PWR_WakeUpPinCmd(ENABLE);
                 /*ENABLE all GPIO_EXTI*/       
                 PWR_EnterSTANDBYMode();                         //        PWR_Regulator_LowPower
//        PWR_EnterSTOPMode(PWR_Regulator_ON, PWR_STOPEntry_WFE);   //停止 中断后程序重这运行下去
             /* At this stage the system has resumed from STOP mode -------------------*/          
                 //GPIO_SetBits(GPIOD, GPIO_Pin_11);
             /* 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_10);
          }
    delay(50);
    if(xi==1)
    {
         for(i=1;i<6;i++)
         {
         USART_SendData(USART1, SCII);
         while (!(USART1->SR & USART_FLAG_TXE));
         USART_ClearITPendingBit(USART1,USART_IT_TXE);
//         delay(50);
         }
         xi=0;
         }
   }
}

void RCC_Configuration(void)
{
  ErrorStatus HSEStartUpStatus;
  /**************************/
  RCC_DeInit();
  /* Enable HSE */
  RCC_HSEConfig(RCC_HSE_ON);

  /* Wait till HSE is ready */
  HSEStartUpStatus = RCC_WaitForHSEStartUp();

  if(HSEStartUpStatus == SUCCESS)
  {
    /* HCLK = SYSCLK */
    RCC_HCLKConfig(RCC_SYSCLK_Div1);
  
    /* PCLK2 = HCLK */
    RCC_PCLK2Config(RCC_HCLK_Div1);

    /* PCLK1 = HCLK/2 */
    RCC_PCLK1Config(RCC_HCLK_Div2);

    /* Flash 2 wait state */
    FLASH_SetLatency(FLASH_Latency_2);
    /* Enable Prefetch Buffer */
    FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);

    /* PLLCLK = 8MHz * 9 = 72 MHz */
    RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);

    /* 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)
    {
    }
  }  
  /* Enable USART1 and GPIOA clock */
    RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1 | RCC_APB2Periph_GPIOA|
                    RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD| RCC_APB2Periph_AFIO,ENABLE);
}

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);
  //指定向量表位置在RAM存储器
  //向量表位于RAM 参阅Section:NVIC_VectTab查阅更多该参数允许取值范围
#else  /* VECT_TAB_FLASH  */
  /* Set the Vector Table base location at 0x08000000 */
    NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0);
    //指定向量表位置在flash程序存储器   
#endif
    NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
        NVIC_InitStructure.NVIC_IRQChannel = EXTI9_5_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);
                                                                         
        NVIC_InitStructure.NVIC_IRQChannel = EXTI15_10_IRQChannel;
    NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
    NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;
    NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
    NVIC_Init(&NVIC_InitStructure);       
       
        NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQChannel; //UART4全局中断 通道
        NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority =0;//
        NVIC_InitStructure.NVIC_IRQChannelSubPriority =4; //
        NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
        NVIC_Init(&NVIC_InitStructure);

}

void EXTI_Configuration(void)
{
  EXTI_InitTypeDef EXTI_InitStructure;

  /* Connect EXTI Line9 to PB.09 */
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource10);
  GPIO_EXTILineConfig(GPIO_PortSourceGPIOB, GPIO_PinSource9);

  EXTI_InitStructure.EXTI_Line = EXTI_Line9;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;  //外中断   EXTI_Mode_Event 事件中断
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  EXTI_GenerateSWInterrupt(EXTI_Line9);

  EXTI_InitStructure.EXTI_Line = EXTI_Line10;
  EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;  //外中断   EXTI_Mode_Event 事件中断
  EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
  EXTI_InitStructure.EXTI_LineCmd = ENABLE;
  EXTI_Init(&EXTI_InitStructure);
  EXTI_GenerateSWInterrupt(EXTI_Line10);
}

/*void Sys_Standby(void)
{
  SCB->SCR|=1<<2;// SLEEPDEEP (SYS->CTRL)
  RCC->APB1ENR|=1<<28; //
  PWR->CSR|=1<<8; // WKUP
  PWR->CR|=1<<2; // Wake-up
  PWR->CR|=1<<1; //PDDS
  __WFE(); // WFI
} */

void USART_Configuration(void)
{   
        USART_InitTypeDef USART_InitStructure;
        /************************************************/
        USART_InitStructure.USART_BaudRate = 9600;         
        //该成员设置了USART传输的波特率                               
        //波特率可以由以下公式计算
        //IntegerDivider = ((APBClock) / (16 * (USART_InitStruct->USART_BaudRate)))
        //FractionalDivider = ((IntegerDivider - ((u32) IntegerDivider)) * 16) + 0.5
        USART_InitStructure.USART_WordLength = USART_WordLength_8b;         
        //设置传输数据位数 提示了在一个帧中传输或者接收到的数据位数
        USART_InitStructure.USART_StopBits = USART_StopBits_1;
        //发送的停止位数目
        USART_InitStructure.USART_Parity = USART_Parity_No ;   
        //定义了奇偶校验
        USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
        //指定了硬件流控制模式使能还是失能       
        USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;  
        //指定了使能或者失能发送和接收模式
        /* Configure USART1 basic and asynchronous paramters */
        USART_Init(USART1, &USART_InitStructure);
        /* Enable USART1 */
        USART_ITConfig(USART1,USART_IT_RXNE, ENABLE);
        USART_Cmd(USART1, ENABLE); //使能或者失能USART外设
}

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 GPIO_Configuration(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
  /* Configure USART1 Tx (PA.09) as alternate function push-pull */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
  GPIO_Init(GPIOA, &GPIO_InitStructure);
   
  /*Configure USART1 Rx (PA.10) as input floating; */
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOA, &GPIO_InitStructure);

  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9;                                                        //EXTI
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
  GPIO_Init(GPIOB, &GPIO_InitStructure);

  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);
}

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

#ifdef  DEBUG
void assert_failed(u8* file, u32 line)
{
  //如果传给宏assert_param的参数为false,
  //则调用函数assert_failed并返回被错误调用的函数所在的文件名
  //和行数。如果传给宏assert_param的参数为true,则无返回值
  /* Infinite loop */
while (1)
  {
  }
}
#endif

回复评论 (2)

你好,你使用的是STANDBY模式,那么请看下图:
1.jpg
如果使用这种模式那么唤醒只能是:RTC WAKEUP引脚,看门狗,NRST的外部复位引脚
你详细比较一下你想使用的模式
处处留心皆学问!
点赞  2011-4-9 09:56
希望楼主把弄好以后的程序发上来一份大家学习参考
点赞  2011-4-9 10:00
电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 京公网安备 11010802033920号
    写回复