问下STM32F103 硬件SPI1 用外部晶振HSE可以正常工作,系统时钟用内部晶振HSI不工作,什么原因
void SPI1_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);//ʹÄÜSPI1ÍâÉèʱÖÓ
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE);//ʹÄÜGPIOA
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5|GPIO_Pin_7;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;//ËÙ¶È50MHz
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //¸´ÓÃÍÆÍìÊä³ö
GPIO_Init(GPIOA, &GPIO_InitStructure); //³õʼ»¯GPIOA
GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_7);
SPI_InitStructure.SPI_Direction = SPI_Direction_1Line_Tx;//Ö»·¢ËÍģʽ
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;//ÉèÖÃSPI¹¤×÷ģʽ£ºÖ÷»úģʽ
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;//ÉèÖÃSPIÊý¾Ý´óС£º8λ֡½á¹¹
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//´®ÐÐͬ²½Ê±ÖÓ¿ÕÏÐʱSCLKλ¸ßµçƽ
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//´®ÐÐͬ²½Ê±ÖÓ¿ÕµÚ¶þ¸öʱÖÓÑز¶»ñ
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//NSSÐźÅÓÉÓ²¼þ¹ÜÀí
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//²¨ÌØÂÊÔ¤·ÖƵֵ£º²¨ÌØÂÊÔ¤·ÖƵֵΪ4
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//Êý¾Ý´«Êä¸ßλÏÈÐÐ
SPI_InitStructure.SPI_CRCPolynomial = 7;//CRCÖµ¼ÆËãµÄ¶àÏîʽ
SPI_Init(SPI1,&SPI_InitStructure);//³õʼ»¯SPI
SPI_Cmd(SPI1, ENABLE);//ʹÄÜSPI
}
|