OpenEdv-开源电子网

 找回密码
 立即注册
正点原子全套STM32/Linux/FPGA开发资料,上千讲STM32视频教程免费下载...
查看: 3930|回复: 1

关于nrf24l01的问题

[复制链接]

6

主题

12

帖子

0

精华

初级会员

Rank: 2

积分
56
金钱
56
注册时间
2013-7-31
在线时间
0 小时
发表于 2013-10-25 17:19:18 | 显示全部楼层 |阅读模式
<div><span style="font-size:14px;">问题:<br />
1.<br />
void RX_Mode(void)</span></div>
<div><span style="font-size:14px;">{</span></div>
<div><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_CE=0;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Buf(WRITE_REG+</span><span style="color:#e53333;font-size:14px;">RX_ADDR_P1</span><span style="font-size:14px;">,(u8*)RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址</span></div>
<div><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+EN_AA,0x01); &nbsp; &nbsp;//使能通道0的自动应答 &nbsp; &nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+EN_RXADDR,0x01);//使能通道0的接收地址 &nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+RF_CH,40);</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;&nbsp; &nbsp; //设置RF通信频率</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">                </span><span style="font-size:14px;">&nbsp;&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH);//选择通道0的有效数据宽度&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;&nbsp; &nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+RF_SETUP,0x0f);//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 &nbsp;&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_CE = 1; //CE为高,进入接收模式&nbsp;</span></div>
<div><span style="font-size:14px;">}</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">                                                </span><span style="font-size:14px;">&nbsp;</span></div>
<div><span style="font-size:14px;">//该函数初始化NRF24L01到TX模式</span></div>
<div><span style="font-size:14px;">//设置TX地址,写TX数据宽度,设置RX自动应答的地址,填充TX发送数据,选择RF频道,波特率和LNA HCURR</span></div>
<div><span style="font-size:14px;">//PWR_UP,CRC使能</span></div>
<div><span style="font-size:14px;">//当CE变高后,即进入RX模式,并可以接收数据了</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">                </span><span style="font-size:14px;">&nbsp;&nbsp;&nbsp;</span></div>
<div><span style="font-size:14px;">//CE为高大于10us,则启动发送.</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;</span></div>
<div><span style="font-size:14px;">void TX_Mode(void)</span></div>
<div><span style="font-size:14px;">{</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">                                                                                                                </span><span style="font-size:14px;">&nbsp;</span></div>
<div><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_CE=0;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;&nbsp; &nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Buf(WRITE_REG+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH);//写TX节点地址&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Buf(WRITE_REG+</span><span style="font-size:14.399999618530273px;line-height:16.799999237060547px;color:#e53333;">RX_ADDR_P1</span><span style="font-size:14px;">,(u8*)RX_ADDRESS,RX_ADR_WIDTH); //设置TX节点地址,主要为了使能ACK</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">&nbsp;&nbsp;</span></div>
<div><br />
</div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+EN_AA,0x01); &nbsp; &nbsp; //使能通道0的自动应答 &nbsp; &nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+EN_RXADDR,0x01); //使能通道0的接收地址 &nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+SETUP_RETR,0x1a);//设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+RF_CH,40); &nbsp; &nbsp; &nbsp; //设置RF通道为40</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+RF_SETUP,0x0f); &nbsp;//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 &nbsp;&nbsp;</span></div>
<div><span style="font-size:14px;">&nbsp;&nbsp;</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+CONFIG,0x0e); &nbsp; &nbsp;//配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式,开启所有中断</span></div>
<div><span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        </span><span style="font-size:14px;">NRF24L01_CE=1;//CE为高,10us后启动发送</span></div>
<div><span style="font-size:14px;">}</span><br />
<span class="Apple-tab-span" style="white-space:pre;font-size:14px;">        <br />
这是<br />
        </span><span style="font-size:14px;">一对一的发送,红色的部分是我在源码的基础上修改的,void TX_Mode(void)函数中无论写成</span><span style="color:#e53333;font-size:14px;">,或是</span><span style="color:#e53333;font-size:14px;">RX_ADDR_P1,</span><span style="font-size:14px;">void RX_Mode(void) 函数中写成&nbsp;</span><span style="color:#e53333;font-size:14px;">RX_ADDR_P1或是</span><span style="color:#e53333;font-size:14px;">RX_ADDR_P0,<span style="color:#000000;">这四种任意组合均可,在发射端写</span></span><span style="color:#e53333;font-size:14px;">RX_ADDR_P0<span style="color:#000000;">是为了让0通道应答,而接收端写</span></span><span style="color:#e53333;font-size:14px;">RX_ADDR_P1<span style="color:#000000;">,是设置1通道接收,为什么还能通信?<br />
&nbsp;2 &nbsp;&nbsp;&nbsp; &nbsp; 在发射函数中有这样一句话,</span></span><span style="font-size:14px;">NRF24L01_Write_Reg(WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH);改成NRF24L01_Write_Reg(WRITE_REG+</span><span style="color:#e53333;font-size:14px;">RX_PW_P1</span><span style="font-size:14px;">,RX_PLOAD_WIDTH);</span><br />
<span style="font-size:14px;">我在一个帖子中,发帖人说</span><span style="background-color:#d1d9e2;font-family:微软雅黑;font-size:14px;line-height:normal;">接收摸式下可以不设置发送的有效数据宽度,但接收模式一定要!!<span style="background-color:#ffffff;">,我设置了1通道的宽度,没有设置0通道的数据宽度,一样可以通信,为什么?</span><span style="background-color:#ffffff;">(原帖地址</span></span><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">http://www.openedv.com/posts/list/6369.htm#31824</span></span><span style="background-color:#d1d9e2;font-size:14px;"><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;background-color:#ffffff;">)</span></span><br />
<span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;background-color:#ffffff;">3 我把发送端和接收端的关于0通道的全部变为1通道为什么不能通信?难道用一个通道通信,只能用0通道吗?(发送端数据显示在lcd上,但是接收端接受不到数据,无法再lcd上显示)</span></span><br />
<span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;background-color:#ffffff;">函数如下:</span></span><br />
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">void RX_Mode(void)</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">{</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;"><span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_CE=0;<span class="Apple-tab-span" style="white-space:pre;">        </span>&nbsp;&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Buf(WRITE_REG+RX_ADDR_P1,(u8*)RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;"><span class="Apple-tab-span" style="white-space:pre;">        </span>&nbsp;&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Reg(WRITE_REG+EN_AA,0x02); &nbsp; &nbsp;//使能通道0的自动应答 &nbsp; &nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Reg(WRITE_REG+EN_RXADDR,0x02);//使能通道0的接收地址 &nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Reg(WRITE_REG+RF_CH,40);<span class="Apple-tab-span" style="white-space:pre;">        </span>&nbsp;&nbsp; &nbsp; //设置RF通信频率<span class="Apple-tab-span" style="white-space:pre;">                </span>&nbsp;&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Reg(WRITE_REG+RX_PW_P1,RX_PLOAD_WIDTH);//选择通道0的有效数据宽度&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>&nbsp;&nbsp; &nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Reg(WRITE_REG+RF_SETUP,0x0f);//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 &nbsp;&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_Write_Reg(WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">&nbsp;&nbsp;<span class="Apple-tab-span" style="white-space:pre;">        </span>NRF24L01_CE = 1; //CE为高,进入接收模式&nbsp;</span></span></div>
<div><span style="color:#ff0000;font-family:微软雅黑;font-size:medium;"><span style="line-height:normal;font-size:14px;color:#000000;">}</span><span class="Apple-tab-span" style="white-space:pre;font-size:14px;color:#000000;"><span style="line-height:normal;font-size:14px;color:#000000;">        <br />
</span><div><span style="line-height:normal;">void TX_Mode(void)</span></div>
<div><span style="line-height:normal;">{<span class="Apple-tab-span">                                                                                                                </span>&nbsp;</span></div>
<div><span style="line-height:normal;"><span class="Apple-tab-span">        </span>NRF24L01_CE=0;<span class="Apple-tab-span">        </span> &nbsp; &nbsp;</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Buf(WRITE_REG+TX_ADDR,(u8*)TX_ADDRESS,TX_ADR_WIDTH);//写TX节点地址&nbsp;</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Buf(WRITE_REG+RX_ADDR_P1,(u8*)RX_ADDRESS,RX_ADR_WIDTH); //设置TX节点地址,主要为了使能ACK<span class="Apple-tab-span">        </span> &nbsp;</span></div>
<div><span style="line-height:normal;"><br />
</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Reg(WRITE_REG+EN_AA,0x02); &nbsp; &nbsp; //使能通道0的自动应答 &nbsp; &nbsp;</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Reg(WRITE_REG+EN_RXADDR,0x02); //使能通道0的接收地址 &nbsp;</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Reg(WRITE_REG+SETUP_RETR,0x1a);//设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Reg(WRITE_REG+RF_CH,40); &nbsp; &nbsp; &nbsp; //设置RF通道为40</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Reg(WRITE_REG+RF_SETUP,0x0f); &nbsp;//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 &nbsp;&nbsp;</span></div>
<div><span style="line-height:normal;">&nbsp; <span class="Apple-tab-span">        </span>NRF24L01_Write_Reg(WRITE_REG+CONFIG,0x0e); &nbsp; &nbsp;//配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式,开启所有中断</span></div>
<div><span style="line-height:normal;"><span class="Apple-tab-span">        </span>NRF24L01_CE=1;//CE为高,10us后启动发送</span></div>
<div><span style="line-height:normal;">}<span class="Apple-tab-span">        <br />
请</span>教。</span></div>
</span></span></div>
</span></div>
正点原子逻辑分析仪DL16劲爆上市
回复

使用道具 举报

38

主题

2061

帖子

6

精华

论坛大神

Rank: 7Rank: 7Rank: 7

积分
3273
金钱
3273
注册时间
2012-1-16
在线时间
37 小时
发表于 2013-10-25 21:33:15 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则



关闭

原子哥极力推荐上一条 /2 下一条

正点原子公众号

QQ|手机版|OpenEdv-开源电子网 ( 粤ICP备12000418号-1 )

GMT+8, 2024-11-23 18:44

Powered by OpenEdv-开源电子网

© 2001-2030 OpenEdv-开源电子网

快速回复 返回顶部 返回列表