|
24L01丢数据严重,要有重发功能应该如何设置?
[复制链接]
//代码来自本论坛shower.xu
void init_NRF24L01(void)
{
Delay_us(100);
PORT &=~BIT(CE);
PORT |= BIT(CSN);
PORT &=~BIT(CLK);
SPI_Write_Buf(WRITE_REG + TX_ADDR, TX_ADDRESS1, TX_ADR_WIDTH); // Writes TX_Address to nRF24L01
SPI_Write_Buf(WRITE_REG + RX_ADDR_P0, TX_ADDRESS1, TX_ADR_WIDTH); // RX_Addr0 same as TX_Adr for Auto.Ack
//SPI_Write_Buf(WR_TX_PLOAD, tx_buf, TX_PLOAD_WIDTH1); // Writes data to TX payload
SPI_RW_Reg(WRITE_REG + EN_AA, 0x01); // 禁止所有Pipe自动应答,调试TX时
SPI_RW_Reg(WRITE_REG + EN_RXADDR, 0x01); // 禁止所有接受通道
//SPI_RW_Reg(WRITE_REG + SETUP_RETR, 0x00); // 禁止自动重发
SPI_RW_Reg(WRITE_REG + RF_CH, 0); // Select RF channel 40
SPI_RW_Reg(WRITE_REG + RX_PW_P0, RX_PLOAD_WIDTH); //设置接收数据长度
SPI_RW_Reg(WRITE_REG + RF_SETUP, 0x07); // TX_PWR:-12dBm, Datarate:1Mbps, LNA:HCURR
SPI_RW_Reg(WRITE_REG + CONFIG, 0x0e); // Set PWR_UP bit, enable CRC(2 bytes) & Prim:TX. MAX_RT & TX_DS enabled..
}
void main()
{
unsigned char IncreaseData;
WDTCTL = WDTPW + WDTHOLD;
IO_initial();
init_NRF24L01();
GLED_off();
while(1)
{
msg[0]=IncreaseData;
nRF24L01_TxPacket(msg); //要检测掉包自动重发功能,这里需不需要怎样修改啊?
SPI_RW_Reg(WRITE_REG+STATUS,0xff); // clear interrupt flag(TX_DS)
Delay_us(10000);
GLED_ray();
Delay_us(10000);
IncreaseData++;
}
例子是自本论坛shower.xu的例子。我下载后能收发数据,但是连续发送数据接收端收到的数据经常是不连续的。
问题:发现对方接收不到则重发功能应该如何设置?
是在init_NRF24L01()里设置(24L01就自动重发?)还是在Main()里设置?
|
|