金牌会员
- 积分
- 1633
- 金钱
- 1633
- 注册时间
- 2012-8-28
- 在线时间
- 71 小时
|
楼主 |
发表于 2013-5-13 16:01:08
|
显示全部楼层
<div>const u8 ip[6]={'0','F','U','C','K',0x00};//发射地址 那个0x00用于LCD函数结束显示</div>
<div>const u8 ip0[6]={'0','F','U','C','K',0x00};//接收地址0 我调了2天</div>
<div>const u8 ip1[6]={'1','F','U','C','K',0x00};//接收地址1 才发现低位在前,高位在后。</div>
<div> //(低位优先,写的时候低位写到高位,读的时候低位先被读出)</div>
<div>const u8 ip2[6]={'2','F','U','C','K',0x00};//接收地址2 地址char5,char4,char3,char2,char1.</div>
<div>const u8 ip3[6]={'3','F','U','C','K',0x00};//接收地址3<span class="Apple-tab-span" style="white-space:pre;"> </span>通道2345只能设置char1</div>
<div>const u8 ip4[6]={'4','F','U','C','K',0x00};//接收地址4<span class="Apple-tab-span" style="white-space:pre;"> </span>写的时候顺序是char1,char2,char3,char4,char5</div>
<div>const u8 ip5[6]={'5','F','U','C','K',0x00};//接收地址5<span class="Apple-tab-span" style="white-space:pre;"> <br />
<br />
<div>void RX_Mode(void)//接收</div>
<div>{</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_CE=0; <span class="Apple-tab-span"> </span> //设置24L01+关闭,用于修改无线配置<span class="Apple-tab-span"> </span></div>
<div> NRF24L01_Write_Reg(0x20+0x00,0x0f);//配置接收模式的基本参数WR_UP,EN_CRC,16BIT_CRC,</div>
<div> NRF24L01_Write_Reg(0x20+0x01,0x3f);//应答设置0x3f代表543210应答</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x01,careg,1); //该函数检查无线寄存器0x01的内容</div>
<div> NRF24L01_Write_Reg(0x20+0x02,0x3f);//接收通道使能0x3f代表543210通道接收</div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x05,50); //设置RF通信频率2.4G+设置值Mhz。范围0x00到0x7f</div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x06,0x0f);//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 </div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x06,0xa7);//24L01+模块设置TX发射参数,0db增益,250kbps,低噪声增益开启</div>
<div><br />
</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X0a,(u8*)ip0,5);//写RX0接收地址</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x0a,caip0,5);<span class="Apple-tab-span"> </span> //查地址确定已写入</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X0b,(u8*)ip1,5);//写RX1接收地址</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x0b,caip1,5);</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X0c,(u8*)ip2,1);//写RX2接收地址(只写1次,原因高位都被锁了)</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x0c,caip2,5);</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X0d,(u8*)ip3,1);//写RX3接收地址 </div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x0d,caip3,5);</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X0e,(u8*)ip4,1);//写RX4接收地址</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x0e,caip4,5);</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X0f,(u8*)ip5,1);//写RX5接收地址</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x0f,caip5,5);</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0X20+0X10,(u8*)ip1,5);//写TX的地址</div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Read_Buf(0x10,caout,5);</div>
<div><br />
</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x11,32);//选择通道0的有效数据宽度32字节 </div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x12,32);//选择通道1的有效数据宽度32字节 </div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x13,32);//选择通道2的有效数据宽度32字节 </div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x14,32);//选择通道3的有效数据宽度32字节 </div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x15,32);//选择通道4的有效数据宽度32字节 </div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x16,32);//选择通道5的有效数据宽度32字节 </div>
<div><br />
</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_CE = 1; //CE为高,进入接收模式</div>
<div><br />
</div>
<div><br />
</div>
<div>}<span class="Apple-tab-span"> </span> </div>
<div><br />
</div>
<div>//该函数初始化NRF24L01到TX模式</div>
<div>//设置TX地址,写TX数据宽度,设置RX自动应答的地址,填充TX发送数据,选择RF频道,波特率和LNA HCURR</div>
<div>//PWR_UP,CRC使能</div>
<div>//当CE变高后,即进入RX模式,并可以接收数据了<span class="Apple-tab-span"> </span> </div>
<div>//CE为高大于10us,则启动发送.<span class="Apple-tab-span"> </span> </div>
<div>void TX_Mode(void)//发射</div>
<div>{<span class="Apple-tab-span"> </span> </div>
<div><span class="Apple-tab-span"> </span>NRF24L01_CE=0;//无线待机<span class="Apple-tab-span"> </span> </div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0x20+0x10,(u8*)ip,5);//写TX节点地址 </div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Buf(0x20+0x0a,(u8*)ip0,5); //设置TX节点地址,主要为了使能ACK<span class="Apple-tab-span"> </span> </div>
<div><br />
</div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x01,0x3f); //使能通道543210的自动应答 </div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x02,0x3f); //使能通道543210的接收地址 </div>
<div><br />
</div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x04,0xff);//设置自动重发间隔时间:4000us + 86us;最大自动重发次数:15次</div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x05,50); //设置RF通道。最大为(111 1111)Mhz +2.4Ghz</div>
<div> <span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x06,0x0f); //设置TX发射参数,0db增益,2Mbps,低噪声增益开启 </div>
<div>//<span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x06,0xa7);//24L01+模块设置TX发射参数,0db增益,250kbps,低噪声增益开启</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_Write_Reg(0x20+0x00,0x0e); //配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式,开启所有中断</div>
<div><span class="Apple-tab-span"> </span>NRF24L01_CE=1;//CE为高,10us后启动发送</div>
<div>}<span class="Apple-tab-span"> </span> </div>
<div><br />
</div>
<br />
</span></div> |
|