首先我贴出配置SPI的代码
void SPI1_Config(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
SPI_InitTypeDef SPI_InitStructure;
/* Enable the SPI periph */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SPI1, ENABLE);
/* Enable SCK, MOSI, MISO and NSS GPIO clocks */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
GPIO_PinAFConfig(ADE7953_SCLK_GROUP, ADE7953_SCLK_PIN, GPIO_AF_0);
GPIO_PinAFConfig(ADE7953_MOSI_GROUP, ADE7953_MOSI_PIN, GPIO_AF_0);
GPIO_PinAFConfig(ADE7953_MISO_GROUP, ADE7953_MISO_PIN, GPIO_AF_0);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
/* SPI SCK pin configuration */
GPIO_InitStructure.GPIO_Pin = ADE7953_SCLK_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(ADE7953_SCLK_GROUP, &GPIO_InitStructure);
/* SPI MOSI pin configuration */
GPIO_InitStructure.GPIO_Pin = ADE7953_MOSI_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(ADE7953_MOSI_GROUP, &GPIO_InitStructure);
/* SPI MISO pin configuration */
GPIO_InitStructure.GPIO_Pin = ADE7953_MISO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_Level_3;
//GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(ADE7953_MISO_GROUP, &GPIO_InitStructure);
/* Deinitializes the SPIx peripheral registers to their default reset values*/
SPI_I2S_DeInit(SPI1);
/* SPI configuration -------------------------------------------------------*/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;//8λÊý¾Ý
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //ʱÖÓ³£¸ß
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;// µÚ¶þ¸öʱÖÓÑØ£¨Ê±ÖÓ³£¸ßʱµÄÉÏÉýÑØ£©²¶»ñÊý¾Ý
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //Èí¼þƬѡ
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;// 48/16=3M µÄSPI
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1,&SPI_InitStructure);
SPI_RxFIFOThresholdConfig(SPI1, SPI_RxFIFOThreshold_QF);//
SPI_Cmd(SPI1, ENABLE); /*!< SD_SPI enable */
}
|