stm32中斷解剖(非外部中斷)
疑問?
1.為什么不需要配置RCC_APB2Periph_AFIO
2 查看固件庫手冊 發(fā)現(xiàn)NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //選擇外部中斷3號線 與
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //選擇TIM2中斷 是結構體的不同值,怎么回事?
3TIME2是在什么情況下促使發(fā)生了TIM2_IRQChannel; 是定時器定時滿了?還是?TIM1有那么多中斷方式,那么TIM2的全局中斷時什么意思?
void NVIC_Configuration(void)//嵌套中斷配置
{
#ifdef VECT_TAB_RAM
NVIC_SetVectorTable(NVIC_VectTab_RAM,0x0);
#else
NVIC_SetVectorTable(NVIC_VectTab_FLASH,0x0);
#endif
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //選擇TIM2中斷
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;//
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2; //
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;//使能
NVIC_Init(&NVIC_InitStructure);
}
void TIM2_IRQHandler(void)
{
//USART_SendData(USART2,TIM3->CNT);
/****************此處有誤,但程序盡然正常跑,趣了怪了*******
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET)
{
}
******/
/**************改成**********if ( TIM_GetITStatus(TIM2 , TIM_IT_Update) != RESET )
TIM_ClearITPendingBit(TIM2 , TIM_FLAG_Update);//必須清除中斷標志位否則一直中斷
*****************/
Delay(100000);
printf("TIM3->wangwenwneCNT=%d",TIM3->CNT);//此函數已被我重定向(fputc())
}
int fputc(int ch,FILE * f)
{
USART_SendData(USART2,(unsigned char)ch);
while(USART_GetFlagStatus(USART2,USART_FLAG_TC)==RESET)
{
}
return(ch);
}
void TIMER2_PWM_Init(void)
{
/****配置時間基**********/
TIM_TimeBaseStructure.TIM_Period = 0xFFFF;
TIM_TimeBaseStructure.TIM_Prescaler = 0xFF;//分頻
TIM_TimeBaseStructure.TIM_ClockDivision = 0x0; //時鐘分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; //向上計數
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0x03;
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1; //模式
// TIM_OCInitStructure.TIM_Channel = TIM_Channel_1;
TIM_OCInitStructure.TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse=CCR1_Val;
TIM_OCInitStructure.TIM_OCPolarity=TIM_OCPolarity_Low;
TIM_OC1Init(TIM2,&TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2,TIM_OCPreload_Disable);
/**********************/
TIM_Cmd(TIM2,ENABLE);
TIM_ITConfig(TIM2,TIM_IT_CC1,ENABLE);
}
第一種方法:
NVIC_SETPRIMASK(); //關閉總中斷
NVIC_RESETPRIMASK(); //開放總中斷
第二種方法:
NVIC_SETFAULTMASK(); //關閉總中斷
NVIC_RESETFAULTMASK(); //開放總中斷
評論