I don't know if the title is correct. This is the first time I use interrupt handlers. My problem is that I am trying to configure capture for one axis (axis 1) using PB8, TIM4, Channel3.
This is my code:
void TIM4_Config() { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4, ENABLE); RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOB, ENABLE); /* TIM4 channel 3 pin (PB8) configuration */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL; GPIO_Init(GPIOB, &GPIO_InitStructure); GPIO_PinAFConfig(GPIOB, GPIO_PinSource8, GPIO_AF_TIM4); TIM_ICInitTypeDef TIM_ICInitStructure; TIM_ICInitStructure.TIM_Channel = TIM_Channel_3; TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising; TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI; TIM_ICInitStructure.TIM_ICPrescaler = 84 - 1; TIM_ICInitStructure.TIM_ICFilter = 0x0; TIM_ICInit(TIM4, &TIM_ICInitStructure); irq_attach(STM32_IRQ_TIM4, handlerTimer4); up_prioritize_irq(STM32_IRQ_TIM4, 1); up_enable_irq(STM32_IRQ_TIM4); TIM_ITConfig(TIM4, TIM_IT_CC3, ENABLE); /* TIM enable counter */ TIM_Cmd(TIM4, ENABLE); } int handlerTimer4(int i, void* c) { if (TIM_GetITStatus(TIM4, TIM_IT_CC3) != RESET) { TIM_ClearITPendingBit(TIM4, TIM_IT_CC3); ++count; value = TIM_GetCapture3(TIM4); device_->GetCurrentPosition(OfaAxisEnum::OFA_Z, currentPosition); } else { TIM_ClearITPendingBit(TIM4, TIM_IT_CC3); } TIM_ClearFlag(TIM4, TIM_FLAG_CC3) ; }
The thing is that the handler gets called (I put a breakpoint inside the handler), but I am doing the capture setup inside a motion command. So the handler gets called while doing the motion, but I thing it will get stuck inside the handler because the motion doesnt happend.
I did the same thing(same code, except I changed timer, channel, and GPIO) for another axis (axis 0) using PI0, TIM5, Channel4, and it worked well.
Anyone has an idea what my problem could be ? I can't figure it out, the setup I guess should be ok if the handler its called.