大家帮忙看看下面的问题,谢谢了!
void RCC_Config(void)
{
/* SYSCLK, HCLK, PCLK2 and PCLK1 configuration -----------------------------*/
/* RCC system reset(for debug purpose) */
RCC_DeInit();
/* Enable HSE */
RCC_HSEConfig(RCC_HSE_ON);
/* Wait till HSE is ready */
// HSEStartUpStatus = RCC_WaitForHSEStartUp();
if (RCC_WaitForHSEStartUp() == SUCCESS)
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable);
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
/* HCLK = SYSCLK */
RCC_HCLKConfig(RCC_SYSCLK_Div1);
/* PCLK2 = HCLK */
RCC_PCLK2Config(RCC_HCLK_Div1);
/* PCLK1 = HCLK/2 */
RCC_PCLK1Config(RCC_HCLK_Div2); // 已经设置2分频,应该是72/2=36MHz
/* PLLCLK = 8MHz * 9 = 72 MHz */
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9);
/* Enable PLL */
RCC_PLLCmd(ENABLE);
/* Wait till PLL is ready */
while (RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET)
{
}
/* Select PLL as system clock source */
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK);
/* Wait till PLL is used as system clock source */
while(RCC_GetSYSCLKSource() != 0x08)
{
}
}
}
已经设置好APB1总线频率是36MHz,下面使用APB1总线挂外的TIM3产生以秒为单位的中断,程序如下:
/*******************************************************************************
* Function Name : TIM3_LIGHTSOURCE_DELAY_Config
* Description : 通过TIM3中断以秒为单位,产生光源TIMEOUT。
* Input : lightsource_timeout
* Output : None
* Return : None
*******************************************************************************/
void TIM3_LIGHTSOURCE_DELAY_Config(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3, ENABLE); //使能TIM3总线
TIM_Cmd(TIM3, DISABLE); //关闭TIM3
TIM_DeInit(TIM3); //复位TIM3
TIM_TimeBaseStructure.TIM_ClockDivision = 0; // 定时器基准频率36M
TIM_TimeBaseStructure.TIM_Prescaler = 36000-1; //分频系数,1khz
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; // 向上计数
TIM_TimeBaseStructure.TIM_Period = 1000-1; //自动重载值 ARR 1HZ
TIM_TimeBaseInit(TIM3, &TIM_TimeBaseStructure); //初始化定时器
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //使用中断优先组1
/* Enable the TIM3 gloabal Interrupt */
NVIC_InitStructure.NVIC_IRQChannel = TIM3_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 4;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
问题是,实际的中断是0.5秒一次,反推回去,就是APH1的时钟还是72MHz,但是STM32F103手册里面明确写着,APB1操作速度限于36MHz,APB2操作于全速(最高72MHz)。谁帮我看看啊!
补充内容:
补充一下啊! /* PCLK1 = HCLK/1 */ RCC_PCLK1Config(RCC_HCLK_Div1); /* PCLK1 = HCLK/2 */ RCC_PCLK1Config(RCC_HCLK_Div2); 以上两条中断时间一样,都是0.5秒。 /* PCLK1 = HCLK/4 */ RCC_PCLK1Config(RCC_HCLK_Div4); 中断是1秒/次。 哪里不对呢? |