本帖最后由 wenyangzeng 于 2018-3-18 16:50 编辑 这个在STM32CubeMX配置很方便呀: void HAL_TIM_IC_MspInit(TIM_HandleTypeDef* htim_ic) { GPIO_InitTypeDef GPIO_InitStruct; if(htim_ic->Instance==TIM3) { /* USER CODE BEGIN TIM3_MspInit 0 */ /* USER CODE END TIM3_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_TIM3_CLK_ENABLE(); /**TIM3 GPIO Configuration PB5 ------> TIM3_CH2 */ GPIO_InitStruct.Pin = GPIO_PIN_5; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW; GPIO_InitStruct.Alternate = GPIO_AF2_TIM3; HAL_GPIO_Init(GPIOB, &GPIO_InitStruct); /* USER CODE BEGIN TIM3_MspInit 1 */ /* USER CODE END TIM3_MspInit 1 */ } } /* TIM3 init function */ static void MX_TIM3_Init(void) { TIM_MasterConfigTypeDef sMasterConfig; TIM_IC_InitTypeDef sConfigIC; htim3.Instance = TIM3; htim3.Init.Prescaler = 0; htim3.Init.CounterMode = TIM_COUNTERMODE_UP; htim3.Init.Period = 0; htim3.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1; if (HAL_TIM_IC_Init(&htim3) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET; sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE; if (HAL_TIMEx_MasterConfigSynchronization(&htim3, &sMasterConfig) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } sConfigIC.ICPolarity = TIM_INPUTCHANNELPOLARITY_RISING; sConfigIC.ICSelection = TIM_ICSELECTION_DIRECTTI; sConfigIC.ICPrescaler = TIM_ICPSC_DIV1; sConfigIC.ICFilter = 0; if (HAL_TIM_IC_ConfigChannel(&htim3, &sConfigIC, TIM_CHANNEL_2) != HAL_OK) { _Error_Handler(__FILE__, __LINE__); } } 复制代码
所在话题
参与活动
-
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
网络 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16 -
滴滴押注社区团购,明确“投入不设上限,要做市场第一”
线下 2020-10-16