Go Down

Topic: NRF24L01+ and arduino mini pro- radio.write()-fails (Read 552 times) previous topic - next topic

dosilyoun

Hi,

I am doing a simple project, where two arduino mini pro (3.3V version) communicating each other via NRF24L01+s.

I am using the basic Getting Started example project from TMh20 (without modifications). The NRF chip version is NRF-8PA-LNA.  As a power supply, i am using an external regulator with LC filtering. The Arduino and NRF are supplied by 3.3V.  I checked the connections many times.

The problem is the project get into an ifinite loop at : radio.write function.
After a little debugging, i found the write funtion in the library of TMh20.

This is the write function:
Code: [Select]
bool RF24::write( const void* buf, uint8_t len, const bool multicast )
{
//Start Writing
startFastWrite(buf,len,multicast);

//Wait until complete or failed
#if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
uint32_t timer = millis();
#endif

while( ! ( get_status()  & ( _BV(TX_DS) | _BV(MAX_RT) ))) {
#if defined (FAILURE_HANDLING) || defined (RF24_LINUX)
if(millis() - timer > 95){
errNotify();
#if defined (FAILURE_HANDLING)
  return 0;
#else
  delay(100);
#endif
}
#endif
}
   
ce(LOW);

uint8_t status = write_register(NRF_STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );

  //Max retries exceeded
  if( status & _BV(MAX_RT)){
  flush_tx(); //Only going to be 1 packet int the FIFO at a time using this method, so just flush
  return 0;
  }
//TX OK 1 or 0
  return 1;
}


This is the loop where stuck:
Code: [Select]
while( ! ( get_status()  & ( _BV(TX_DS) | _BV(MAX_RT) )))

because the get_status() returning with the value 14 but the TX_DS and MAX_RT  are still zero, so the while loop never ends.

I am really helpless because I read many tutorials and forums but nothing helped. Any idea what can be wrong?

Thanks in advance.

Robin2

The NRF chip version is NRF-8PA-LNA. 
That seems strange. Are you using a Nordic chip and building your own circuit board or are you using a regular nR24L01+ module?

In either case please post a link to the datasheet so there is no confusion.

The examples in this Simple nRF24L01+ Tutorial work with the regular modules. I have deliberately made the code as simple as possible.

Wireless problems can be very difficult to debug so get the wireless part working on its own before you start adding any other features.

And if you want help with your own code you must post the complete programs for the two Arduinos. However it will be easier to help if you use the code in my Tutorial as I am familiar with it.

...R

Two or three hours spent thinking and reading documentation solves most programming problems.

dosilyoun

#2
Apr 28, 2018, 05:31 pm Last Edit: Apr 28, 2018, 05:36 pm by dosilyoun
I am using the tutorial what you mentioned.
First, used the CheckConnection.ino
Code: [Select]


// 18 Mar 2018 - simple program to verify connection between Arduino
//      and nRF24L01+
//  This program does NOT attempt any communication with another nRF24

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#include <printf.h>

#define CE_PIN   9
#define CSN_PIN 10

const byte thisSlaveAddress[5] = {'R','x','A','A','A'};

RF24 radio(CE_PIN, CSN_PIN);

char dataReceived[10]; // this must match dataToSend in the TX
bool newData = false;


void setup() {
    Serial.begin(9600);
    printf_begin();

    Serial.println("CheckConnection Starting");
    Serial.println();
    Serial.println("FIRST WITH THE DEFAULT ADDRESSES after power on");
    Serial.println("  Note that RF24 does NOT reset when Arduino resets - only when power is removed");
    Serial.println("  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not");
    Serial.println("     communicating with the nRF24");
    Serial.println();
    radio.begin();
    radio.printDetails();
    Serial.println();
    Serial.println();
    Serial.println("AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1");
    Serial.println(" and 250KBPS data rate");
    Serial.println();
    radio.openReadingPipe(1, thisSlaveAddress);
    radio.setDataRate( RF24_250KBPS );
    radio.printDetails();
    Serial.println();
    Serial.println();
}


void loop() {

}



I got this:
Code: [Select]
CheckConnection Starting

FIRST WITH THE DEFAULT ADDRESSES after power on
  Note that RF24 does NOT reset when Arduino resets - only when power is removed
  If the numbers are mostly 0x00 or 0xff it means that the Arduino is not
     communicating with the nRF24

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xe7e7e7e7e7 0xc2c2c2c2c2
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xe7e7e7e7e7
RX_PW_P0-6 = 0x00 0x00 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x07
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 1MBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX


AND NOW WITH ADDRESS AAAxR  0x41 41 41 78 52   ON P1
 and 250KBPS data rate

STATUS = 0x0e RX_DR=0 TX_DS=0 MAX_RT=0 RX_P_NO=7 TX_FULL=0
RX_ADDR_P0-1 = 0xe7e7e7e7e7 0x4141417852
RX_ADDR_P2-5 = 0xc3 0xc4 0xc5 0xc6
TX_ADDR = 0xe7e7e7e7e7
RX_PW_P0-6 = 0x00 0x20 0x00 0x00 0x00 0x00
EN_AA = 0x3f
EN_RXADDR = 0x03
RF_CH = 0x4c
RF_SETUP = 0x27
CONFIG = 0x0e
DYNPD/FEATURE = 0x00 0x00
Data Rate = 250KBPS
Model = nRF24L01+
CRC Length = 16 bits
PA Power = PA_MAX



Then i used SimpleTx.ino program with 2 plus serial comment in the send function:
Code: [Select]

// SimpleTx - the master or the transmitter

#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>


#define CE_PIN   9
#define CSN_PIN 10

const byte slaveAddress[5] = {'R','x','A','A','A'};


RF24 radio(CE_PIN, CSN_PIN); // Create a Radio

char dataToSend[10] = "Message 0";
char txNum = '0';


unsigned long currentMillis;
unsigned long prevMillis;
unsigned long txIntervalMillis = 1000; // send once per second


void setup() {

    Serial.begin(9600);

    Serial.println("SimpleTx Starting");

    radio.begin();
    radio.setDataRate( RF24_250KBPS );
    radio.setRetries(3,5); // delay, count
    radio.openWritingPipe(slaveAddress);
}

//====================

void loop() {
    currentMillis = millis();
    if (currentMillis - prevMillis >= txIntervalMillis) {
        send();
        prevMillis = millis();
    }
}

//====================

void send() {

    bool rslt;
     Serial.println("Before the write funtcion");
    rslt = radio.write( &dataToSend, sizeof(dataToSend) );
        // Always use sizeof() as it gives the size as the number of bytes.
        // For example if dataToSend was an int sizeof() would correctly return 2
    Serial.println("After the write funtcion");
    Serial.print("Data Sent ");
    Serial.print(dataToSend);
    if (rslt) {
        Serial.println("  Acknowledge received");
        updateMessage();
    }
    else {
        Serial.println("  Tx failed");
    }
}

//================

void updateMessage() {
        // so you can see that new data is being sent
    txNum += 1;
    if (txNum > '9') {
        txNum = '0';
    }
    dataToSend[8] = txNum;
}


And this is the result:
Code: [Select]
SimpleTx Starting
Before the write funtcion


Stuck again at write function.

Thanks for the help.


And this is nrf verion i am using:
https://www.hestore.hu/prod_getfile.php?id=8194
https://www.hestore.hu/prod_10035524.html?lang=en

Robin2

I have not come across that problem before.

How are you powering your nRF24? Your link is for a high-power version with the external antenna.

Make a simple pencil drawing showing how you have everything connected and post a photo of the drawing. See this  Simple Image Guide

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

dosilyoun

#4
Apr 29, 2018, 11:40 am Last Edit: Apr 29, 2018, 11:41 am by dosilyoun
Connection:

Robin2

I don't see anything wrong with your wiring - but I do often miss things.

Am I correct to think that you seem to be able to communicate between the Pro-Mini and the nRF24 when you are not trying to send anything?  But when you try to send data the system hangs?

Is that behaviour the same for both Pro-Minis?

If not, have you tried swapping them so that the one that is misbehaving is receiving rather than transmitting? (Just to see if it makes a difference).

I don't know if it would make any difference but are you sure you are compiling your code for an 8MHz pro-mini.

What happens if you power the nRF24 from a pair of new AA alkaline cells (3v) with a common GND to the Pro Mini?

How many nRF24s do you have? It is always useful to have some spares that you can use to check for a faulty device.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Go Up