SPI我用到的是硬件的用了3个口13,14,15
初始化函数
void SPI1_Init(void)
{
GPIO_InitTypeDef SPI_GPIO;
SPI_InitTypeDef SPI_Init_Q;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB,ENABLE);
SPI_GPIO.GPIO_Mode = GPIO_Mode_AF_PP;//复用推挽
SPI_GPIO.GPIO_Pin = GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15;
SPI_GPIO.GPIO_Speed = GPIO_Speed_50MHz;
SPI_Init_Q.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //传输的波特率为256
SPI_Init_Q.SPI_CPHA = SPI_CPHA_2Edge;//在第二个周期有效
SPI_Init_Q.SPI_CPOL = SPI_CPOL_High;//悬空状态为高电平
SPI_Init_Q.SPI_CRCPolynomial = 7;
SPI_Init_Q.SPI_DataSize = SPI_DataSize_8b;//传输数据大小为8位
SPI_Init_Q.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//全双工
SPI_Init_Q.SPI_Mode = SPI_Mode_Master;//主模式
SPI_Init_Q.SPI_FirstBit = SPI_FirstBit_MSB;//第一个由高点起始
SPI_Init_Q.SPI_NSS = SPI_NSS_Soft;//软件控制
SPI_Init(SPI2,&SPI_Init_Q);
GPIO_Init(GPIOB,&SPI_GPIO);
GPIO_SetBits(GPIOB,GPIO_Pin_13 | GPIO_Pin_14 | GPIO_Pin_15);
}