cancel
Showing results for 
Search instead for 
Did you mean: 

Timer2 Configuration

DOSS FOF
Associate II
Posted on May 15, 2017 at 10:47

I'm working on STM32 nucleo432lkc. I'm trying to divide the MSI frequency for the timer by 50 but when I try this , i get nothing on the ouput of the pin. Below is the timer 2 code :

void TIM2_init(void)

{

      TIM_ClockConfigTypeDef sClockSourceConfig;

      TIM_MasterConfigTypeDef sMasterConfig;

    __TIM2_CLK_ENABLE();

    TIM_init_struct.Instance = TIM2;

    TIM_init_struct.Init.Prescaler = 0 ;//40000;

    TIM_init_struct.Init.CounterMode = TIM_COUNTERMODE_UP;

    TIM_init_struct.Init.Period = 0 ;//491;

    TIM_init_struct.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

    TIM_init_struct.Init.RepetitionCounter = 0;

    //HAL_TIM_Base_Init(&TIM_init_struct);

    if(HAL_TIM_Base_Init(&TIM_init_struct)== HAL_OK)

      {

        /* Start the TIM time Base generation in interrupt mode */

        HAL_TIM_Base_Start_IT(&TIM_init_struct);

      }

    HAL_NVIC_SetPriority(TIM2_IRQn, 0, 1);

    HAL_NVIC_EnableIRQ(TIM2_IRQn);

     sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

      if (HAL_TIM_ConfigClockSource(&TIM_init_struct, &sClockSourceConfig) != HAL_OK)

      {

          TIM_Error_Handler();

      }

      sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;

      sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

      if (HAL_TIMEx_MasterConfigSynchronization(&TIM_init_struct, &sMasterConfig) != HAL_OK)

      {

          TIM_Error_Handler();

      }

}

void TIM2_IRQHandler()

{

    //}

     HAL_TIM_IRQHandler(&TIM_init_struct);

}

#include 'stdbool.h'

bool test = false;

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)

{

    int timerValue =  HAL_RCC_GetSysClockFreq();

    if (test) {

        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_RESET);

        test = false;

    } else {

        HAL_GPIO_WritePin(GPIOB, GPIO_PIN_0, GPIO_PIN_SET);

        test = true;

    }

//    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_0);

    HAL_GPIO_TogglePin(GPIOB, GPIO_PIN_3);

}

10 REPLIES 10
Posted on May 23, 2017 at 10:06

Hello,

It's Ok now.

Thanks