以下驱动是SPI2的应用
static void MMC_SPI_Config(void)
{
SPI_DeInit();
GPIO_Init(GPIOC, GPIO_PIN_2, GPIO_MODE_OUT_PP_HIGH_FAST);
GPIO_Init(GPIOC, GPIO_PIN_4, GPIO_MODE_IN_FL_NO_IT);
GPIO_Init(GPIOE, GPIO_PIN_5, GPIO_MODE_OUT_PP_HIGH_FAST);
SPI_Init(SPI_FIRSTBIT_MSB, SPI_BAUDRATEPRESCALER_256, SPI_MODE_MASTER
, SPI_CLOCKPOLARITY_HIGH, SPI_CLOCKPHASE_2EDGE,
SPI_DATADIRECTION_2LINES_FULLDUPLEX, SPI_NSS_SOFT,0x00);
SPI_Cmd(ENABLE);
}
static
UCHAR SPI_ReadWrite_Byte(unsigned char byte)
{
/* Loop while DR register in not emplty */
while(SPI_GetFlagStatus(SPI_FLAG_TXE) == RESET);
/* Send byte through the SPI1 peripheral */
SPI_SendData(byte);
/* Wait to receive a byte */
while(SPI_GetFlagStatus(SPI_FLAG_RXNE) == RESET);
/* Return the byte read from the SPI bus */
return SPI_ReceiveData();
}
『本文转载自网络,版权归原作者所有,如有侵权请联系删除』