nRF24L01 + can not receive or receiving occasional abnormal combat issues such as sharing

Summary of reception is abnormal nRF24L01 +

Debug nRF24L01 + wireless transceiver module when the most part of the flag is at the receiving end can receive the data. In practical application debugging, there will be a lot of unexpected circumstances, cause nRF24L01 + module receiving end can not receive data sent by the sender.

Based on past experience repeatedly N nRF24L01 + debugging module, can be divided into summary the following cases:
data not received a sending end: a phenomenon
Phenomenon 2: only the receiving side or the transmitting side re-power when a received
phenomenon 3: occasionally sending the data can not be received after the reception mode into the
phenomenon 4: a module with a period PA of power can not receive the
phenomenon 5: occasional irregular can not be received
will be in accordance with this 5 phenomenon there is a solution targeted share of actual combat, respectively.

How quickly determine nRF24L01 + is a communication failures at the receiving end

In debugging nRF24L01 + module communication, when a communication failure occurs, how to quickly determine if the problem is at the receiving end, rather than a problem sending end of it? Here recommend to his home Method:
First, using the test code provided by the manufacturer, without any changes, burned into two modules, there is no problem if a hardware circuit, generally the normal reception can be transmitted, such as communication can not occur, check the SCM model changes brought about IO port settings are correct, do not tamper with logic code and nRF24L01 + drive part of the code, only to find the IO port configuration of macro definitions can be modified properly.

If this communication can be described hardware module is no problem. Otherwise, the problem in the hardware circuit, the circuit portion carefully check, see the "normal hardware required to receive data protection substantially."

When the code provided by the manufacturer using test may communicate, to burn into their own code as a module of code in the receiving end. Referring burning before receiving some manufacturers test configuration code, changes in your program channel rate, the address, whether the automatic answer, etc., consistent with the test item.

After this adjustment, you still do not, that is your problem with the receiving-side code, see the following several phenomena.

Normal basic security hardware required to receive data

Before commissioning the code must first ensure that the hardware circuit is normal, the following is necessary prerequisite includes:
. 1, the IO interface circuit connected between the microcontroller and the normal module. Code Sequence SPI pin microcontroller circuit configuration matches the actual connection.
2, nRF24L01 + power modules near the foot (the closer the better) with a filter capacitor, preferably two, a 104, a 22uF or more.
3, when in the receive mode, CE pin should be high (high enough, more than 3.1V).
4, the power supply voltage at 3.3V, less than 80mV corrugations, ripples smaller the better.

The above conditions must have, otherwise not receive it more normal.

Phenomenon 1: Less than once also receive data sent by a transmitter

Most of this phenomenon when we first debugging module, then we want to be ruled out in two directions.

To exclude the hardware part above with reference to "normal basic security hardware required to receive data" mentioned one, there is no careful examination can not meet. Based on past experience, the most easily overlooked is that two capacitors near the nRF24L01 + module power supply pin, if you already have, it would try to replace a new set of exclusion element itself is the problem, preferably with capacitance meter or multimeter capacitance file measuring it. However, if there are not close distance module (should be less than the distance 0.5CM), preferably welded directly to a temporary pin on the module, in order to rule out this reason.

CE foot is then measured is 3.3V, if the pull-up capacity is greater than 0V and lower than 3.1V is described below CE level is not normal, check the IO port of the microcontroller. If the microcontroller mode is configurable IO port on the pull mode (e.g., STC microcontroller), with push-pull mode. If the microcontroller is configurable pull mode, pull-up resistor, to meet the CE pin when pulled, to maintain a level above 3.1V.

If the hardware part is no problem, CE feet normal pull, provided that the check code for receiving the focus mode, the following reference code:

/*-----------------------------------------------------------------------------
函数名称:NRF24_RxMode
输入参数:pSelfAddr:本机硬件地址;ch:通信频道
功能描述:设置nRF24L01+工作在接收模式
------------------------------------------------------------------------------*/
void NRF24_RxMode(U8 *pSelfAddr, U8 ch){
    CE = 0;                                                                 // 拉低CE进入配置模式
    nRF24L01P_Write_Buf(WRITE_REG + RX_ADDR_P0, pSelfAddr, TX_ADR_WIDTH);   // 设置接收设备自己的通道0地址
    nRF24L01P_Write_Reg(WRITE_REG + EN_AA, 0x01);                           // 使能接收通道0自动应答
    nRF24L01P_Write_Reg(WRITE_REG + EN_RXADDR, 0x01);                       // 使能接收通道0
    nRF24L01P_Write_Reg(WRITE_REG + RF_CH, ch);                             // 选择射频通道为变量ch
    nRF24L01P_Write_Reg(WRITE_REG + RX_PW_P0, TX_PLOAD_WIDTH);              // 设置接收通道0有效数据宽度
    nRF24L01P_Write_Reg(WRITE_REG + RF_SETUP, RF_date_rate|dBm);            // 设置数据传输率、发射功率      
    nRF24L01P_Write_Reg(WRITE_REG + CONFIG, 0x0f);                          // 使能16位CRC校验,上电,接收模式
    nRF24L01P_Write_Reg(WRITE_REG + STATUS, 0xff);                          // 清除所有的中断标志位
    CE = 1;                                                                 // 拉高CE启动接收设备
}

In the above code, we should pay attention to:
pSelfAddr : receiving end of your hardware device address, to be consistent with the destination address of the sender, otherwise not receive.
CH : RF working channel number, a value of 1-125 may be provided, to be consistent with the sender, or receive.
RF_date_rate : data transmission rate, the value may be set 0x00,0x08,0x20, representing 1Mbds, 2Mbds, 250Kbds, must be consistent provided the transmitting side, otherwise not receive.
dBm : transmit power, there is no practical effect in the receive mode, but can not be greater than the set value 0x07, otherwise affect the configuration of the bit rate.
TX_ADR_WIDTH : Description address width must match the transmitting side, is set to 5 test recommendations.
TX_PLOAD_WIDTH : Description width data transfer, must be consistent with the transmitting side, it is set to 32 when the test is recommended.

Phenomenon 2: You can only receive once when sending end or the receiving end of the re-power

Reason 1: has been sending the same data packet, which is sent each time the data is the same.
nRF24L01 + is a first receiving end PID bit to distinguish whether the same data packet, the PID same as the first, if the second received, it is treated as data retransmission process is not discarded directly, it does not produce successful reception interruptions.
The data sheet says the PID is written every time the transmit FIFO will automatically accumulate, that is, every write once will change once, but many times in experiments (using SI24R1 module), found that if the two written is the same content, the PID does not change, the same receiving terminal directly discard data received later.
This gives rise to only receive is successful, then not receive this phenomenon. After re-power, all registers are reconfigured before the PID is not the same, so we can once again receive, then they would not be received.
Solution: In the selected data content you send a byte every time it is changed, it will not appear.

2 reason, the transmitting side continuously transmits faster, slower receiver-side processing is not clear cut receive FIFO.
After the transmitting end continuously transmits three data, the receiving end 96 byte buffer fills up, if this time has not been read, it will not be received. The transmitting end is still transmitted at the same rate and then some, although at this time the receiving end reads out a set of 32 bytes, if the process is relatively slow, and that the receive buffer may be quickly and filled.
When the receiving end has been processed go check logic code to receive data, such as the middle through mode conversion, clears the interrupt flag, because there is no longer produced successful reception interrupt flag (IRQ interrupt is first determined using the successful reception, the receiving buffer is full will no longer interrupt a), it is considered not received the data, so they no longer receive the data.
This gives rise to only receive once you receive this phenomenon, after power, all the registers are reconfigured, interrupt and buffers are cleared, so I can no longer receive.
Solution: After the data each time it receives the readout, after the completion of the processing logic, if after receiving the transmission mode conversion, the converted clear at the receive FIFO.

Cause 3, did not clear the interrupt flag, once after receiving the IRQ has been maintained at a low level.
If the MCU external interrupt, an interrupt is received once valid data is not clear the interrupt flag, then receive valid data will no longer generate the next.
Solution: receive is successful, clearing an interrupt.
SCM whether it has received the following code data by identifying ways IRQ query, combined with the interruption query in two ways:

/*-----------------------------------------------------------------------------
函数名称:RF24_RxData
返回数据:是否收到数据,1收到,0未收到
功能描述:nRF24L01P+判断是否收到数据,若收到直接取出,应在主循环中调用
------------------------------------------------------------------------------*/
bit RF24_RxData(){
    U8 state;

    if(IRQ == 0){                                                       //有中断触发,提高CPU效率,减少SPI通讯量
        state = nRF24L01P_Read_Reg(STATUS);                             //读取状态寄存器的值       
        nRF24L01P_Write_Reg(WR_STATUS, state);                          //清除RX_DS中断标志
        if(state & RX_DR)                                               //接收到数据
        {
            nRF24L01P_Read_Buf(RD_RX_PLOAD, RF24Buf, TX_PLOAD_WIDTH);   //读取数据
            nRF24L01P_Write_Reg(FLUSH_RX,0xFF);                         //清除RX FIFO寄存器
            return TRUE; 
        }
    }                                                                   
    return FALSE;                                                       //没收到任何数据
}

Note that the code above the "Clear RX_DS interrupt flag" effect and "Clear RX FIFO register" to ensure that each set when received, can make a new start receiving nRF24L01 +.

Phenomenon 3: occasionally sending the data into receive mode after not receiving a

1 reason, after the failure of transmission, transmit FIFO register is not cleared, causing abnormal reception mode rpm.
nRF24L01 + when sending the maximum number of transmissions still have not received an ACK (ACK is enabled), is not automatically clear the transmit buffer. In the transmission mode to the standby mode when the state diagram of the manual, must be a case where no data transmit buffer, CE = 0 before entering the standby mode. In the standby mode, it can be set to receive mode. However, the data sheet describes the part of the text added in any state, as long as CE = 0 can enter standby mode, there has been described contradiction.
When we debug, I encountered this problem, after many experiments N, in the case of the transmit buffer as well as data directly to the receiving mode is unstable, so in the end to send, if the number of transmissions is reached the maximum no longer continue to send, you must remember to clean TX_FIFO.
Solution: after sending the transmission status is determined, if the maximum transmission number is reached, the cleaning TX_FIFO.
Reference code is as follows:

/*-----------------------------------------------------------------------------
函数名称:RF24_TxData
输入参数:*buf:待发送的数据缓冲区指针
返回数据:是否发送成功,1发送成功,0发送失败
功能描述:nRF24L01P+发送数据
------------------------------------------------------------------------------*/
bit RF24_TxData(U8 *buf){
    U8 state;

    CE = 0;                                                 //使能24L01配置
    nRF24L01P_Write_Buf(WR_TX_PLOAD, buf, TX_PLOAD_WIDTH);  //写数据到TX FIFO,32个字节
    CE = 1;                                                 //使能发送     

    while(IRQ == 1);                                        //等待发送完成
    state=nRF24L01P_Read_Reg(STATUS);                       //读取状态寄存器的值    
    nRF24L01P_Write_Reg(WR_STATUS, state);                  //清除TX_DS或MAX_RT中断标志
    if(state&MAX_RT)
        nRF24L01P_Write_Reg(FLUSH_TX, 0xff);                //达到最大发送次数,清除TX FIFO寄存器
    if(state&TX_DS)
        return TRUE;                                        //发送完成  
    return FALSE;                                           //发送失败
}

2 reason, in sending the code logic is automatically converted to a receiving mode, when the transmission cycle, and receive three or more intermediate data.
Because sending a set of data will be automatically set to receive (write logic is also good to avoid certain places forget to reception), that before sending the next set of data, there is a time interval, this If the data come in time, it is acceptable. But the upper code does not process the received data, that is not read, but sending the cycle will enter the stage to receive treatment. If such data by three times during the cycle to send, receive buffer on the full, but also generate interrupt every conversion mode when they are being cleared. And other end of the cycle, and then determine whether the data is received when due to receive buffer is full and can no longer receive interrupt, so can not receive the data.
Solution: In each set the receive mode when the wash RX_FIFO.

3 reason, the code is not set to receive mode operation all registers, other codes associated registers changed.
Prior to the present reception mode, other codes may be changed relative to a reception register, causing the transmitting end to change inconsistent or incorrect values, resulting in not normally received.
Solution: set as a function of reception mode, again related to the operation complete register, which can avoid this problem.

Phenomenon 4: Module working for some time with a high-power PA can not be received

After testing a number of manufacturers nRF24L01 + variety of different modules, and discovery module with the shield band power amplification, during close-intensive applications, a relatively high failure rate. PA is first received and then an abnormal overheating, increase the current receive mode, the surface temperature will be hot.
Energizer is recommended not to use with the PA, if necessary use, not intensive applications, not to make use of on-board antenna with the shield.
This is the practical application of the test experience, does not mean that all this does not rule out some manufacturers with a better shield.

5 phenomenon: not receive occasional irregular

The above problems are ruled out, then, if you still can not receive the occasional situation occurs, it would focus on checking power supply and filter capacitor is recommended to replace a power supply, ensure the stability of low ripple power supply voltage is better. Better quality of the filter capacitor, as close as possible to the module, the closer the better.

Frequently Asked Questions About nRF24L01 + as the receiving end of the first share here, other aspects in addition to share.

Guess you like

Origin www.cnblogs.com/xueweisuoyong/p/11084536.html