cancel
Showing results for 
Search instead for 
Did you mean: 

stm32f10c-eval timer1 problem

sukrubahadirarslan
Associate III
Posted on October 29, 2013 at 12:53

hi 

I am trying to use timer 1 in stm3210c-eval.

I wrote this code below.

My problem is : counter starts counting but my program doesnt go to the ISR .

so whats the problem ?

here is my code :

#include ''stm32f10x.h''

#include ''stm32_eval.h''

#include ''stm32f10x_tim.h''

#include <stdio.h>

TIM_TimeBaseInitTypeDef timer_base_config_anahtari;

TIM_OCInitTypeDef timer_output_config_anahtari;

NVIC_InitTypeDef nvic_config_anahtari;

GPIO_InitTypeDef gpio_config_anahtari;

void timerbase_configuration(void);

void timer_output_compare_configure_et(void);

void nvic_configuration(void);

void rcc_configuration(void);

void gpio_configuration(void);

void TIM1_UP_IRQHandler()

{

uint8_t bitdurumu;

bitdurumu = GPIO_ReadOutputDataBit(GPIOD,GPIO_Pin_7);

if(bitdurumu == Bit_SET)

{

GPIO_ResetBits(GPIOD,GPIO_Pin_7);

}

else

{

GPIO_SetBits(GPIOD,GPIO_Pin_7);

}

TIM_ClearFlag(TIM1,TIM_FLAG_Update);

TIM_ClearITPendingBit(TIM1,TIM_IT_Update);

}

int main(void)

{

rcc_configuration();

nvic_configuration();

gpio_configuration();

  timerbase_configuration(); 

  while (1)

  {

  }

}

#ifdef  USE_FULL_ASSERT

/**

  * @brief  Reports the name of the source file and the source line number

  *         where the assert_param error has occurred.

  * @param  file: pointer to the source file name

  * @param  line: assert_param error line source number

  * @retval None

  */

void assert_failed(uint8_t* file, uint32_t line)

  /* User can add his own implementation to report the file name and line number,

     ex: printf(''Wrong parameters value: file %s on line %d\r\n'', file, line) */

  /* Infinite loop */

  while (1)

  {

  }

}

#endif

void rcc_configuration()

{

RCC_HCLKConfig(RCC_SYSCLK_Div1);

RCC_PCLK2Config(RCC_HCLK_Div16);   .

RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD,ENABLE);

RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);

}

void timerbase_configuration()

{

timer_base_config_anahtari.TIM_CounterMode = TIM_CounterMode_Up;

timer_base_config_anahtari.TIM_Period = 0xC350;       

timer_base_config_anahtari.TIM_Prescaler = 144;

timer_base_config_anahtari.TIM_RepetitionCounter = 10;

timer_base_config_anahtari.TIM_ClockDivision = TIM_CKD_DIV1; 

TIM_TimeBaseInit(TIM1,&timer_base_config_anahtari); TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);

TIM_Cmd(TIM1,ENABLE);

}

void gpio_configuration()

{

gpio_config_anahtari.GPIO_Mode = GPIO_Mode_Out_PP;

gpio_config_anahtari.GPIO_Pin = GPIO_Pin_7;

gpio_config_anahtari.GPIO_Speed =GPIO_Speed_2MHz;

GPIO_Init(GPIOD,&gpio_config_anahtari);

}

void nvic_configuration()

{

nvic_config_anahtari.NVIC_IRQChannel = TIM1_UP_IRQn ;

nvic_config_anahtari.NVIC_IRQChannelPreemptionPriority =0x0f;

nvic_config_anahtari.NVIC_IRQChannelSubPriority = 0x0f;

nvic_config_anahtari.NVIC_IRQChannelCmd = ENABLE;

NVIC_Init(&nvic_config_anahtari);

thanks for your help

1 REPLY 1
Posted on October 29, 2013 at 16:53

Doesn't look too bad, but I don't have a STM3210C-EVAL

Check what tool chain you are using, compiling as C++/CPP file instead of C, that the startup_stm32f1xx.s is suitable for CL series chip, etc. Check IRQHandler name in .MAP file, confirm linkage.

Might also want to enable PWM outputs on TIM1, not sure it's needed here.

Have you break-pointed the IRQ in the debugger?
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..