初级会员
- 积分
- 68
- 金钱
- 68
- 注册时间
- 2013-5-5
- 在线时间
- 0 小时
|
<div>我想让程序一块一直发送一块一直接受,但是我的程序可以实现一直发送,但是一直无法接受,程序如下接受模式被注释。<br />
请大神帮忙看一下程序有没有问题。<br />
<br />
#include <stm32f10x_lib.h><br />
</div>
<div>#include "sys.h"</div>
<div>#include "usart.h"<span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div>#include "delay.h"<span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div>#include "led.h" <span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div>#include "NRF24l01.h"</div>
<div>#include "key.h"</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div>int main(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> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>u8 Tx_Buf1[]={1}; //要发送的数据 1</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>u8 Rx_Buf[32]; //接收到的数据 最多32字节</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>u8 key=0;</div>
<div><br />
</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>Stm32_Clock_Init(9);//系统时钟设置</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>delay_init(72);<span class="Apple-tab-span" style="white-space:pre;"> </span>//延时初始化</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>uart_init(72,9600); //串口1初始化 <span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>KEY_Init();<span class="Apple-tab-span" style="white-space:pre;"> </span> <span class="Apple-tab-span" style="white-space:pre;"> </span>//按键初始化</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>LED_Init(); //LED初始化</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Init(); //初始化NRF24L01 </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> LED1=1;//<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>while(1)//</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>TX_Mode();<span class="Apple-tab-span" style="white-space:pre;"> </span>//发送模式 </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_TxPacket(Tx_Buf1);<span class="Apple-tab-span" style="white-space:pre;"> </span>// 发送命令数据</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>LED1=0;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>delay_ms(300);</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>LED1=1;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>delay_ms(300);<span class="Apple-tab-span" style="white-space:pre;"> </span>//发送后LED1闪一下<span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div>/*<span class="Apple-tab-span" style="white-space:pre;"> </span>RX_Mode();//接收模式</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> if(Rx_Buf[0]==1)<span class="Apple-tab-span" style="white-space:pre;"> </span> //若接收到对应的数据则实现对应功能 </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> Rx_Buf[0]=0;//清空数据 </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> LED0=0;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> delay_ms(300);</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> LED0=1;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span> delay_ms(300);//接收到数据 后闪烁<span class="Apple-tab-span" style="white-space:pre;"> </span> </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>}*/<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>}</div> |
|