Nrf24l01 making loop consume more time

Hi there,

I'm using two NRFs (TX and RX), when the RX is disconnected the loop function on the TX take nearly 50ms to complete.
When the RX is powered and get connected to TX, the loop function takes only 2.5 ms.
I'm going to go crazy about this, and i can't find the answer.
autoACK, dynamic payload and ACKpayload are all enabled.

Radio setup code:

void setupRadio() {
  radio.setDataRate(RF24_250KBPS);  // The lowest data rate value for more stable communication
  radio.setPALevel(RF24_PA_MIN);  // Output power is set for maximum while unbinding
  radio.openWritingPipe(pipeOut);
  radio.setAutoAck(true);
  radio.enableDynamicPayloads();
  radio.enableAckPayload();
  radio.stopListening();  // Start the radio comunication for Transmitter
  radio.powerUp();
}

Radio transmit code:

void transmitRadio() {
  if (radio.write(&txArray, sizeof(TxData))) {
    if (!rxConnected ) {
      rxConnected = true;
    }
    if (radio.isAckPayloadAvailable()) {
      radio.read(&payload, sizeof(struct ackPayload));  //read the payload, if available
    } else {
      noAckCount++;
    }
  } else {
    if (rxConnected && millis() - t2 > 2000) {
      rxConnected = false;
    }
  }
}

Main Loop Function:

void loop() {
  t1 = micros();
  readButtonsOne();
  readButtonsTwo();
  transmitRadio();
  if (displayOpen) {
    drawOLED();
  }
  t2 = micros();
  Serial.println(t2 - t1);
}

Any help is appreciated.

Do you remember from 5 months ago that you cannot get help unless your show the complete code for both Arduino setups? Are you putting in serial.Print() messages to track the program execution and see what is taking the extra time? That will be the first thing people trying to help will ask you to do. It's called "debugging".

1 Like

The transmitter waits for an ACK from the receiver. If it times out without receiving one it retries. Eventually it gives up. In your case this is apparently about 50 ms. See section 7 of the data sheet.

1 Like

I think I see a problem in how you have it wired but without a schematic I cannot be sure. Post an annotated schematic that shows exactly how you have wired it. Be sure to show all power, ground connections, power sources as well as anything else connected. Note any leads over 10"/25 cm in length. `

Yes I did the debugging and found that the piece of code causing this issue was the transmitRadio() function, and that's why I didn't post the full code plus it is more than 1000 line of code (RX is excluded).

Thanks,,,

I thought about that, and tried different setups and NRFs modules with different antennas, but no luck in this.

Thanks,,,

Thanks oldcurmudgeon

that was the issue, after making setRetries to (0,0) the problem solved.

setRetries has a default value of (5*250 us,15 tries) which was taking two much time waiting for acknowledge packet as you said.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.