新手入门
- 积分
- 27
- 金钱
- 27
- 注册时间
- 2013-5-28
- 在线时间
- 0 小时
|
楼主 |
发表于 2013-5-29 10:31:03
|
显示全部楼层
void SPIx_Init(void)
<br>{
<br>
<br> SPI_InitTypeDef SPI_InitStructure;
<br>
<br> RCC->APB2ENR|=1<<2; //PORTA时钟使能
<br> RCC->APB2ENR|=1<<12; //SPI1时钟使能
<br>
<br> //这里只针对SPI口初始化
<br> GPIOA->CRL&=0X000FFFFF;
<br> GPIOA->CRL|=0XBBB00000;//PA5.6.7复用
<br> GPIOA->ODR|=0X7<<5; //PA5.6.7上拉
<br>
<br> SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
<br> SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
<br> SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
<br> SPI_InitStructure.SPI_CPOL = SPI_CPOL_High;
<br> SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
<br> SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
<br> SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256;
<br> SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
<br> SPI_InitStructure.SPI_CRCPolynomial = 7;
<br> SPI_Init(SPI1, &SPI_InitStructure);
<br> SPIx_ReadWriteByte(0xff);//启动传输
<br>} |
|