cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F410-nucleo interval timer

aditya patil
Associate
Posted on August 10, 2017 at 05:12

I am trying to code interval timer for stm32f410 nucleo demo board.

Following is the code wherein I try to set the on-board LED-2 GPIO_PIN_5 as indication but till now no success

Please following is the code ....need some help here.

Code:

   

/*******************************************************************************************************/

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){

 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_5,1);

 while(1);

 __HAL_TIM_CLEAR_FLAG(&TimHandle,TIMx_CC_IRQn);

}

/*******************************************************************************************************/

int timer_init1(){

 uint32_t uwPrescalerValue      = 0;

  uwPrescalerValue                   = (uint32_t) ((SystemCoreClock /2) / 50000) - 1; 

  TimHandle.Instance                = TIMx;    

  TimHandle.Init.Period             = 1;

  TimHandle.Init.Prescaler         = uwPrescalerValue;

  TimHandle.Init.ClockDivision  = TIM_CLOCKDIVISION_DIV1;

  TimHandle.Init.CounterMode  = TIM_COUNTERMODE_UP; 

 __HAL_TIM_CLEAR_IT(&TimHandle, TIMx_CC_IRQn);

 HAL_NVIC_SetPriority(TIMx_CC_IRQn, 0, 1);

  HAL_NVIC_EnableIRQ(TIMx_CC_IRQn);

  if(HAL_TIM_Base_Init(&TimHandle) != HAL_OK){

    Error_Handler();

  }

 if(HAL_TIM_Base_Start_IT(&TimHandle) != HAL_OK){

    Error_Handler();

  }

 

 return 0;

}

/*******************************************************************************************************/

void init_io(){

 GPIO_InitStruct.Pin  = GPIO_PIN_5;

 GPIO_InitStruct.Mode  = GPIO_MODE_OUTPUT_PP;

 GPIO_InitStruct.Pull  = GPIO_PULLUP;

 GPIO_InitStruct.Speed = GPIO_SPEED_FAST;

 HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

}

/*******************************************************************************************************/

int main(void){ 

 HAL_Init();

 SystemClock_Config();

 __HAL_RCC_GPIOA_CLK_ENABLE();

 __enable_irq();

 init_io();

 timer_init1();

 while(1){

 } 

}

Thanks,

-aditya Patil

#timer #smt32-nucleo #interrups
1 REPLY 1
Sebastian K.
Associate II
Posted on August 10, 2017 at 13:15

Hello,

maybe you can add some more information?

  • What is the behaviour you expect?
  • What is happening instead?

Some observations I made in your code:

  • Why is there a 'while (1);' in the callback? Wouldn't that lock the processor in an endless loop?
  • A timer 'Period' value of 1 seems very low - depending on the clock frequency you're running (which is not visible in your code), that would probably result in a very high timer frequency. Is that what you want?
  • Is 'TIMx' as timer handle even defined? You should replace that with the timer you want to use. Same goes for everything else with 'TIMx' in it...

Are you using CubeMX to generate the initial code, or where did you get that from?