AnsweredAssumed Answered

STM32F4 Timer pinE5

Question asked by vink.remco on Mar 21, 2015
Latest reply on Mar 23, 2015 by waclawek.jan
Dear stm community,

I'm struggling with a problem that i can't get a timer to work.
Im trying to get the PINE5 Timer to work.

If I read everything well it has the TIM9_CH1 timer as alternating function.
So I wrote this code:

void InitializeTimer()
    int period = 500;
    RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM9, ENABLE);

    TIM_TimeBaseInitTypeDef timerInitStructure;
    timerInitStructure.TIM_Prescaler = 40000;
    timerInitStructure.TIM_CounterMode = TIM_CounterMode_Up;
    timerInitStructure.TIM_Period = period;
    timerInitStructure.TIM_ClockDivision = TIM_CKD_DIV1;
    timerInitStructure.TIM_RepetitionCounter = 0;
    TIM_TimeBaseInit(TIM9, &timerInitStructure);
    TIM_Cmd(TIM9, ENABLE);

void InitializePWMChannel()
    TIM_OCInitTypeDef outputChannelInit = {0,};
    outputChannelInit.TIM_OCMode = TIM_OCMode_PWM1;
    outputChannelInit.TIM_Pulse = 400;
    outputChannelInit.TIM_OutputState = TIM_OutputState_Enable;
    outputChannelInit.TIM_OCPolarity = TIM_OCPolarity_High;

    TIM_OC1Init(TIM9, &outputChannelInit);
    TIM_OC1PreloadConfig(TIM9, TIM_OCPreload_Enable);

    GPIO_PinAFConfig(GPIOE, GPIO_PinSource5, GPIO_AF_TIM9);

void Initializepin()
    RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOE, ENABLE);

    GPIO_InitTypeDef gpioStructure;
    gpioStructure.GPIO_Pin = GPIO_Pin_5;
    gpioStructure.GPIO_Mode = GPIO_Mode_AF;
    gpioStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_Init(GPIOE, &gpioStructure);

Can someone tell me where im making a mistake, or help me in the right direction?

any help would be appreciated.