新手上路
- 积分
- 41
- 金钱
- 41
- 注册时间
- 2011-11-4
- 在线时间
- 0 小时
|
<div>u8 NRF24L01_TxPacket(u8 *txbuf)</div>
<div>{</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>u8 sta;</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>SPIx_SetSpeed(SPI_SPEED_16);//spi速度为9Mhz(24L01的最大SPI时钟为10Mhz) </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE=0;</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_Write_Buf(WR_TX_PLOAD,txbuf,TX_PLOAD_WIDTH);//写数据到TX BUF 32个字节</div>
<div> <span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE=1;//启动发送<span class="Apple-tab-span" style="white-space:pre;"> </span></div>
<div>//<span class="Apple-tab-span" style="white-space:pre;"> </span>delay_us(20);</div>
<div>//<span class="Apple-tab-span" style="white-space:pre;"> </span>NRF24L01_CE=0; </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>while(NRF24L01_IRQ!=0);//等待发送完成</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>sta=NRF24L01_Read_Reg(STATUS); //读取状态寄存器的值<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+STATUS,sta); //清除TX_DS或MAX_RT中断标志</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>if(sta&MAX_TX)//达到最大重发次数</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(FLUSH_TX,0xff);//清除TX FIFO寄存器 </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>return MAX_TX; </div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>if(sta&TX_OK)//发送完成</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>{</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>return TX_OK;</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>}</div>
<div><span class="Apple-tab-span" style="white-space:pre;"> </span>return 0xff;//其他原因发送失败</div>
<div>}<br />
问题是:NRF24L01_TxPacket(u8 *txbuf)返回的是MAX_TX。用示波器看IRQ那个引脚是只有10us的低电平,然后都是高电平?请问大家怎么就发送不能完成呢。</div> |
|