新手上路
- 积分
- 45
- 金钱
- 45
- 注册时间
- 2015-3-19
- 在线时间
- 0 小时
|
5金钱
void SPIx_Init(void)<br />
{<br />
<br />
GPIO_InitTypeDef GPIO_InitStructure;<br />
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA|RCC_APB2Periph_SPI1, ENABLE ); <br />
<br />
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;<br />
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; //???????ì????<br />
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br />
GPIO_Init(GPIOA, &GPIO_InitStructure);<br />
<br />
GPIO_SetBits(GPIOA,GPIO_Pin_5|GPIO_Pin_6|GPIO_Pin_7);<br />
<br />
SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex; //?è??SPI???ò?ò?????ò??????????:SPI?è???????????ò?????¤<br />
SPI_InitStructure.SPI_Mode = SPI_Mode_Master; //?è??SPI?¤×÷????:?è?????÷SPI<br />
SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b; //?è??SPI???????ó??:SPI·???????8?????á??<br />
SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low; //???????®???±????????:?±???ü????????<br />
SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge; //?????????????????±????<br />
SPI_InitStructure.SPI_NSS = SPI_NSS_Soft; //NSS???????????¨NSS?????©?????í???¨????SSI???©???í:????NSS??????SSI??????<br />
SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_256; //?¨???¨?????¤·???????:?¨?????¤·???????256<br />
SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB; //???¨??????????MSB??????LSB??????:??????????MSB??????<br />
SPI_InitStructure.SPI_CRCPolynomial = 7; //CRC?????????à????<br />
SPI_Init(SPI1, &SPI_InitStructure); //?ù??SPI_InitStruct?????¨???????????????èSPIx?????÷<br />
<br />
SPI_Cmd(SPI1, ENABLE); //????SPI???è<br />
<br />
SPIx_ReadWriteByte(0xff);//???????? <br />
} <br />
<br />
void NRF24L01_Init(void)<br />
{<br />
GPIO_InitTypeDef GPIO_InitStructure;<br />
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA|RCC_APB2Periph_GPIOB, ENABLE ); <br />
<br />
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4; //PA4-->NRF2401_CSN<br />
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì????<br />
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br />
GPIO_Init(GPIOA, &GPIO_InitStructure);<br />
GPIO_SetBits(GPIOA,GPIO_Pin_4);<br />
<br />
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0; //PB0-->NRF2401_CE<br />
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //???ì????<br />
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;<br />
GPIO_Init(GPIOB, &GPIO_InitStructure);<br />
GPIO_SetBits(GPIOB,GPIO_Pin_0);<br />
<br />
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_1; //PB1-->NRF2401_IRQ<br />
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU; //????????<br />
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; <br />
GPIO_Init(GPIOB, &GPIO_InitStructure);<br />
GPIO_SetBits(GPIOB,GPIO_Pin_1);<br />
<br />
SPIx_Init(); //??????SPI<br />
<br />
Clr_NRF24L01_CE; //NRF24L01???????ú???? NRF24L01_CE<br />
Set_NRF24L01_CSN; //SPI???? NRF24L01_CSN <br />
}<br />
<br />
贴上两个初始化的函数,不知道问题在哪,还请指教 |
|