Timer STM32F103计时器IRQ处理程序从不执行
我试图设置一个每1ms执行一次的计时器,以估计函数的执行时间。我把代码附在这篇文章的末尾。我对计时器的配置非常确定,因为我在Mo_AHRS_连续演示中对一个正在工作的演示只做了很少的修改,甚至prvFindFactors的函数也被这样的演示所采用。 不幸的是,在这种情况下,我的ISR从未执行过,你知道原因吗?谢谢Timer STM32F103计时器IRQ处理程序从不执行,timer,embedded,interrupt,stm32,interrupt-handling,Timer,Embedded,Interrupt,Stm32,Interrupt Handling,我试图设置一个每1ms执行一次的计时器,以估计函数的执行时间。我把代码附在这篇文章的末尾。我对计时器的配置非常确定,因为我在Mo_AHRS_连续演示中对一个正在工作的演示只做了很少的修改,甚至prvFindFactors的函数也被这样的演示所采用。 不幸的是,在这种情况下,我的ISR从未执行过,你知道原因吗?谢谢 void iNemoProfilerConfig(void) { unsigned short a; unsigned short b; unsigned long n;
void iNemoProfilerConfig(void)
{
unsigned short a;
unsigned short b;
unsigned long n;
/* This value is the frequency interrupts in Hz */
unsigned short frequency = 1000;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable timer clocks */
RCC_APB1PeriphClockCmd( RCC_APB1Periph_TIM4, ENABLE );
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
TIM_TimeBaseStructInit( &TIM_TimeBaseStructure );
/* Time base configuration for timer 2 - which generates the interrupts. */
n = SystemCoreClock/frequency;
prvFindFactors( n, &a, &b );
TIM_TimeBaseStructure.TIM_Period = b - 1;
TIM_TimeBaseStructure.TIM_Prescaler = a - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit( TIM4, &TIM_TimeBaseStructure );
TIM_ARRPreloadConfig( TIM4, ENABLE );
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 13;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init( &NVIC_InitStructure );
}
void Enable_Timer4(FunctionalState command) {
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
TIM_ITConfig( TIM4, TIM_IT_Update, command );
}
void TIM4_IRQHandler(void)
{
USART1_Printf("INTERRUPT = %i \r\n", counter);
if(TIM_GetITStatus(TIM4, TIM_IT_Update))
{
//xTim2Raised=SET;
counter++;
/* Clear the IRQ bit */
TIM_ClearITPendingBit(TIM4, TIM_IT_Update);
}
}
//main chunk
int main(void)
{
SystemInit();
/* At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
USART1_Init();
for(uint32_t i=0; i<0xFFFFF;i++);
iNemoTimerConfig();
iNemoProfilerConfig();
iNEMO_AHRS_Start();
LSM_Start();
L3G_Start();
/* Wait some seconds in order to ensure the user opens the VCOM terminal */
for(uint32_t i=0;i<0x1FFFFFF;i++);
Enable_Timer(ENABLE);
Enable_Timer4(ENABLE);
while(1)
{
counter = 0;
iNEMO_AHRS_Attitude();
USART1_Printf("counter = %i \r\n", counter);
ISR是否执行过一次?您是否试图在ISR中对USART1_Printf进行注释。我担心main while1上的printf和isr中的printf在中断处理程序中从不使用printf或类似的东西!这可能会导致大量运行时问题。如果需要,只需在变量中存储一个单词左右。更糟糕的是,选择USART将产生中断溢出:对于115200 UART链路,每个字符占用约9us。所以~11个字符等于1ms,这与计时器的周期有关。不计算发送到其他地方的数据。关于这个问题:处理程序真的没有被调用吗?在处理器上尝试一个断点。停止STM32F的CPU时,计时器可以自动停止,因此不会丢失。。