初级会员
- 积分
- 65
- 金钱
- 65
- 注册时间
- 2014-10-27
- 在线时间
- 0 小时
|
5金钱
<span></span><span>void Nrf24l01_Init(u8 model, u8 ch)</span><br />
<span>{</span><br />
<span></span><span> </span><span>SPI_CE_L();</span><br />
<span></span><span> </span><span>NRF_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS, RX_ADR_WIDTH); //写RX节点地址 </span><br />
<span></span><span> </span><span>NRF_Write_Buf(NRF_WRITE_REG+TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); //写TX节点地址 </span><br />
<span></span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+EN_AA, 0x01); //使能通道0的自动应答 </span><br />
<span></span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+EN_RXADDR, 0x01); //使能通道0的接收地址 </span><br />
<span></span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x1a); //设置自动重发间隔时间:500us;最大自动重发次数:10次 </span><br />
<span></span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+RF_CH, 40); //设置RF通道为CHANAL</span><br />
<span></span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP, 0x0f); //设置TX发射参数,0db增益,2Mbps,低噪声增益开启</span><br />
<span></span><span> </span><span>//NRF_Write_Reg(NRF_WRITE_REG+RF_SETUP, 0x07); //设置TX发射参数,0db增益,1Mbps,低噪声增益开启</span><br />
<span> </span><span>/////////////////////////////////////////////////////////</span><br />
<span></span><span> </span><span>i</span><span>f(model==1) //RX</span><br />
<span></span><span> </span><span>{</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //选择通道0的有效数据宽度 </span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQ收发完成中断开启,16位CRC,主接收</span><br />
<span></span><span> </span><span>}</span><br />
<span></span><span> </span><span>else if(model==2) //TX</span><br />
<span></span><span> </span><span>{</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //选择通道0的有效数据宽度 </span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQ收发完成中断开启,16位CRC,主发送</span><br />
<span></span><span> </span><span>}</span><br />
<span></span><span> </span><span>else if(model==3) //RX2</span><br />
<span></span><span> </span><span>{</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(FLUSH_TX,0xff); //清除TX FIFO寄存器</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(FLUSH_RX,0xff); //清除RX FIFO寄存器</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0f); // IRQ收发完成中断开启,16位CRC,主接收</span><br />
<br />
<span></span><span> </span><span> </span><span>Spi_RW(0x50);</span><br />
<span></span><span> </span><span> </span><span>Spi_RW(0x73);</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); //使能通道0的动态数据长度</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); //使能总通道动态数据,且使能ACK应答</span><br />
<span></span><span> </span><span>}</span><br />
<span></span><span> </span><span>else //TX2</span><br />
<span></span><span> </span><span>{</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG + CONFIG, 0x0e); // IRQ收发完成中断开启,16位CRC,主发送</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(FLUSH_TX,0xff); //清除TX FIFO寄存器</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(FLUSH_RX,0xff); //清除RX FIFO寄存器</span><br />
<br />
<span></span><span> </span><span> </span><span> </span><span>Spi_RW(0x50);</span><br />
<span></span><span> </span><span> </span><span>Spi_RW(0x73);</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+0x1c,0x01); //使能通道0的动态数据长度</span><br />
<span></span><span> </span><span> </span><span>NRF_Write_Reg(NRF_WRITE_REG+0x1d,0x06); //使能总通道动态数据长度,且总使能ACK应答</span><br />
<span></span><span> </span><span>}<br />
<span> </span><span>SPI_CE_H();</span><br />
<span>}<br />
</span><br />
上面</span>这个函数是四轴程序里NRF24L01无线模块的初始化函数,但是其中<span> <br />
</span><span> </span><span>Spi_RW(0x50);</span><br />
<span></span><span> </span><span> </span><span>Spi_RW(0x73);<br />
这两条语句是什么意思呢?前面<br />
uint8_t NRF_Write_Reg(uint8_t reg, uint8_t value)<br />
{<br />
uint8_t status;<br />
SPI_CSN_L(); /* 选通器件 */<br />
status = Spi_RW(reg); /* 写寄存器地址 */<br />
Spi_RW(value); /* 写数据 */<br />
SPI_CSN_H(); /* 禁止该器件 */<br />
return status;<br />
}<br />
<br />
这个函数都<span> ( </span><span>SPI_CSN_H(); /* 禁止该器件 */)关掉该无线模块了,这两条语句能起到作用吗?</span><br />
</span><br />
<br />
<br /> |
|