I found the problem occurs because the transmitter is expecting acknowledgment from the receiver which is getting lost somehow, while transmission and the transmitter still waits for ack for the last transmitted data (which it never gets) so it keeps on transmitting the last packet again and again. I saw on forums that its because of the TX buffer getting full after 3 retries or something. I don't exactly know why it happens.
I first tried resetting just the transmitter through code but it was not enough (as already mentioned in the question). So I now reset both the TX and RX using the below code. I have a separate 1 byte reset-counter in the first byte of the array (you may use a single byte variable) which acts as an id for the packet (you may use the internal PID as well).
The below code resets the TX if transmission fails by checking the return value of
write function and resets the RX when it receives the same ack or packet (with the same reset-counter value) more than 2 times (I use a condition to check if the last counter value is different from the current one or not). To reset it using code I use the below algorithm :
- Power Down the NRF using
- Re-initialize the nrf for the MCU.
- Power Up the NRF using
Note: I am using TMRH20 RF24 Library.
if ( myRadio1.write( &dataTransmitted, sizeof(dataTransmitted)))
\\Serial.println(" 1 Tx1 problem end");
myRadio2.read( &dataReceived, sizeof(dataReceived));
myRadio2.writeAckPayload(1, &ack2, sizeof(ack2));
if (prevack2 == dataReceived)
\\Serial.println("RX 2 problem");
prevack2 = dataReceived;
if (c2 > 2)
c2 = 0;