1

I'm struggling to establish a link between two Arduino Nano using nRF24L01 (the module that contains PA and LNA). I assume I made a coding mistake (May be in the setup method?), and I need help in finding it. I’m using the gettingStarted example from the TMRh20 V1.4.1 RF24 library, with slight modifications in the addressing and error messaging. The sketch contains the code for both the transmitter and the receiver, and the selection is done by the ROLE flag in compile time.

Hardware:

  1. I'm using home-designed PCB. For this setup only the Arduino and RF24 modules are assembled.
  2. Power: a. The RF24 is fed by the 3.3V output of the Arduino. b. There is a 47uF cap to filter the power. c. The power traces length is about 20mm, and 1.2 mm thick of 1oz copper.
  3. Measurements a. The setup method verifies that the RF24 module is connected to the SPI bus and reacts to the commands. I verified this test by removing and inserting a module. It works. b. When the transmitter was running at repetition rate of 1 cycle per second, I used an oscilloscope to measure on the power line of the RF24 module a ripple of 50mV over DC level of 3.25V (per the data sheet the minimum supply voltage is 1.9V).
  4. The setup method verifies explicitly that the RF24 module is connected to the SPI bus and reacts to the commands.

Debugging:

  1. To begin with, the message ** “Transmission failed or timed out” ** was issued.
  2. When I added the line “radio.setAutoAck(false)” to the setup method, the error message was changed into ** “Transmission succeeded; retransmission failed” **. This is odd because I had to explicitly specify a mode that the chip should be in by default.
  3. I replaced both module in both sides to brand new units, to no avail.
  4. I added to the library’s ** write ** function a print of the status register. It reflects transmission success (see below).

Currently the transmitter messages are as follows (the line numbers were added for the notes): 1 Start loop - TX station 2 WRITE TP 3 - TX OK: status=2E 3 Time to transmit = 960 us. 4 Transmission succeeded; transmitted: 0.08 5 Back transmission failed

Notes:

  1. Lines 1, 3, 4 and 5 are issued by the main loop.
  2. Line 2 is the WRITE printout. a. Bit 5 of the status is the TX_DS flag, which signify that the TX FIFO status. Active means that the packet was transmitted successfully. b. Bits 3:1 mean that RX FIFO is empty.
  3. Line 4 – printout of the transmitted payload. The number is increased in every loop by 0.01.
  4. Lines 5 tells us that the nothing was received from the other side (the receiver reports that he received nothing).

My problem is that either the transmitter doesn't transmit (low probability) or there is a mismatch between the stations. I assume I made a coding mistake (May be in the setup method?), and I’d appreciate any help in finding it.

Or, should I add voltage regulator to increase the 3.25V to 3.3V?

    #include <SPI.h>
#include "RF24.h"
// instantiate an object for the nRF24L01 transceiver
RF24 radio(9, 10);           // using pin 9 for CE, pin 10 for CSN
uint32_t address[2] = {0x123456, 0x654321};
byte role = 1;
float payload = 0.0;
uint16_t counter = 0;
int terminationTimer;
/***********************************************************/
void setup() 
{
  Serial.begin(9600);
  while (!Serial) ; 
  Serial.println("Starting...");

// initialize the transceiver on the SPI bus
  radio.begin();                            
// Modification - the installed library doesn't 
// return flag. Instead, check the SPI bus by 
// changing register contents
  radio.setPALevel(RF24_PA_HIGH);        // RF24_PA_MAX is default.
  bool paError = !radio.isChipConnected() | (radio.getPALevel() != RF24_PA_HIGH);
  radio.setPALevel(RF24_PA_MIN);
  paError |= (radio.getPALevel() != RF24_PA_MIN);
  if(paError)
  {
    Serial.println("Radio HW error");
    while (true) ;                // Halt
  }
  Serial.print("radio role = ");
  Serial.println(role);
  radio.setRetries(15,15);
  radio.setAutoAck(false);

  if(role == 1)
  {
    radio.openWritingPipe(address[1]);    // always uses pipe 0
    radio.openReadingPipe(1, address[0]); // pipe 1 for
    radio.stopListening();                // put radio in TX mode
  }
  else
  {
    radio.openWritingPipe(address[0]);    // always uses pipe 0
    radio.openReadingPipe(1, address[1]); // using pipe 1
    radio.startListening();               // put radio in RX mode
  }
  terminationTimer = millis();
//Serial.println("TP C");
} // setup
/****************************************************************/
void loop() 
{
//Serial.println("TP D - start loop; role = " + String(role));
//delay(1000);
  if (role == 1) 
  {
Serial.println("\nStart loop - TX station");
 // This device is a TX node
    unsigned long start_timer = micros();            // start the timer
    bool report = radio.write(&payload, sizeof(float)); // transmit & save the result
    uint32_t end_timer = micros();              // end the timer
    if (report) 
    {
// All the code in this block is designed for testing only
      Serial.print(("Time to transmit = "));
      Serial.print(end_timer - start_timer); // print the timer 
      Serial.println((" us."));
      radio.startListening();               // put radio in RX mode
      Serial.print("Transmission succeeded; transmitted: ");
      Serial.println(String(payload));
      Serial.print("Back transmission ");
      int tDelay = millis();
      while(((millis() - tDelay) < 250) && !radio.available()){}
      if(radio.available())
      {
        float pl;
        radio.read(&pl, sizeof(float));  // fetch payload from FIFO
        Serial.print("succeeded. Retransmitted: ");
        Serial.println(pl);
      }
      else
        Serial.println("failed");
      radio.stopListening();             // put radio in TX mode
      payload += 0.01;                   // increment float payload
    } 
    else Serial.println(("Transmission failed or timed out")); // payload was not delivered
// to make this example readable in the serial monitor
    delay(1000);  // slow transmissions down to 1 per second
  } 
  else 
  {
Serial.println("\nStart loop - RX station");
// This device is a RX node
    uint8_t pipe = 0;
    if (radio.available(/*&pipe*/))   // is there a payload? get the pipe number that recieved it
    {
      uint8_t bytes;
      bytes = sizeof(float);         // get the size of the payload
      radio.read(&payload, bytes);   // fetch payload from FIFO
// The rest of the code in this block is for debugging
      radio.stopListening();          // put radio in TX mode
      delay(10);
      Serial.print("Received ");
      Serial.print(bytes);          // print the size of the payload
      Serial.print((" bytes on pipe "));
      Serial.print(pipe);             // print the pipe number
      Serial.print((": "));
      Serial.print(payload);
      if(radio.write(&payload, bytes))
        Serial.print("; back transmission succeeded.");
      else
        Serial.println("; back transmission failed");
      radio.startListening();          // put radio in RX mode
    }
    else 
    {
      Serial.println("no receive");
      delay(700);
    }
  } // role
/*
  if((millis() - terminationTimer) > 10000)
  {
    Serial.println(("Halt"));
      while(true){}
  }
*/
} // loop
1
  • I gave up and switched to ESP32 Commented Sep 4, 2021 at 7:02

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.