true 发表于 2017-9-26 09:13:12

分享:STM32CubeMX基本定时器

芯片:STM32F103C8T6应用管脚:输出:PA0、PA1TIM3实现1ms定时功能,系统TIMx_CNT=8MHZ=8000 000HZ,设置TIMx_PSC=800-1,那么TIMx_ARR=(TIMx_CNT/TIMx_PSC)*定时器时间=(8000000/800)*0.001=10,TIMx_ARR=10-1。配置界面
http://img.blog.csdn.net/20160803105542775?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
TIM3配置http://img.blog.csdn.net/20160803105636713?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
开启NVIC中断配置http://img.blog.csdn.net/20160803110429919?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center
程序中增加回调函数
view plain copy



[*]/* USER CODE BEGIN 4 */
[*]/**
[*]* @briefPeriod elapsed callback in non blocking mode
[*]* @paramhtim : TIM handle
[*]* @retval None
[*]*/
[*]void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
[*]{
[*]    if(htim==&htim3)
[*]    {
[*]            HAL_GPIO_WritePin(GPIOA,GPIO_PIN_0,(GPIO_PinState)!HAL_GPIO_ReadPin(GPIOA,GPIO_PIN_0));
[*]    }
[*]}
[*]/* USER CODE END 4 */

启动TIM3定时器
view plain copy



[*]/* USER CODE BEGIN 2 */
[*]AL_TIM_Base_Start_IT(&htim3);
[*]/* USER CODE END 2 */


页: [1]
查看完整版本: 分享:STM32CubeMX基本定时器