| 
 
初级会员 
 
	积分136金钱136 注册时间2016-10-26在线时间40 小时 | 
 
 
 楼主|
发表于 2016-11-7 17:22:20
|
显示全部楼层 
| void NRF24L01_Init(void)
 {
 GPIO_InitTypeDef GPIO_InitStructure;
 SPI_InitTypeDef  SPI_InitStructure;
 
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_GPIOD, ENABLE);         //使能PB,G端口时钟
 
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12;                                 //PB12上拉 防止W25X的干扰
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //推挽输出
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOB, &GPIO_InitStructure);        //初始化指定IO
 GPIO_SetBits(GPIOB,GPIO_Pin_12);//上拉
 
 
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8;        //PG8 7 推挽
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;                  //推挽输出
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_Init(GPIOD, &GPIO_InitStructure);//初始化指定IO
 
 GPIO_InitStructure.GPIO_Pin  = GPIO_Pin_6;        //IRQ
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPD; //PG6 输入
 GPIO_Init(GPIOD, &GPIO_InitStructure);
 
 GPIO_ResetBits(GPIOD,GPIO_Pin_6|GPIO_Pin_7|GPIO_Pin_8);//PG6,7,8上拉
 
 SPI2_Init();                    //初始化SPI
 
 SPI_Cmd(SPI2, DISABLE); // SPI外设不使能
 
 SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;  //SPI设置为双线双向全双工
 SPI_InitStructure.SPI_Mode = SPI_Mode_Master;                //SPI主机
 SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;                //发送接收8位帧结构
 SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;                //时钟悬空低
 SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;        //数据捕获于第1个时钟沿
 SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;                //NSS信号由软件控制
 SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_16;                //定义波特率预分频的值:波特率预分频值为16
 SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;        //数据传输从MSB位开始
 SPI_InitStructure.SPI_CRCPolynomial = 7;        //CRC值计算的多项式
 SPI_Init(SPI2, &SPI_InitStructure);  //根据SPI_InitStruct中指定的参数初始化外设SPIx寄存器
 
 SPI_Cmd(SPI2, ENABLE); //使能SPI外设
 
 NRF24L01_CE=0;                         //使能24L01       D8
 NRF24L01_CSN=1;                        //SPI片选取消     D7
 
 }
 | 
 |