您现在的位置: 主页 > 嵌入式开发入门到精通 > 单片机技术进阶 > 基于STM32F051库函数版本的SPI初始化 -
本文所属标签:
为本文创立个标签吧:

基于STM32F051库函数版本的SPI初始化 -

来源: 网络用户发布,如有版权联系网管删除 2018-09-07 

[导读]void SPI_Init(void){ GPIO_InitTypeDef GPIO_InitStruct; SPI_InitTypeDef SPI_InitStruct; /*!< SPI_CS_GPIO, SPI_MOSI_GPIO, SPI_MISO_GPIO, SPI_SCK_GPIO Init */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF|

void SPI_Init(void)

本文引用地址: http://www.21ic.com/app/mcu/201808/779100.htm

{

GPIO_InitTypeDef GPIO_InitStruct;

SPI_InitTypeDef SPI_InitStruct;

/*!< SPI_CS_GPIO, SPI_MOSI_GPIO, SPI_MISO_GPIO, SPI_SCK_GPIO Init */

RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOF| RCC_AHBPeriph_GPIOB, ENABLE);

RCC_APB1PeriphClockCmd(FLASH_SPI2, ENABLE);

/*!< Configure SPI pins: SCK */

GPIO_InitStruct.GPIO_Pin = SCK_PIN;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_Init(SCK_PORT, &GPIO_InitStruct);

/*!< Configure SPI pins: MISO */

GPIO_InitStruct.GPIO_Pin = MISO_PIN;

GPIO_Init(MISO_PORT, &GPIO_InitStruct);

/*!< Configure SPI pins: MOSI */

GPIO_InitStruct.GPIO_Pin =MOSI_PIN;

GPIO_Init(MOSI_PORT, &GPIO_InitStruct);

/* Connect PXx to SPI_SCK */

GPIO_PinAFConfig( SCK_PORT, SCK_PIN, GPIO_AF_0);

/* Connect PXx to SPI_MISO */

GPIO_PinAFConfig( MISO_PORT, MISO_PIN, GPIO_AF_0);

/* Connect PXx to SPI_MOSI */

GPIO_PinAFConfig( MOSI_PORT, MOSI_PIN, GPIO_AF_0);

/*!< Configure SPI_CS_PIN pin: */

GPIO_InitStruct.GPIO_Pin = SPI_CS_PIN;

GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT;

GPIO_InitStruct.GPIO_OType = GPIO_OType_PP;

GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP;

GPIO_InitStruct.GPIO_Speed = GPIO_Speed_Level_3;

GPIO_Init( SPI_CS _PORT, &GPIO_InitStruct);

SPI_FLASH_CS_HIGH();

/*!< SD_SPI Config */

SPI_InitStruct.SPI_Direction = SPI_Direction_2Lines_FullDuplex;

SPI_InitStruct.SPI_Mode = SPI_Mode_Master;

SPI_InitStruct.SPI_DataSize = SPI_DataSize_8b;

SPI_InitStruct.SPI_CPOL = SPI_CPOL_High;

SPI_InitStruct.SPI_CPHA = SPI_CPHA_2Edge;

SPI_InitStruct.SPI_NSS = SPI_NSS_Soft; //软件设定NSS位

SPI_InitStruct.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;

SPI_InitStruct.SPI_FirstBit = SPI_FirstBit_MSB;

SPI_InitStruct.SPI_CRCPolynomial = 7;

SPI_Init(SPI2, &SPI_InitStruct);

SPI_RxFIFOThresholdConfig(SPI2, SPI_RxFIFOThreshold_QF);

SPI_Cmd(SPI2, ENABLE); /*!< SD_SPI enable */




              查看评论 回复



嵌入式交流网主页 > 嵌入式开发入门到精通 > 单片机技术进阶 > 基于STM32F051库函数版本的SPI初始化 -
 

"基于STM32F051库函数版本的SPI初始化 -"的相关文章

网站地图

围观()