cancel
Showing results for 
Search instead for 
Did you mean: 

timer 16 interupt not trigering on a stm32L432

PGood.1
Associate II

Im migrating the code from a stm32L031 to a stm32L432 and the timer interupt isnt triggering Ive set the LED to toggle in the CaptureCallback. This code works on a L031 using timer22. Clearly Im missing something obvious;

void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim)

{

 uint8_t byteindex;

 uint8_t byteoffset;

 HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);

 if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1)

 {

  new_cap = htim16.Instance->CCR1;

  if (new_cap > old_cap){

  time = new_cap - old_cap;

  }else{

  time = 65535 - old_cap + new_cap;

  }

  older_cap=old_cap;

  old_cap = new_cap;

}

void SystemClock_Config(void)

{

 RCC_OscInitTypeDef RCC_OscInitStruct = {0};

 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};

 RCC_PeriphCLKInitTypeDef PeriphClkInit = {0};

 /** Configure LSE Drive Capability

 */

 HAL_PWR_EnableBkUpAccess();

 __HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);

 /** Initializes the RCC Oscillators according to the specified parameters

 * in the RCC_OscInitTypeDef structure.

 */

 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSI|RCC_OSCILLATORTYPE_LSE

               |RCC_OSCILLATORTYPE_MSI;

 RCC_OscInitStruct.LSEState = RCC_LSE_ON;

 RCC_OscInitStruct.LSIState = RCC_LSI_ON;

 RCC_OscInitStruct.MSIState = RCC_MSI_ON;

 RCC_OscInitStruct.MSICalibrationValue = 0;

 RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;

 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;

 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;

 RCC_OscInitStruct.PLL.PLLM = 1;

 RCC_OscInitStruct.PLL.PLLN = 16;

 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV7;

 RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;

 RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;

 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

 {

  Error_Handler();

 }

 /** Initializes the CPU, AHB and APB buses clocks

 */

 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

               |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;

 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_1) != HAL_OK)

 {

  Error_Handler();

 }

 PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2;

 PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;

 if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)

 {

  Error_Handler();

 }

 /** Configure the main internal regulator output voltage

 */

 if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)

 {

  Error_Handler();

 }

 /** Enable MSI Auto calibration

 */

 HAL_RCCEx_EnableMSIPLLMode();

}

/**

 * @brief TIM16 Initialization Function

 * @param None

 * @retval None

 */

static void MX_TIM16_Init(void)

{

 /* USER CODE BEGIN TIM16_Init 0 */

 /* USER CODE END TIM16_Init 0 */

 TIM_IC_InitTypeDef sConfigIC = {0};

 /* USER CODE BEGIN TIM16_Init 1 */

 /* USER CODE END TIM16_Init 1 */

 htim16.Instance = TIM16;

 htim16.Init.Prescaler = 32;

 htim16.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim16.Init.Period = 65535;

 htim16.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim16.Init.RepetitionCounter = 0;

 htim16.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;

 if (HAL_TIM_Base_Init(&htim16) != HAL_OK)

 {

  Error_Handler();

 }

 if (HAL_TIM_IC_Init(&htim16) != HAL_OK)

 {

  Error_Handler();

 }

 sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING;

 sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI;

 sConfigIC.ICPrescaler = TIM_ICPSC_DIV1;

 sConfigIC.ICFilter = 0;

 if (HAL_TIM_IC_ConfigChannel(&htim16, &sConfigIC, TIM_CHANNEL_1) != HAL_OK)

 {

  Error_Handler();

 }

 /* USER CODE BEGIN TIM16_Init 2 */

 /* USER CODE END TIM16_Init 2 */

}

2 REPLIES 2

Not ALL the related code end-to-end.

Check the IRQHandler, the linkage (that the linker actually bound the code), and NVIC enabling..

TIM1_UP_TIM16_IRQHandler

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
PGood.1
Associate II

Got the IRQ handler going by adding HAL_TIM_IC_Start_IT(&htim16, TIM_CHANNEL_1); in the main() function