我的开发板是8兆晶振
时钟配置如下:
void RCC_Configuration(void)
{
ErrorStatus HSEStartUpStatus; //ía2¿¸ßËùê±Öó(HSE)μÄ1¤×÷×′쬱äá¿
RCC_DeInit(); //½«ËùóDóëê±ÖóÏà1ØμļÄ′æÆ÷éèÖÃÎaĬèÏÖμ
RCC_HSEConfig(RCC_HSE_ON); //Æô¶ˉía2¿¸ßËùê±ÖóHSE
HSEStartUpStatus = RCC_WaitForHSEStartUp(); //μè′yía2¿¸ßËùê±Öó(HSE)Î趨
if(SUCCESS == HSEStartUpStatus) //èç1ûía2¿¸ßËùê±ÖóòѾ-Î趨
{
/* Enable Prefetch Buffer */
FLASH_PrefetchBufferCmd(FLASH_PrefetchBuffer_Enable); //FlashéèÖÃ
/* Flash 2 wait state */
FLASH_SetLatency(FLASH_Latency_2);
RCC_HCLKConfig(RCC_SYSCLK_Div1); //éèÖÃAHBê±ÖóμèóúÏμí3ê±Öó(1·ÖÆμ)/72MHZ
RCC_PCLK2Config(RCC_HCLK_Div1); //éèÖÃAPB2ê±ÖóoíHCLKê±ÖóÏàμè/72MHz(×î′óÎa72MHz)
RCC_PCLK1Config(RCC_HCLK_Div2); //éèÖÃAPB1ê±ÖóêÇHCLKê±ÖóμÄ2·ÖÆμ/36MHz(×î′óÎa36MHz)
#ifndef STM32F10X_CL //èç1ûê1óÃμÄ2»êÇSTM32F107x»òSTM32F105xÏμáDMCU,PLLòÔÏÂÅäÖÃ
RCC_PLLConfig(RCC_PLLSource_HSE_Div1, RCC_PLLMul_9); //PLLCLK = 8MHz * 9 = 72 MHz
#else //èç1ûê1óÃμÄêÇSTM32F107x»òSTM32F105xÏμáDMCU,PLLòÔÏÂÅäÖÃ
/***** ÅäÖÃPLLx *****/
/* PLL2 configuration: PLL2CLK = (HSE / 5) * 8 = 40 MHz */
RCC_PREDIV2Config(RCC_PREDIV2_Div5);
RCC_PLL2Config(RCC_PLL2Mul_8);
RCC_PLL2Cmd(ENABLE); //ê1ÄüPLL2
while (RCC_GetFlagStatus(RCC_FLAG_PLL2RDY) == RESET);//μè′yPLL2Î趨
/* 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); //ê1ÄüPLL
while(RCC_GetFlagStatus(RCC_FLAG_PLLRDY) == RESET); //μè′yPLLÎ趨
RCC_SYSCLKConfig(RCC_SYSCLKSource_PLLCLK); //éèÖÃÏμí3ê±ÖóμÄê±ÖóÔ′ÎaPLL
while(RCC_GetSYSCLKSource() != 0x08); //¼ì2éÏμí3μÄê±ÖóÔ′êÇ·ñêÇPLL
RCC_ClockSecuritySystemCmd(ENABLE); //ê1ÄüÏμí3°2è«ê±Öó
/* 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初始化:
/* 3õê¼»ˉÅäÖÃSTM32 SPI1 */
SPI_InitStructure.SPI_Direction=SPI_Direction_2Lines_FullDuplex; //SPIéèÖÃÎaË«ÏßË«Ïòè«Ë«1¤
SPI_InitStructure.SPI_Mode=SPI_Mode_Master; //éèÖÃÎaÖ÷SPI
SPI_InitStructure.SPI_DataSize=SPI_DataSize_8b; //SPI·¢Ëí½óêÕ8λ֡½á11
SPI_InitStructure.SPI_CPOL=SPI_CPOL_Low; //ê±ÖóDü¿Õμí
SPI_InitStructure.SPI_CPHA=SPI_CPHA_1Edge; //êy¾Y2¶»ñóúμú1¸öê±ÖóÑØ
SPI_InitStructure.SPI_NSS=SPI_NSS_Soft; //NSSóéía2¿1ü½Å1üàí
SPI_InitStructure.SPI_BaudRatePrescaler=SPI_BaudRatePrescaler_2; //2¨ìØÂêÔ¤·ÖÆμÖμÎa2
SPI_InitStructure.SPI_FirstBit=SPI_FirstBit_MSB; //êy¾Y′«êä′óMSBλ¿aê¼
SPI_InitStructure.SPI_CRCPolynomial=7; //CRC¶àÏîê½Îa7
SPI_Init(SPI1,&SPI_InitStructure); //¸ù¾YSPI_InitStructÖDÖ¸¶¨μÄ2Îêy3õê¼»ˉíaéèSPI1¼Ä′æÆ÷
SPI_Cmd(SPI1,ENABLE); //STM32ê1ÄüSPI1
波特率预分频值为2,是不是表示SPI工作在36MHz啊?谢谢
|