开启TIM11更新中断代码
时间: 2023-07-02 19:22:48 浏览: 101
以下是开启TIM11更新中断的代码示例:
```
// 使能TIM11时钟
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11, ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 1000 - 1; // 设置自动重装载寄存器的值
TIM_TimeBaseStructure.TIM_Prescaler = 8400 - 1; // 设置时钟预分频值
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 设置时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // 设置计数器模式为向上计数
TIM_TimeBaseInit(TIM11, &TIM_TimeBaseStructure); // 初始化TIM11
// 配置TIM11更新中断
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_TRG_COM_TIM11_IRQn; // 设置中断通道为TIM11更新中断
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; // 设置抢占优先级
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1; // 设置子优先级
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM11, TIM_IT_Update, ENABLE); // 使能TIM11更新中断
TIM_Cmd(TIM11, ENABLE); // 使能TIM11
```
这段代码会使能TIM11的时钟,并配置TIM11的自动重装载寄存器值、预分频值、计数器模式等参数。然后,它会配置TIM11的更新中断,并使能TIM11更新中断。最后,它会使能TIM11。
阅读全文