当前位置:网站首页>Stm32f030 is stuck with timer interrupt
Stm32f030 is stuck with timer interrupt
2022-07-18 09:36:00 【Little tiger_ IOT】
1、 What happened
Initialize the timer , To configure NVIC, And then run , It's stuck .
The original code is as follows :
// Initialize the timer 2,10ms,NVIC Set interrupt priority
static void timer2_init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
// Timer TIM2 initialization -> 10ms
TIM_TimeBaseStructure.TIM_Period = 99; // The value of the automatic reload register cycle
TIM_TimeBaseStructure.TIM_Prescaler = 7199; // Set as TIMx Prescaled value of clock frequency divisor
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // Set the clock split :TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//TIM Upcount mode
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // Initialize... According to the specified parameters TIMx Unit of time base
// Interrupt priority NVIC Set up
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM2 interrupt
NVIC_InitStructure.NVIC_IRQChannelPriority = 1; // priority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ The channel is energized
NVIC_Init(&NVIC_InitStructure); // initialization NVIC register
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); // Enable to designate TIM2 interrupt , Allow update interrupt
TIM_Cmd(TIM2,ENABLE); // Enable timer
}void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET){ // Check TIM2 Whether the update interrupt occurs or not
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // eliminate TIMx Update interrupt flag
}
}2、 Analyze and solve
Let's see which piece of code caused it , So first, the whole timer initialization part is commented , normal , So the problem location needs timer initialization .
Initialize the timer according to the parameters , It doesn't feel like a problem , If you write wrong, you won't get stuck ,NVIC Configuration involves interruption , So it may be the problem of interrupting this part , The comments NVIC_Init The normal , So the problem lies in the configuration of timer interrupt .
A flash of light , Thought of a mistake ( Actually, it's not hahaha ),main There is no setting in the function NVIC grouping , And found that F030 No NVIC Grouping .
then , Search for information according to this phenomenon , Different problems lead to different solutions , In the end stay TIM_ITConfig The clear interrupt flag is added before TIM_ClearITPendingBit(TIM2, TIM_IT_Update); , strange , I haven't met this problem before , Is it F030 Peculiar ? If you know , generous with your criticism , thank you .
Modern code :
// Initialize the timer 2,10ms,NVIC Set interrupt priority
static void timer2_init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
// Timer TIM2 initialization -> 10ms
TIM_TimeBaseStructure.TIM_Period = 99; // The value of the automatic reload register cycle
TIM_TimeBaseStructure.TIM_Prescaler = 7199; // Set as TIMx Prescaled value of clock frequency divisor
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; // Set the clock split :TDTS = Tck_tim
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//TIM Upcount mode
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); // Initialize... According to the specified parameters TIMx Unit of time base
// Interrupt priority NVIC Set up
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //TIM2 interrupt
NVIC_InitStructure.NVIC_IRQChannelPriority = 1; // priority
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; //IRQ The channel is energized
NVIC_Init(&NVIC_InitStructure); // initialization NVIC register
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); // eliminate TIMx Update interrupt flag
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); // Enable to designate TIM2 interrupt , Allow update interrupt
TIM_Cmd(TIM2,ENABLE); // Enable timer
}边栏推荐
- Codeforces Round #804 C The Third Problem
- Shiro integrates redis to realize distributed session processing
- internship:移动端源码的分析
- sql语句
- 构建数据基础制度,开启OID赛道新纪元
- Codeforces Round #803 (Div. 2) D. Fixed Point Guessing
- 成长一夏 挑战赛|跟大佬学习 / 创作,得CSDN大礼包、专属荣誉证书、纪念T恤和勋章!
- Exness: crude oil stopped falling and rebounded. Pay attention to the performance of US terrorist data in the evening
- Codeforces Round #803 (Div. 2) A. XOR Mixup
- Nest framework
猜你喜欢

Leetcode-128-longest continuous sequence

构建数据基础制度,开启OID赛道新纪元

leetcode双指针水题题解

Codeforces Round #802 B. Palindromic Numbers

6-Redis架构设计到使用场景-持久化机制、缓存失效策略、缓存命中率

2022-7-15 Leetcode 151.颠倒字符串中的单词 —— 【从后往前分割】

Codeforces Round #802 B. Palindromic Numbers

Leetcode-240-search two-dimensional matrix II

Codeforces Round #804 C The Third Problem

Flutter 模拟火箭发射动画
随机推荐
svg loading动画
Help, update to Siyuan v2.0.27, dark+ theme adaptive width problem
nacos win10单机启动命令
Tengshi's new luxury medium and large MPV is exposed, safe and comfortable
功能、模块质量和非功能性测试
[mt2126] Digital Games
Seaborn - 绘制多标签的混淆矩阵、召回、精准、F1
2022-7-15 Leetcode 151.颠倒字符串中的单词 —— 【从后往前分割】
Win11系统.NET Framework 3.5怎么启用?
AIRIOT答疑第4期|如何使用數據分析引擎?
Codeforces Round #803 (Div. 2) D. Fixed Point Guessing
Educational Codeforces Round 131 A - D
日志的管理与应急处理
openGauss 联合产业界创新,共建开源数据库根社区
Codeforces Round #806 (Div. 4) A - G
Codeforces Global Round 21 C. Fishingprince Plays With Array
迪赛智慧数——折(渐变堆叠图):全国居民人均可支配收入
STM32F030使用定时器中断卡死的问题
408天勤第八章排序课内代码合集
4-Redis架构设计到使用场景-Redis请求执行过程