香水城版主-----这是我第一个STM32的单片机的例子,以前使用过STM8S系列的单片机.
我用TIM1 测试中断,它就是死活进不了中断,郁闷呀,哪位大虾帮忙看看,问题出在哪里.下面是我的例程.
void RCC_Configura(void)
{ RCC_DeInit();
RCC_HSEConfig(RCC_HSE_ON);
//SystemInit();
}
//---------------------------------------------------------------------
void GPIOD_Configure(void)
{ GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD| RCC_APB2Periph_AFIO, ENABLE);
GPIO_InitStructure.GPIO_Pin = LED1|LED2|LED3|LED4;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_SetBits(GPIOD,LED1|LED2|LED3|LED4);
}
//-----------------------------------------------------------------------
void TIM1_Configure(void)
{ TIM_TimeBaseInitTypeDef TIM1_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM1_InitStructure.TIM_Prescaler = 0x0;
TIM1_InitStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM1_InitStructure.TIM_Period = (10000-1);
TIM1_InitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM1_InitStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM1_InitStructure); /*SET TIM1 VAUALE*/
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_SetCounter(TIM1,0);
TIM_Cmd(TIM1,ENABLE);
}
//-------------------------------------------------------------------
void Interrupt_Configure(void)
{ NVIC_InitTypeDef NVIC_InitStructure;
NVIC_SetVectorTable(NVIC_VectTab_FLASH, 0x0000);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
} //-----------------------------------------------------------------------------
int main(void)
{ RCC_Configura();
GPIOD_Configure();
TIM1_Configure();
Interrupt_Configure();
GPIO_ResetBits(GPIOD, LED1|LED3);
while (1)
{ GPIO_SetBits(GPIOD,LED4);
delay(1000000);
GPIO_ResetBits(GPIOD,LED4);
delay(1000000);
}
}
//--------------------------------------------------------
以下是中断服务子程序
/////////////////////////////////////////////////////////////
void TIM1_UP_IRQHandler (void)
{ TIM_ClearFlag(TIM1,TIM_FLAG_Update);
GPIO_ResetBits(GPIOD,LED2);
GPIO_SetBits(GPIOD,LED1);
} |