#define W25X_SPI_XXX SPI1
#define W25X_SPI_GPIO GPIOB
#define W25X_SPI_SCK_CLK RCC_APB2Periph_SPI1
#define W25X_SPI_CS_Pin GPIO_Pin_15//GPIOA
#define W25X_SPI_CLK_Pin GPIO_Pin_3//GPIOB
#define W25X_SPI_MISO_Pin GPIO_Pin_4//GPIOB
#define W25X_SPI_MOSI_Pin GPIO_Pin_5//GPIOB
GPIO_InitTypeDef GPIO_InitStruct;
SPI_InitTypeDef SPI_InitStructure;
RCC_APB2PeriphClockCmd(W25X_SPI_SCK_CLK | RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO,ENABLE);
GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable , ENABLE);//释放JTAG引脚
GPIO_PinRemapConfig(GPIO_Remap_SPI1 , ENABLE);//释放JTAG引脚
GPIO_InitStruct.GPIO_Pin = W25X_SPI_CLK_Pin | W25X_SPI_MOSI_Pin;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(W25X_SPI_GPIO,&GPIO_InitStruct);
GPIO_InitStruct.GPIO_Pin = W25X_SPI_MISO_Pin;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_Init(W25X_SPI_GPIO,&GPIO_InitStruct);
// RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_AFIO,ENABLE);
GPIO_InitStruct.GPIO_Pin = W25X_SPI_CS_Pin;
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOA,&GPIO_InitStruct);
W25X_SPI_CS_High; //片选置高电平
//打开SP1时钟
// RCC_APB2PeriphClockCmd(W25X_SPI_SCK_CLK,ENABLE);
//关闭SPI1
SPI_Cmd(W25X_SPI_XXX, DISABLE);
//设置SPI2
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //全双工收发
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //设为主机
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //8位帧结构
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High; //空闲时时钟为低
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge; //第1个时钟沿捕获数据
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //CS由SSI位控制(自控)
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4; //波特率为4分频
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //高位先传送
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC校验多项式为7
SPI_Init(W25X_SPI_XXX,&SPI_InitStructure); //初始化SPI1
//启动SPI2
SPI_Cmd(W25X_SPI_XXX,ENABLE);