[mw_shl_code=c,true]#include "standby.h"
#include "stm32f10x_exti.h"
#include "stm32f10x_gpio.h"
#include "stm32f10x_rcc.h"
#include "misc.h"
#include "key.h"
#include "delay.h"
#include "led.h"
#include "stm32f10x_pwr.h"
void StanByMode_Init(void)
{
GPIO_InitTypeDef GPIO_InitStruct;
NVIC_InitTypeDef NVIC_InitStruct;
EXTI_InitTypeDef EXTI_InitStruct;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_AFIO,ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
GPIO_InitStruct.GPIO_Pin = GPIO_Pin_0;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_IPD;
GPIO_Init(GPIOA,&GPIO_InitStruct);
GPIO_EXTILineConfig(GPIO_PortSourceGPIOA, GPIO_PinSource0);
EXTI_InitStruct.EXTI_Line = EXTI_Line0;
EXTI_InitStruct.EXTI_Mode = EXTI_Mode_Interrupt;
EXTI_InitStruct.EXTI_Trigger = EXTI_Trigger_Rising;
EXTI_InitStruct.EXTI_LineCmd = ENABLE;
EXTI_Init(&EXTI_InitStruct);
NVIC_InitStruct.NVIC_IRQChannel = EXTI0_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void Sys_Standby(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_PWR, ENABLE);
PWR_WakeUpPinCmd(ENABLE);
PWR_EnterSTANDBYMode();
}
void EXTI0_IRQHandeler(void)
{
EXTI_ClearITPendingBit(EXTI_Line0);
if(KEY) //#define KEY GPIO_ReadInputDataBit(GPIOA,GPIO_Pin_0)
{
delay_ms(10);
if(KEY)
{
Sys_Standby();
}
}
}[/mw_shl_code]
问题是这样的:我现在在做原子老大的待机实验,以上为我自己编写的代码,主函数就是红灯闪烁,按理说当我按下wk_up按键时应该进入休眠状态,再按一下复位,但是现在当我按下按键时,程序直接卡死在那,也就是说直接定格在灯闪烁的某个状态,只能复位,我想问问各位这种情况如何解决,已快崩溃!!!
首先说说不能进入中断的原因:
我自己写了一个利用systick时钟延时的函数,当使用这个函数进行延时时,主函数可以正常运行,但是不能进入外部中断(其他中断暂时还没有试验),用老大的就可以。
下面是我写的源码:
[mw_shl_code=c,true]#include "systick.h" #include "stm32f10x.h" #include "core_cm3.h" static __IO u32 TimingDelay; void SysTick_Init() { if (SysTick_Config(SystemCoreClock / 1000)) { /* Capture error */ while (1); } SysTick->CTRL &= ~ SysTick_CTRL_ENABLE_Msk; } void Delay_ms(__IO uint32_t nTime) { TimingDelay = nTime; SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk; while(TimingDelay != 0); } void TimingDelay_Decrement(void) { if (TimingDelay != 0x00) { TimingDelay--; } } [/mw_shl_code] [mw_shl_code=c,true]void SysTick_Handler(void) { [/mw_shl_code] [mw_shl_code=c,true] [mw_shl_code=c,true] TimingDelay_Decrement();[/mw_shl_code] [/mw_shl_code] [mw_shl_code=c,true]} [/mw_shl_code] 问题也随之而来:
为什么会出现这种现象,是因为systick时钟中断与外部中断发生冲突还是?没遇过这种情况的兄弟今后注意,知道的原因的兄弟麻烦告诉我一声,共同进步!
一周热门 更多>