/* SPI1 Config -------------------------------------------------------------/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master,//这里设置SPI1为主模式,设置SSI为1
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure. SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//这里设置SSM为1,软件管理
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/* SPI2 Config -------------------------------------------------------------*/
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;//这里设置SPI2为从模式SSI为0 //因为SPI2和SPI1用的是同一个SPI_InitStructure,所以SSM位已经为1
SPI_Init(SPI2, &SPI_InitStructure);
/* SPI1 Config -------------------------------------------------------------/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master,//这里设置SPI1为主模式,设置SSI为1
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure. SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//这里设置SSM为1,软件管理
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/* SPI2 Config -------------------------------------------------------------*/
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;//这里设置SPI2为从模式SSI为0 //因为SPI2和SPI1用的是同一个SPI_InitStructure,所以SSM位已经为1
SPI_Init(SPI2, &SPI_InitStructure);
/* SPI1 Config -------------------------------------------------------------/
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
SPI_InitStructure.SPI_Mode = SPI_Mode_Master,//这里设置SPI1为主模式,设置SSI为1
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
SPI_InitStructure. SPI_CPOL = SPI_CPOL_Low;
SPI_InitStructure.SPI_CPHA = SPI_CPHA_2Edge;
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;//这里设置SSM为1,软件管理
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_4;
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_LSB;
SPI_InitStructure.SPI_CRCPolynomial = 7;
SPI_Init(SPI1, &SPI_InitStructure);
/* SPI2 Config -------------------------------------------------------------*/
SPI_InitStructure.SPI_Mode = SPI_Mode_Slave;//这里设置SPI2为从模式SSI为0 //因为SPI2和SPI1用的是同一个SPI_InitStructure,所以SSM位已经为1
SPI_Init(SPI2, &SPI_InitStructure);
对于SPI2的配置,和SPI1用的是同一个结构体,只需要把模式和SSI一改就行,其他的譬如软件使能,还有时序什么的都不用改。这样SPI1和SPI2就配置好了。以后就可以传输数据了。
|