初级会员
- 积分
- 127
- 金钱
- 127
- 注册时间
- 2013-11-15
- 在线时间
- 0 小时
|
请教各位大神,,原子哥的24L01模块配套的程序里的接收模式和发射模式要怎么设置才能使它传输和接收的距离最远啊? <br />
<br />
<span style="color:#e53333;">//下面两个函数怎么改</span><br />
<div>//该函数初始化NRF24L01到RX模式</div>
<div>//设置RX地址,写RX数据宽度,选择RF频道,波特率和LNA HCURR</div>
<div>//当CE变高后,即进入RX模式,并可以接收数据了<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div>void NRF24L01_RX_Mode(void)</div>
<div>{</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE=0;<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Buf(WRITE_REG_NRF+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+EN_AA,0x01); //使能通道0的自动应答 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+EN_RXADDR,0x01);//使能通道0的接收地址 <span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+RF_CH,40);<span class="Apple-tab-span" style="white-space:pre;"> </span> //设置RF通信频率<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+RX_PW_P0,RX_PLOAD_WIDTH);//选择通道0的有效数据宽度 <span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+RF_SETUP,0x0f);//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+CONFIG, 0x0f);//配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE = 1; //CE为高,进入接收模式 </div>
<div>}<span class="Apple-tab-span" style="white-space:pre;"> </span> </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" style="white-space:pre;"> </span> </div>
<div>//CE为高大于10us,则启动发送.<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div>void NRF24L01_TX_Mode(void)</div>
<div>{<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE=0;<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Buf(WRITE_REG_NRF+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH);//写TX节点地址 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Buf(WRITE_REG_NRF+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH); //设置TX节点地址,主要为了使能ACK<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><br />
</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+EN_AA,0x01); //使能通道0的自动应答 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+EN_RXADDR,0x01); //使能通道0的接收地址 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+SETUP_RETR,0x1a);//设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+RF_CH,40); //设置RF通道为40</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+RF_SETUP,0x0f); //设置TX发射参数,0db增益,2Mbps,低噪声增益开启 </div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Reg(WRITE_REG_NRF+CONFIG,0x0e); //配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式,开启所有中断</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE=1;//CE为高,10us后启动发送</div>
<div>}<span class="Apple-tab-span" style="white-space:pre;"> </span> </div> |
|