void SPI2_Init(void)
{
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_SPI2,ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_13 |GPIO_Pin_14| GPIO_Pin_15;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
/* Deselect the FLASH: Chip Select high */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;//对SPI1_CR1中BIDIMODE置0
SPI_InitStructure.SPI_Mode = SPI_Mode_Master;//对SPI1_CR1中SSI和MSTR得值1
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;//对SPI1_CR1中DFF位清零
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;//
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;//
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//对SPI1_CR1中ssm的位置1
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;//SPI_BaudRatePrescaler_4; 18MHz
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;//对SPI1_CR1中LSBFIRST位清零
SPI_InitStructure.SPI_CRCPolynomial = 7;//对SPI1_CRCPR中值设为7
SPI_Init(SPI2, &SPI_InitStructure);
SPI_Cmd(SPI2, ENABLE);
}
高手看看有哪设的不对的地方吗 |