AnsweredAssumed Answered

Problem trying to write a timer program counting edges

Question asked by yao.randy.001 on Jun 6, 2014
Latest reply on Jun 6, 2014 by yao.randy.001
Hey ST,

I'm using STM32F4DISCOVERY board, and tried to write a counter for rising and falling edges using timer input capture mode. Couldn't capture anything though. Any ideas what's wrong would be appreciated.

Also, does anyone know what TIM_ICFilter, GPIO_OType does?

Thanks in advance.
//PA5 -> TIM2
#include "stm32f4xx_dma.h"
#include "stm32f4xx_exti.h"
#include "stm32f4xx_gpio.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_tim.h"
#include "semihosting.h"

void GPIO_Config(void);
void TIM_IC_Config(void);

//Global Variables
uint32_t count;

int main(void)

         count = TIM_GetCapture1(TIM2);
         printf("\nTIM: %d",count);

void GPIO_Config(void)
     RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); //tim1? cannot unable?

     GPIO_InitTypeDef gpio;
     gpio.GPIO_Pin = GPIO_Pin_5;
     gpio.GPIO_Mode = GPIO_Mode_AF;
     gpio.GPIO_PuPd = GPIO_PuPd_NOPULL;
     gpio.GPIO_Speed = GPIO_Speed_50MHz;
     gpio.GPIO_OType = GPIO_OType_PP; //What is this actually?
     GPIO_Init(GPIOA, &gpio);

void TIM_IC_Config(void)
     //TIM2 Channel 1
     TIM_ICInitTypeDef tim;
     tim.TIM_Channel = TIM_Channel_1;
     tim.TIM_ICPolarity = TIM_ICPolarity_BothEdge; //Both up and down edge
     tim.TIM_ICSelection = TIM_ICSelection_DirectTI; //??? direct vs indirect
     tim.TIM_ICPrescaler = TIM_ICPSC_DIV2;
     tim.TIM_ICFilter = 0x00; //?