开了定时器2的定时中断时,在切换内存卡里的图片显示时,出现卡死或者显示乱码,在关闭定时器2的定时中断时,不出现这样的问题,请问这是问什么了?下面时定时器2的配置
/// TIM2中断优先级配置
void TIM2_NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
/*
* TIM_Period / Auto Reload Register(ARR) = 1000 TIM_Prescaler--71
* 中断周期为 = 1/(72MHZ /72) * 1000 = 1ms
*
* TIMxCLK/CK_PSC //预分频?--> TIMxCNT --> TIM_Period(ARR) --> 中断 且TIMxCNT重置为0重新计数
*/
void TIM2_Configuration(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
/* 设置TIM2CLK 为 72MHZ */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , ENABLE);
//TIM_DeInit(TIM2);
/* 自动重装载寄存器周期的值(计数值) */
TIM_TimeBaseStructure.TIM_Period=10000; //10MS中断一次
/* 累计 TIM_Period个频率后产生一个更新或者中断 */
/* 时钟预分频数为72 */
TIM_TimeBaseStructure.TIM_Prescaler= 71;
/* 对外部时钟进行采样的时钟分频,这里没有用到 */
TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode=TIM_CounterMode_Up; //向上计数
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);//时基初始化
TIM_ClearFlag(TIM2, TIM_FLAG_Update);
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);//使能中断
TIM_Cmd(TIM2, ENABLE); //使能定时器2
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2 , DISABLE); /*先关闭等待使用*/
}
void TIM2_init(void)
{
TIM2_NVIC_Configuration();
TIM2_Configuration();
}
/*********************************************END OF FILE**********************/ |