最近在做一个很简单的程序,然后客户必须要低功耗,开始用STC的
单片机由于要使用5个1外部中断实现低功耗唤醒,功能实现不了,换
STM32来是,产考了很多资料但不管怎么样就是进不了睡眠模式,要不就是进入了睡眠模式但却不能唤醒,而且用电流表测量电流竟然达到了40mA,折腾了好多天也一直没有个结果。有没有大神指导下的!下面是我参考官方例程写的程序!!
- int main(void)
- {
- SYS_HSI_CLK_Config();
- if (Systick_Config(SystemCoreClock / 1000))
- {
- while (1);//²¶»ñ´íÎó
- }
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
- PWR_BackupAccessCmd(ENABLE);
- RCC_BackupResetCmd(ENABLE);
- RCC_BackupResetCmd(DISABLE);
- SleepMode_Measure();
- LED_IO_Init();
- while (1)
- {
- switch(mode)
- {
- case 1:SW_1() ;break;
- case 2:SW_2() ;break;
- case 3:SW_3() ;break;
- case 4:SW_4() ;break;
- case 5:SW_5() ;break;
- default: __WFI(); break; // Sys_Standby();rest_all(GPIOA,OUT_DATA,~OUT_DATA);
- }
- //test();
- GPIOC->ODR |=0x2000;
- Delay(50);
- GPIOC->ODR =~0x2000;
- Delay(50);
- }
- }
- void SleepMode_Measure()
- {
- __IO uint32_t index = 0;
- GPIO_InitTypeDef GPIO_InitStructure;
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, ENABLE);
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_All;
- GPIO_Init(GPIOA, GPIO_InitStructure);
- GPIO_Init(GPIOB, GPIO_InitStructure);
- GPIO_Init(GPIOC, GPIO_InitStructure);
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA | RCC_AHBPeriph_GPIOB | RCC_AHBPeriph_GPIOC, DISABLE);
- EXTI0_1InitConfig();
- EXTI2_3InitConfig();
- EXTI4_15InitConfig();
- __WFI();
- /*
- while (1)
- {
- for(index = 0; index < 0x7FFFF; index++);
- }
- */
- }
- void EXTI0_1InitConfig(void)
- {
- //Enable GPIOA clock
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- // Configure PA0 pin as input floating
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, GPIO_InitStructure);
- // Enable SYSCFG clock
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- // Connect EXTI0 Line to PA0 pin
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource1);
- // Configure EXTI1 line
- EXTI_InitStructure.EXTI_Line = EXTI_Line1;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Rising;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init( EXTI_InitStructure);
- // Enable and set EXTI0 Interrupt
- NVIC_InitStructure.NVIC_IRQChannel = EXTI0_1_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPriority = 0x00;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init( NVIC_InitStructure);
- }
- void EXTI2_3InitConfig(void)
- {
- //Enable GPIOA clock
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- // Configure PA0 pin as input floating
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2|GPIO_Pin_3;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, GPIO_InitStructure);
- // Enable SYSCFG clock
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- // Connect EXTI0 Line to PA2 pin
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource2);
- // Connect EXTI0 Line to PA3 pin
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource3);
- // Configure EXTI2 line
- EXTI_InitStructure.EXTI_Line = EXTI_Line2;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init( EXTI_InitStructure);
- // Configure EXTI3 line
- EXTI_InitStructure.EXTI_Line = EXTI_Line3;
- EXTI_Init( EXTI_InitStructure);
- // Enable and set EXTI2-3 Interrupt
- NVIC_InitStructure.NVIC_IRQChannel = EXTI2_3_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPriority = 0x01;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init( NVIC_InitStructure);
- }
- void EXTI4_15InitConfig(void)
- {
- //Enable GPIOA clock
- RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
- // Configure PA0 pin as input floating
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4|GPIO_Pin_5;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
- GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
- GPIO_Init(GPIOA, GPIO_InitStructure);
- // Enable SYSCFG clock
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG, ENABLE);
- // Connect EXTI0 Line to PA4 pin
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource4);
- // Connect EXTI0 Line to PA5 pin
- SYSCFG_EXTILineConfig(EXTI_PortSourceGPIOA, EXTI_PinSource5);
- // Configure EXTI4 line
- EXTI_InitStructure.EXTI_Line = EXTI_Line4;
- EXTI_InitStructure.EXTI_Mode = EXTI_Mode_Interrupt;
- EXTI_InitStructure.EXTI_Trigger = EXTI_Trigger_Falling;
- EXTI_InitStructure.EXTI_LineCmd = ENABLE;
- EXTI_Init( EXTI_InitStructure);
- // Configure EXTI5 line
- EXTI_InitStructure.EXTI_Line = EXTI_Line5;
- EXTI_Init( EXTI_InitStructure);
- // Enable and set EXTI4-15 Interrupt
- NVIC_InitStructure.NVIC_IRQChannel = EXTI4_15_IRQn;
- NVIC_InitStructure.NVIC_IRQChannelPriority = 0x10;
- NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
- NVIC_Init( NVIC_InitStructure);
- //Sys_Enter_Standby();
- }