疑问?
1.为什么不需要配置RCC_APB2Periph_AFIO
2 查看固件库手册 发现NVIC_InitStructure.NVIC_IRQChannel = EXTI3_IRQn; //选择外部中断3号线 与
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQChannel; //选择TIM2中断 是结构体的不同值,怎么回事?
3TIME2是在什么情况下促使发生了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(); //开放总中断
上一篇:高压电源之LCC谐振变换原型
下一篇:ARM吴雄昂:物联网需要开放的生态系统
推荐阅读最新更新时间:2024-03-16 14:04