cancel
Showing results for 
Search instead for 
Did you mean: 

Timer GPIO problem

cool26happy
Associate II
Posted on October 25, 2014 at 15:36

Hello everyone.

I use STM32F4 Discovery. When I config timer (Time base) GPIO peripherals does not work. Timer is work, and GPIO is work (widthout timer configuration).

Where is a problem?

Best regards.
9 REPLIES 9
cool26happy
Associate II
Posted on October 25, 2014 at 15:43

Problem is in this line... 

TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);

Why?

When I comment this, GPIO is work.

Posted on October 25, 2014 at 16:00

Do you service the interrupt? What does the debugger suggest?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cool26happy
Associate II
Posted on October 25, 2014 at 16:08

void TIM7_IRQHandler(void)

{

TIM_ClearITPendingBit(TIM7, TIM_IT_Update);

Counter++;

if(Counter==1000)

{

Counter=0;

printf(''\n Interrupt'');

}

}

This is working corectly. :\

cool26happy
Associate II
Posted on October 25, 2014 at 16:54

I connected LED on D0 and LED is lighting. In debug mode, after this...

TIM_ITConfig(TIM7, TIM_IT_Update, ENABLE);

LED is off. 

Posted on October 25, 2014 at 17:19

So are we supposed to randomly guess what you're doing until we figure it out?

Present the code that illustrates your problem.

You need to make sure you correctly configure the timebase and the output channel modes, along with the pins and the AF muxing. Make sure to initialize all fields of the timer functions, local/auto variables may contain random junk on the stack, and this can lead to undefined operation.
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on October 25, 2014 at 17:22

Is printf() under interrupt a good plan. It is rather slow and assumes you're sending the data somewhere.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cool26happy
Associate II
Posted on October 25, 2014 at 17:33

#include ''stm32f4xx.h''

#include ''stm32f4xx_syscfg.h''

#include ''stm32f4xx_rcc.h''

#include ''stm32f4xx_gpio.h''

#include ''stm32f4xx_exti.h''

#include ''stm32f4xx_tim.h''

#include ''misc.h''

void Timer_Config(void)

{

TIM_TimeBaseInitTypeDef  TIM_TimeBaseStructure;

NVIC_InitTypeDef NVIC_InitStructure;

RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE);

TIM_TimeBaseStructure.TIM_Prescaler = 84 - 1;

TIM_TimeBaseStructure.TIM_Period = 1000 - 1; 

TIM_TimeBaseStructure.TIM_ClockDivision = 0;

TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;

TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure);

NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;

NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;

NVIC_InitStructure.NVIC_IRQChannelSubPriority = 2;

NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&NVIC_InitStructure);

TIM_ITConfig(TIM3, TIM_IT_Update, ENABLE);

TIM_Cmd(TIM3, ENABLE);

}

void LED_Config(void)

{

GPIO_InitTypeDef GPIO_InitStructure;

GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;

GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0;

GPIO_Init(GPIOD, &GPIO_InitStructure);

}

void TIM3_IRQHandler(void)

{

TIM_ClearITPendingBit(TIM3, TIM_IT_Update);

}

int main()

{

Timer_Config();

LED_Config();

GPIOD->BSRRL = GPIO_Pin_0;

while(1)

{

}

}

Posted on October 25, 2014 at 17:53

That code isn't going to do anything with the pin now is it? Perhaps you should toggle in the interrupt, and then scope if the frequency is too high to perceive.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
cool26happy
Associate II
Posted on October 25, 2014 at 18:30

Timer starts AD conversion on external ADC when LED=1 (LED is indicator). But, when timer is configuration, GPIO does not work. I put code for LED on in timer, but this is not solution. In this example, LED on is in the main because understanding a problem with GPIO.