我正在用C ++在树莓派零上创建一个项目,并在PIC18F26Q10上创建C,其中多个PIC将传感器数据传输到树莓派。 两种设备都可以相互发送和接收数据.我的问题是将成为PRX设备的树莓派只能在数据管道0和1上接收数据。将数据发送到任何其他数据管道会导致PIC端发生最大重试中断.我能够成功地将所有数据管道地址传输到PIC,但是PIC仅具有数据管道0,并且启用了对数据管道0的自动确认。 我已经启用了EN_RXADDR寄存器中的所有数据管道,还启用了EN_AA_REG寄存器中的所有数据管道的自动确认。
我缺少启用数据管道2到5的设置或详细信息吗?
我正在使用C ++和PIGPIO库来控制GPIO。
我的数据管道在头文件中的定义为:
char channelP0[5] = { 0xE7, 0xE7, 0xE7, 0xE7, 0xE7 };
char channelP1[5] = { 0xC2, 0xC2, 0xC2, 0xC2, 0xC2 };
char channelP2[5] = { 0xC2, 0xC2, 0xC2, 0xC2, 0xC3 };
char channelP3[5] = { 0xC2, 0xC2, 0xC2, 0xC2, 0xC4 };
char channelP4[5] = { 0xC2, 0xC2, 0xC2, 0xC2, 0xC5 };
char channelP5[5] = { 0xC2, 0xC2, 0xC2, 0xC2, 0xC6 };
上面的代码块对于PIC18F26Q10和RAspberry pi都是相同的。
这是我的初始化代码:
int NRF24L10::Initialize(int channel)
{
if (handle < 0) //If already open, ignore and return -1.
{
gpioWrite(NRF24_CE, 0);
handle = spiOpen(channel, 100000, 0);
WriteRegister(CONFIG_REG, 0x0D); // RX, TX & Max Retry interrupt enabled, PRX mode, Power Down, 2 byte CRC
WriteRegister(EN_RXADDR_REG, 0x3F); // Enable all data pipe RX addresses
WriteRegister(EN_AA_REG, 0x3F); // Enable auto acknowledge for all data pipes
Powerup();
WriteRegister(SETUP_AW_REG, 0x03);
WriteRegister(SETUP_RETR_REG,0xF3 );
WriteRegister(SETUP_AW_REG, 0x03);
WriteRegister(SETUP_RETR_REG, 0xF3);
WriteRegister(RF_CH_REG, 0x50); // Set to 2480Mhz, outer edge of chanel 13 but still within legal limits
WriteRegister(RF_SETUP_REG, 0x02); // Set gain low for testing.
WriteRegister(STATUS_REG, 0x70);
Activate(); // Enable R_RX_PL_WID
WriteRegister(DYNPD_REG, 0x3F); // Enable dynamic data width on all datapipes
WriteRegister(FEATURE_REG, 0x04); // Enable dynamic data width feature
WriteRegisterBytes(RX_ADDR_P0_REG, channelP0, 5);
WriteRegisterBytes(RX_ADDR_P1_REG, channelP1, 5);
WriteRegister(RX_ADDR_P2_REG, channelP2[4]);
WriteRegister(RX_ADDR_P3_REG, channelP3[4]);
WriteRegister(RX_ADDR_P4_REG, channelP4[4]);
WriteRegister(RX_ADDR_P5_REG, channelP5[4]);
FlushRX();
FlushTX();
PRXmode();
return handle;
}
else
{
return -1;
}
}
最新回答
- 2021-1-41 #
我为lg库添加了NRF24示例。
也许看看是否可以根据您的需要更改C示例之一。
本地C NRF24
本地和远程C NRF24