STM32CubeMX创建一个使用8MhzHSE,倍频到72Mhz,在Keil上仿真debug定时器中断时间正常,烧录就中断时间就变为仿真的72倍了。
是我设置问题吗?
STM32F103C8T6
- static void MX_TIM1_Init(void)
- {
- /* USER CODE BEGIN TIM1_Init 0 */
- /* USER CODE END TIM1_Init 0 */
- TIM_ClockConfigTypeDef sClockSourceConfig = {0};
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- /* USER CODE BEGIN TIM1_Init 1 */
- /* USER CODE END TIM1_Init 1 */
- htim1.Instance = TIM1;
- htim1.Init.Prescaler = 5000;
- htim1.Init.CounterMode = TIM_COUNTERMODE_DOWN;
- htim1.Init.Period = 7200;
- htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim1.Init.RepetitionCounter = 0;
- htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_ENABLE;
- if (HAL_TIM_Base_Init(&htim1) != HAL_OK)
- {
- Error_Handler();
- }
- sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
- if (HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim1, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN TIM1_Init 2 */
- HAL_TIM_Base_Start_IT(&htim1);
- /* USER CODE END TIM1_Init 2 */
-
- }
复制代码- void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim)
- {
- if(htim->Instance==htim1.Instance)
- {
- HAL_GPIO_WritePin(GPIOC, GPIO_PIN_13, !(HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_13)));
- }
- }
复制代码
|
评分
查看全部评分
评分
查看全部评分
从来没遇到过楼主的问题。
根据你的程序看,生成的是0.5S的周期,难道下载到MCU跑起来后不是0.5S吗?
评分
查看全部评分