cancel
Showing results for 
Search instead for 
Did you mean: 

Configure and initialize HALL Sensor to generate Interrupt in STM32F303VC

KE.1
Associate II

Hi Team,

I have configured Timer 2 to capture HALL sensor data

Timer 2 configuration

static void MX_TIM2_Init(void)

{

 /* USER CODE BEGIN TIM2_Init 0 */

 /* USER CODE END TIM2_Init 0 */

 TIM_ClockConfigTypeDef sClockSourceConfig = {0};

 TIM_HallSensor_InitTypeDef sConfig = {0};

 TIM_MasterConfigTypeDef sMasterConfig = {0};

 /* USER CODE BEGIN TIM2_Init 1 */

 /* USER CODE END TIM2_Init 1 */

 htim2.Instance = TIM2;

 htim2.Init.Prescaler = 0;

 htim2.Init.CounterMode = TIM_COUNTERMODE_UP;

 htim2.Init.Period = 65535;

 htim2.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;

 htim2.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;

 if (HAL_TIM_Base_Init(&htim2) != HAL_OK)

 {

  Error_Handler();

 }

 sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;

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

 {

  Error_Handler();

 }

 sConfig.IC1Polarity = TIM_ICPOLARITY_RISING;

 sConfig.IC1Prescaler = TIM_ICPSC_DIV1;

 sConfig.IC1Filter = 15;

 sConfig.Commutation_Delay = 0;

 if (HAL_TIMEx_HallSensor_Init(&htim2, &sConfig) != HAL_OK)

 {

  Error_Handler();

 }

 sMasterConfig.MasterOutputTrigger = TIM_TRGO_OC2REF;

 sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;

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

 {

  Error_Handler();

 }

 /* USER CODE BEGIN TIM2_Init 2 */

 /* USER CODE END TIM2_Init 2 */

}

Code

 HAL_Init();

 /* USER CODE BEGIN Init */

 /* USER CODE END Init */

 /* Configure the system clock */

 SystemClock_Config();

 MX_TIM2_Init();

 HAL_TIMEx_HallSensor_Start(&htim2);

 /* Initialize interrupts */

 MX_NVIC_Init();

 /* USER CODE BEGIN 2 */

 /* USER CODE END 2 */

 /* Infinite loop */

 /* USER CODE BEGIN WHILE */

 while (1)

 {

  /* USER CODE END WHILE */

  /* USER CODE BEGIN 3 */

 }

But interrupt is not generated even if the hall sensor output is changed can you please help in resolving this issue

Thanks,

Krupashankar

1 REPLY 1

Read out and the GPIO registers relevant to the given pin, and check if MODER is set to AF and AFR set to the proper AF number as per datasheet for the TIM channel you intend to use.

Read out the TIM registers and check if the given channel is set to Input Capture in CCMRx, if it's enabled in CCERx, and if the relevant interrupt is enabled in DIER.

Some other interrupt-related hints here.

JW