Skip to main content
fiulala
Associate III
November 19, 2015
Question

GPIO 5V in AF

  • November 19, 2015
  • 3 replies
  • 750 views
Posted on November 19, 2015 at 19:03

Hi,

I wanted to know how could I have 5V in a pin associated with a timer. I do this configuration:

/*GPIOA Configuration: TIM9 CH1 (PA2)*/
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA, &GPIO_InitStructure);

If I try this pulling up with a resistor to 5V, I only get 3,3-3,5V in PA2. If I do the same but in Output Mode i get the 5V. So, how could I get 5V if the pin is in AF?
    This topic has been closed for replies.

    3 replies

    Mikk Leini
    Senior
    November 19, 2015
    Posted on November 19, 2015 at 20:47

    Hi,

    Which microcontroller are you using?

    Tesla DeLorean
    Guru
    November 19, 2015
    Posted on November 19, 2015 at 21:30

    For a static signal, I wouldn't expect GPIO/AF to make a difference, the control signals are upstream from the drive transistors.

    Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
    fiulala
    fiulalaAuthor
    Associate III
    November 20, 2015
    Posted on November 20, 2015 at 11:11

    Hi,

    Which microcontroller are you using? 0690X0000060MnQQAU.gif Sorry, I thought I had said that. I'm using stm32f4-disco.

    For a static signal

    ... Well I don't want a static signal I'm associating pin PA2 to TIM9 to make a square signal. I do like this:

    void TIM9_Configuration(void)

    {

    TIM_OCInitTypeDef TIM_OCInitStructure;

    TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;

    uint16_t Period;

    Period = 100000 / 10; // 10 Hz for 100kHz prescalled

    /* Time base configuration */

    TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 100000) - 1;

    TIM_TimeBaseStructure.TIM_Period = Period - 1;

    TIM_TimeBaseStructure.TIM_ClockDivision = 0;

    TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

    TIM_TimeBaseInit(TIM9, &TIM_TimeBaseStructure);

    /* Enable TIM9 Preload register on ARR */

    TIM_ARRPreloadConfig(TIM9, ENABLE);

    /* TIM PWM1 Mode configuration */

    TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_PWM1;

    TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;

    TIM_OCInitStructure.TIM_Pulse = Period / 2; // 50%

    TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

    /* Output Compare PWM1 Mode configuration: Channel1 PA.02 */

    TIM_OC1Init(TIM9, &TIM_OCInitStructure);

    TIM_OC1PreloadConfig(TIM9, TIM_OCPreload_Enable);

    /* TIM9 Main Output Enable */

    TIM_CtrlPWMOutputs(TIM9, ENABLE);

    /* TIM9 enable counter */

    TIM_Cmd(TIM9, ENABLE);

    }