我的开发板是8兆晶振
时钟配置如下:
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus; //Íⲿ¸ßËÙʱÖÓ(HSE)µÄ¹¤×÷״̬±äÁ¿
RCC_DeInit(); //½«ËùÓÐÓëʱÖÓÏà¹ØµÄ¼Ä´æÆ÷ÉèÖÃΪĬÈÏÖµ
RCC_HSEConfig(RCC_HSE_ON); //Æô¶¯Íⲿ¸ßËÙʱÖÓHSE
HSEStartUpStatus = RCC_WaitForHSEStartUp(); //µÈ´ýÍⲿ¸ßËÙʱÖÓ(HSE)Îȶ¨
if(SUCCESS == HSEStartUpStatus) //Èç¹ûÍⲿ¸ßËÙʱÖÓÒѾÎȶ¨
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //FlashÉèÖÃ
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1); //ÉèÖÃAHBʱÖÓµÈÓÚϵͳʱÖÓ(1·ÖƵ)/72MHZ
RCC_PCLK2Config(RCC_HCLK_Div1); //ÉèÖÃAPB2ʱÖÓºÍHCLKʱÖÓÏàµÈ/72MHz(×î´óΪ72MHz)
RCC_PCLK1Config(RCC_HCLK_Div2); //ÉèÖÃAPB1ʱÖÓÊÇHCLKʱÖÓµÄ2·ÖƵ/36MHz(×î´óΪ36MHz)
#ifndef STM32F10X_CL //Èç¹ûʹÓõIJ»ÊÇSTM32F107x»òSTM32F105xϵÁÐMCU,PLLÒÔÏÂÅäÖÃ
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //PLLCLK = 8MHz * 9 = 72 MHz
#else //Èç¹ûʹÓõÄÊÇSTM32F107x»òSTM32F105xϵÁÐMCU,PLLÒÔÏÂÅäÖÃ
/***** ÅäÖÃPLLx *****/
/* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
RCC_PREDIV2Config(RCC_PREDIV2_Div5);
RCC_PLL2Config(RCC_PLL2Mul_8);
RCC_PLL2Cmd(ENABLE); //ʹÄÜPLL2
while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET);//µÈ´ýPLL2Îȶ¨
/* PLL configuration: PLLCLK = (PLL2 / 5) * 9 = 72 MHz */
RCC_PREDIV1Config(RCC_PREDIV1_Source_PLL2, RCC_PREDIV1_Div5);
RCC_PLLConfig(RCC_PLLSource_PREDIV1, RCC_PLLMul_9);
#endif
RCC_PLLCmd(ENABLE); //ʹÄÜPLL
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //µÈ´ýPLLÎȶ¨
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //ÉèÖÃϵͳʱÖÓµÄʱÖÓԴΪPLL
while(RCC_GetSYSCLKSource() != 0x08); //¼ì²éϵͳµÄʱÖÓÔ´ÊÇ·ñÊÇPLL
RCC_ClockSecuritySystemCmd(ENABLE); //ʹÄÜϵͳ°²È«Ê±ÖÓ
/* Enable peripheral clocks --------------------------------------------------*/
/* Enable I2C1 and I2C1 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
/* Enable GPIOA GPIOB SPI1 and USART1 clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB
| RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD
| RCC_APB2Periph_AFIO, ENABLE);
}
}
这是不是表示72兆啊?
SPI初始化:
/* ³õʼ»¯ÅäÖÃSTM32 SPI1 */
SPI_InitStructure.SPI_Direction=SPI_Direction_2Lines_FullDuplex; //SPIÉèÖÃΪ˫ÏßË«ÏòÈ«Ë«¹¤
SPI_InitStructure.SPI_Mode=SPI_Mode_Master; //ÉèÖÃΪÖ÷SPI
SPI_InitStructure.SPI_DataSize=SPI_DataSize_8b; //SPI·¢ËͽÓÊÕ8λ֡½á¹¹
SPI_InitStructure.SPI_CPOL=SPI_CPOL_Low; //ʱÖÓÐü¿ÕµÍ
SPI_InitStructure.SPI_CPHA=SPI_CPHA_1Edge; //Êý¾Ý²¶»ñÓÚµÚ1¸öʱÖÓÑØ
SPI_InitStructure.SPI_NSS=SPI_NSS_Soft; //NSSÓÉÍⲿ¹Ü½Å¹ÜÀí
SPI_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_2; //²¨ÌØÂÊÔ¤·ÖƵֵΪ2
SPI_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB; //Êý¾Ý´«Êä´ÓMSBλ¿ªÊ¼
SPI_InitStructure.SPI_CRCPolynomial=7; //CRC¶àÏîʽΪ7
SPI_Init(SPI1,&SPI_InitStructure); //¸ù¾ÝSPI_InitStructÖÐÖ¸¶¨µÄ²ÎÊý³õʼ»¯ÍâÉèSPI1¼Ä´æÆ÷
SPI_Cmd(SPI1,ENABLE); //STM32ʹÄÜSPI1
波特率预分频值为2,是不是表示SPI工作在36MHz啊?谢谢
|