<div style="background-color:#E8E8E8;">
[mw_shl_code=c,true]设置的地址:[/mw_shl_code]
[mw_shl_code=c,true]const u8 TX_ADDRESS[TX_ADR_WIDTH]= {0x00,0xc2,0xc2,0xc2,0xc2}; //发送地址;; //发送地址()
const u8 RX_ADDRESS[RX_ADR_WIDTH]= {0x00,0xc2,0xc2,0xc2,0xc2}; //接收地址0
const u8 RX_ADDRESS1[RX_ADR_WIDTH]={0x01,0xc2,0xc2,0xc2,0xc2}; //接收地址1
const u8 RX_ADDRESS2[RX_ADR_WIDTH]={0x02,0xc2,0xc2,0xc2,0xc2}; //接收地址2
const u8 RX_ADDRESS3[RX_ADR_WIDTH]={0x03,0xc2,0xc2,0xc2,0xc2}; //接收地址3
const u8 RX_ADDRESS4[RX_ADR_WIDTH]={0x04,0xc2,0xc2,0xc2,0xc2}; //接收地址4
const u8 RX_ADDRESS5[RX_ADR_WIDTH]={0x05,0xc2,0xc2,0xc2,0xc2}; //接收地址5[/mw_shl_code]
[mw_shl_code=c,true]接收机配置:[/mw_shl_code]
[mw_shl_code=c,true]
<div style="background-color:#E8E8E8;">
[mw_shl_code=c,true]void NRF24L01_RX_Mode(void)
{
NRF24L01_CE=0;
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,(u8*)RX_ADDRESS,RX_ADR_WIDTH);//写RX0节点地址
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P1,(u8*)RX_ADDRESS1,RX_ADR_WIDTH);//写RX1节点地址
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P2,(u8*)RX_ADDRESS2,RX_ADR_WIDTH);//写RX2节点地址
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P3,(u8*)RX_ADDRESS3,RX_ADR_WIDTH);//写RX3节点地址
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P4,(u8*)RX_ADDRESS4,RX_ADR_WIDTH);//写RX4节点地址
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P5,(u8*)RX_ADDRESS5,RX_ADR_WIDTH);//写RX5节点地址
NRF24L01_Write_Reg(NRF_WRITE_REG+EN_AA,0x3f); //使能通道0,1,2,3,4,5的自动应答
NRF24L01_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x3f);//使能通道0,1,2,3,4,5的接收地址
NRF24L01_Write_Reg(NRF_WRITE_REG+RF_CH,40); //设置RF通信频率
NRF24L01_Write_Reg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH);//选择通道0~5的有效数据宽度
NRF24L01_Write_Reg(NRF_WRITE_REG+RX_PW_P1,RX_PLOAD_WIDTH);
NRF24L01_Write_Reg(NRF_WRITE_REG+RX_PW_P2,RX_PLOAD_WIDTH);
NRF24L01_Write_Reg(NRF_WRITE_REG+RX_PW_P3,RX_PLOAD_WIDTH);
NRF24L01_Write_Reg(NRF_WRITE_REG+RX_PW_P4,RX_PLOAD_WIDTH);
NRF24L01_Write_Reg(NRF_WRITE_REG+RX_PW_P5,RX_PLOAD_WIDTH);
NRF24L01_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f);//设置TX发射参数,0db增益,2Mbps,低噪声增益开启
NRF24L01_Write_Reg(NRF_WRITE_REG+CONFIG,0x0f);//配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式
NRF24L01_CE = 1; //CE为高,进入接收模式
} [/mw_shl_code]
发送机配置:
<div style="background-color:#E8E8E8;">
[mw_shl_code=c,true]void NRF24L01_TX_Mode(void)//通道2发送
{
NRF24L01_CE=0;
NRF24L01_Write_Buf(NRF_WRITE_REG+TX_ADDR,(u8*)RX_ADDRESS2,TX_ADR_WIDTH);//写TX节点地址,是通道2
NRF24L01_Write_Buf(NRF_WRITE_REG+RX_ADDR_P0,(u8*)RX_ADDRESS,5); //设置RX节点地址,主要为了使能ACK
NRF24L01_Write_Reg(NRF_WRITE_REG+EN_AA,0x3f); //使能通道0~5的自动应答
NRF24L01_Write_Reg(NRF_WRITE_REG+EN_RXADDR,0x3f); //使能通道0~5的接收地址
NRF24L01_Write_Reg(NRF_WRITE_REG+SETUP_RETR,0x1a);//设置自动重发间隔时间:500us + 86us;最大自动重发次数:10次
NRF24L01_Write_Reg(NRF_WRITE_REG+RF_CH,40); //设置RF通道为40
NRF24L01_Write_Reg(NRF_WRITE_REG+RF_SETUP,0x0f); //设置TX发射参数,0db增益,2Mbps,低噪声增益开启
NRF24L01_Write_Reg(NRF_WRITE_REG+CONFIG,0x0e); //配置基本工作模式的参数WR_UP,EN_CRC,16BIT_CRC,接收模式,开启所有中断
NRF24L01_CE=1;//CE为高,10us后启动发送
}[/mw_shl_code]
</div>
<br />
</div>
<br />
<br />
[/mw_shl_code]
</div> |