Home > other >  STM32 timer interrupt cannot enter the interrupt handler
STM32 timer interrupt cannot enter the interrupt handler

Time:10-16

Intends to use TIM3_CH1 channel output pulse, and then declare a global variable steps, in the TIM3 interrupt to the decrement count steps, so as to realize the pulse TIM3_CH1 only a specified number of steps,
The PC6 - & gt; Led7 (normal TIM3_CH1 connection port),
PC1 - & gt; Led2 (interrupt function control port),
PC0 - & gt; Led1 (port) inside the main function control (defined has been led. H ok, including belt operation)
But found that when debugging led7 will blink, but will not stop, indicates that the actual can't did not enter the interrupt,
But a strange phenomenon is that when I added to the following comments to that part of the cycle code, after all normal,
Led1, led2, led7 all normal blinking, led2 stop after flashing 5 times, led7 stop after flashing 10 times, completely normal, only led1 is not as expected flashing stopped five times, it's hard to know what reason is this? Please tell the great god,
The code is as follows:
# include "system. H
"# include "SysTick. H"
Extern under-16 steps;

Int main ()
{
/* int I=5; */
SysTick_Init (72);
LED_Init ();
Move (10);
/* while (I)
{
Led1=0;
Delay_ms (200);
Led1=1;
Delay_ms (200);
i--;
} */
}

The following is a timer configuration function
# include "StepperDriverTIM3. H"

Under-16 steps;//global variables, to record the pulse number, inside the interrupt function since the subtract
Int led2Status=0;//record the current state of the led2

Void Move (under-16 num)
{
NVIC_InitTypeDef NVIC_InitStructure;

Steps=num;

TIM3_CH1_PWM_Init (7200 * 5-2000-1, 1);

TIM_SetCompare1 (TIM3, 1500);

TIM_ITConfig (TIM3, TIM_IT_Update, ENABLE);
NVIC_PriorityGroupConfig (NVIC_PriorityGroup_1);

NVIC_InitStructure. NVIC_IRQChannel=TIM3_IRQn;
NVIC_InitStructure. NVIC_IRQChannelPreemptionPriority=0;
NVIC_InitStructure. NVIC_IRQChannelSubPriority=2;
NVIC_InitStructure. NVIC_IRQChannelCmd=ENABLE;
NVIC_Init (& amp; NVIC_InitStructure);
}

Void TIM3_CH1_PWM_Init (under-16 per, under-16 PSC)
{
GPIO_InitTypeDef GPIO_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;

RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC, ENABLE);
RCC_APB1PeriphClockCmd (RCC_APB1Periph_TIM3, ENABLE);
RCC_APB2PeriphClockCmd (RCC_APB2Periph_AFIO, ENABLE);

GPIO_InitStructure. GPIO_Pin=GPIO_Pin_6;
GPIO_InitStructure. GPIO_Speed=GPIO_Speed_50MHz;
GPIO_InitStructure. GPIO_Mode=GPIO_Mode_AF_PP;
GPIO_Init (GPIOC, & amp; GPIO_InitStructure);

GPIO_PinRemapConfig (GPIO_FullRemap_TIM3, ENABLE);

TIM_DeInit (TIM3);
TIM_TimeBaseInitStructure. TIM_Period=per;
TIM_TimeBaseInitStructure. TIM_Prescaler=PSC;
TIM_TimeBaseInitStructure. TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInitStructure. TIM_CounterMode=TIM_CounterMode_Up;
TIM_TimeBaseInit (TIM3, & amp; TIM_TimeBaseInitStructure);

TIM_OCInitStructure.TIM_OCMode=TIM_OCMode_PWM1;
TIM_OCInitStructure. TIM_OutputState=TIM_OutputState_Enable;
TIM_OCInitStructure. TIM_Pulse=per/2;
TIM_OCInitStructure. TIM_OCPolarity=TIM_OCPolarity_Low;
TIM_OC1Init (TIM3, & amp; TIM_OCInitStructure);

TIM_OC1PreloadConfig (TIM3, TIM_OCPreload_Enable);
TIM_ARRPreloadConfig (TIM3, ENABLE);

TIM_Cmd (TIM3, ENABLE);

TIM_ClearFlag (TIM3, TIM_FLAG_Update);
TIM_ITConfig (TIM3, TIM_IT_Update, DISABLE);
}

Void TIM3_IRQHandler (void)
{
If (TIM_GetITStatus (TIM3, TIM_IT_Update)!=RESET)
{
Steps -;
Led2=led2Status;
1 - led2Status led2Status=;
if(! Steps)
{
TIM_ITConfig (TIM3, TIM_IT_Update, DISABLE);
TIM_Cmd (TIM3, DISABLE);
}
TIM_ClearITPendingBit (TIM3, TIM_IT_Update);
}
}

# # ifndef _led_H
# define _led_H

# include "system. H
"
# define LED_PORT GPIOC
# define LED_PIN (GPIO_Pin_0 | GPIO_Pin_1 | GPIO_Pin_2 | GPIO_Pin_3 | GPIO_Pin_4 | GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7)
# define LED_PORT_RCC RCC_APB2Periph_GPIOC


# define led1 PCout (0)
# define led2 PCout (1)
# define led3 PCout (2)

Void LED_Init (void);

CodePudding user response:

Supplement, use STM32F103ZET6 board, will is my port is occupied by a what? But did not open port multiplexing clock on principle, isn't it wouldn't be there to take up the problem?

CodePudding user response:

Have found the reason, the main function it forgot to make an infinite loop, to wait for interrupt,

CodePudding user response:

Want to see multiple timers work state definition of identification at the same time, I do together, mark, too
  • Related