STM32F410-nucleo interval timer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2017-08-09 8:12 PM
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- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2017-08-10 4:15 AM
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?
