楼主你好。接收的时候先检测,是指在判断RX_DR之前检测,还是在判断RX_RD之后检测。
我的接收函数如下:
state=SPI_NRF_ReadReg(STATUS);
SPI_NRF_WriteReg(NRF_WRITE_REG+STATUS,state);
if(state&RX_DR)
{
//first read received length from the R_RX_PAYLOAD
receive_length=SPI_NRF_RW(R_RX_PL_WID); //接收的时候需要先检测R_RX_PL_WID(0x60)
printf("data_length = %d\r\n",receive_length);
SPI_NRF_ReadBuf(RD_RX_PLOAD,rxbuf,receive_length);
SPI_NRF_WriteReg(FLUSH_RX,NOP);
return RX_DR;
}
但是此时receive_length=255.我发送端发送了6个数据,接收端能接收,但是receive_length是错误的。
nRF24L01+RX模式如下:
SPI_NRF_WriteBuf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH);
SPI_NRF_WriteReg(NRF_WRITE_REG+EN_AA,0x01);
SPI_NRF_WriteReg(NRF_WRITE_REG+EN_RXADDR,0x01);
SPI_NRF_WriteReg(NRF_WRITE_REG+RF_CH,CHANAL);
//SPI_NRF_WriteReg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //static payload length setting
SPI_NRF_WriteReg(NRF_WRITE_REG+FEATURE, 0x04); // Enable Dynamic payload length
SPI_NRF_WriteReg(NRF_WRITE_REG+DYNDP, 0x01); //Enable dynamic payload lenght data pipe 0
SPI_NRF_WriteReg(NRF_WRITE_REG+RF_SETUP,0x0f);
SPI_NRF_WriteReg(NRF_WRITE_REG+CONFIG, 0x0f);
TX模式如下:
SPI_NRF_WriteBuf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); // Set PTX Address
SPI_NRF_WriteBuf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH); // Set PRX Address for EN_Auto_ACK
SPI_NRF_WriteReg(NRF_WRITE_REG+EN_AA,0x01); //Enable Auto ack data pipe 0
//SPI_NRF_WriteReg(NRF_WRITE_REG+EN_RXADDR,0x01); // Enable data pipe 0
SPI_NRF_WriteReg(NRF_WRITE_REG+SETUP_RETR,0x2a);// Setup of Automatic Retransmission 750uS,10 retranmsion
SPI_NRF_WriteReg(NRF_WRITE_REG+RF_CH,CHANAL); //Channel 40
SPI_NRF_WriteReg(NRF_WRITE_REG+RF_SETUP,0x0f); // 2Mbps,0dB
SPI_NRF_WriteReg(NRF_WRITE_REG+FEATURE, 0x04); //Enable Dynamic payload length
SPI_NRF_WriteReg(NRF_WRITE_REG+DYNDP, 0x01); //Enable dymamic payload length data pipe 0
SPI_NRF_WriteReg(NRF_WRITE_REG+CONFIG,0x0e); // PTX,Power UP,CRC 2Bytes,EN_CRC
请问楼主指教下在使用Dynamic Payload Length发送和接收数据时需要注意哪些问题啊?