如何在输入捕获模式下启动STM32定时器?

时间:2014-04-21 15:21:40

标签: input timer embedded stm32

我有一个STM32F4 MCU,我正在编写一个定时器驱动程序。我想将输入捕获功能添加到计时器,但无法实现,所以我有几个问题:

  1. 如何配置我打算用于信号输入的GPIO引脚? 目前我用这个:

    #define GPIO_PPM_PIN (GPIO_ALT|GPIO_AF1|GPIO_PULLUP|GPIO_PORTB|GPIO_PIN4)
    
  2. 如何配置计时器?我遵循参考手册所说的一切,但这没有帮助

  3. 以下是我的定时器寄存器配置示例(对于通道1):

            config->regs->CR1 = 0;
            config->regs->CR2 = 0;
            config->regs->SMCR = 0;
            config->regs->DIER = GTIM_DIER_CC1IE; //enable interrupt request
    
            config->regs->CCER = 0; // unlock CCMR registers
            config->regs->CCMR1 = GTIM_CCMR_CCS_CCIN1 << GTIM_CCMR1_CC1S_SHIFT;
            config->regs->CCMR2 = 0; //
            config->regs->CCER = (GTIM_CCER_CC1E | GTIM_CCER_CC1P | GTIM_CCER_CC1NP);
            config->regs->DCR = 0;
    
            config->regs->PSC = (config->clock / 1000000) - 1;
            config->regs->ARR = 0xFFFF;
            config->regs->CCR1 = 1000;
            config->regs->EGR = GTIM_EGR_UG;
            config->regs->CR1 = GTIM_CR1_CEN;
    
            up_enable_irq(config->interrupt);
    
            stm32_configgpio(GPIO_INPUT_PIN);
    

    谢谢!

0 个答案:

没有答案