用的mini板和库函数做的闪灯实验,刚上电时,会出现在几下LED的闪烁周期不对的情况。过了一会儿就正常了,并且一直都没有出现问题。用的库函数(3、5版本)代码如下:
int main(void)
{
STM32_CLK_Init(); //IO clock enable
Port_Init(); //IO mode initialize
while(1)
{
u32 i;
GPIO_ResetBits(GPIOA,GPIO_Pin_8); //I/O port reverse
GPIO_SetBits(GPIOD,GPIO_Pin_2);
for(i=1000000;i>0;i--); //delay
GPIO_SetBits(GPIOA,GPIO_Pin_8); //I/O port reverse
GPIO_ResetBits(GPIOD,GPIO_Pin_2);
for(i=1000000;i>0;i--); //delay
}
}
//--------------------------时钟初始化------------------------------------------------------------------
void STM32_CLK_Init(void)
{
RCC_DeInit();
RCC_HSEConfig(RCC_HSE_OFF); //disable HSE
RCC_HSICmd(ENABLE); //enable HSI
RCC_PLLConfig(RCC_PLLSource_HSI_Div2,RCC_PLLMul_9); //
RCC_PLLCmd(ENABLE); //enable PLL
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); //hsi as system clock
if(RCC_GetSYSCLKSource()!=0x00)
{
RCC_SYSCLKConfig(RCC_SYSCLKSource_HSI); //hsi as system clock
}
RCC_HCLKConfig(RCC_SYSCLK_Div1); //AHB clock
RCC_PCLK1Config(RCC_HCLK_Div2); //APB1 clock is HCLK/2
RCC_PCLK2Config(RCC_HCLK_Div1); //APB2 clock is HCLK
RCC_ITConfig(RCC_IT_LSIRDY|RCC_IT_LSERDY|RCC_IT_HSIRDY|RCC_IT_HSERDY|RCC_IT_PLLRDY,DISABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOD,ENABLE);
}
//----------------------------------------IO口初始化-------------------------------------------------------
void Port_Init(void)
{
GPIO_InitTypeDef GPIOA_InitStruct;
GPIO_InitTypeDef GPIOD_InitStruct;
GPIOA_InitStruct.GPIO_Pin=GPIO_Pin_8;
GPIOA_InitStruct.GPIO_Speed=GPIO_Speed_2MHz;
GPIOA_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOA,&GPIOA_InitStruct); //initialize PA8
GPIOD_InitStruct.GPIO_Pin=GPIO_Pin_2;
GPIOD_InitStruct.GPIO_Speed=GPIO_Speed_2MHz;
GPIOD_InitStruct.GPIO_Mode=GPIO_Mode_Out_PP;
GPIO_Init(GPIOD,&GPIOD_InitStruct); //initialize PD2
}
|