高中生
最后登录1970-1-1
在线时间 小时
注册时间2017-8-22
|
楼主 |
发表于 2017-11-14 10:40:10
|
显示全部楼层
void COMM_SPI_Init(void)
{ spi_clear();
SPI_InitTypeDef SPI_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
/* ê1Äü SPI ¼°GPIO ê±Öó */
/*!< SPI_CS_GPIO, SPI_MOSI_GPIO,
SPI_MISO_GPIO,SPI_SCK_GPIO ê±Öóê1Äü */
RCC_AHB1PeriphClockCmd (COMM_SPI_SCK_GPIO_CLK | COMM_SPI_MISO_GPIO_CLK|COMM_SPI_MOSI_GPIO_CLK, ENABLE);
/*!< SPI ê±Öóê1Äü */
COMM_SPI_CLK_INIT(COMM_SPI_CLK, ENABLE);
//éèÖÃòy½Å¸′óÃ
GPIO_PinAFConfig(COMM_SPI_SCK_GPIO_PORT,COMM_SPI_SCK_PINSOURCE,COMM_SPI_SCK_AF);
GPIO_PinAFConfig(COMM_SPI_MISO_GPIO_PORT,COMM_SPI_MISO_PINSOURCE,COMM_SPI_MISO_AF);
GPIO_PinAFConfig(COMM_SPI_MOSI_GPIO_PORT,COMM_SPI_MOSI_PINSOURCE,COMM_SPI_MOSI_AF);
/*!< ÅäÖà SPI òy½Å: SCK */
GPIO_InitStructure.GPIO_Pin = COMM_SPI_SCK_PIN;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(COMM_SPI_SCK_GPIO_PORT, &GPIO_InitStructure);
/*!< ÅäÖà SPI òy½Å: MISO */
GPIO_InitStructure.GPIO_Pin = COMM_SPI_MISO_PIN;
GPIO_Init(COMM_SPI_MISO_GPIO_PORT, &GPIO_InitStructure);
/*!< ÅäÖà SPI_FLASH_SPI òy½Å: MOSI */
GPIO_InitStructure.GPIO_Pin = COMM_SPI_MOSI_PIN;
GPIO_Init(COMM_SPI_MOSI_GPIO_PORT, &GPIO_InitStructure);
/* SPI Ä£ê½ÅäÖà */
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_64;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(COMM_SPI, &SPI_InitStructure);
/* ê1Äü FLASH_SPI */
SPI_Cmd(COMM_SPI, ENABLE);
}
从机的 |
|