nrf24l01 retransmission issue

Hello!
I have a problem with nrf24l01 modules. It seems that the PTX device doesn’t recognise ACKs from PRX device in enchanced shockburst mode.

I’m stuggling with that issue for days and I’m becoming pissed off because I’m making a drone but can’t get it to work cause of these modules… I’ve wasted so much time.

I can receive first packet but then PTX is locked until I reset both PRX and PTX devices. PTX device is behaving like PRX device is not sending any ACKs, but I know for sure that it is. I used HackRF to get the RF signal. It’s clearly visible that after each PTX transmission there’s a ACK packet from PRX.(shown in signal1.jpg and signal2.jpg)

First I thought that there’s something with data rate(I’m using 1Mbps),because I saw that ACK is smaller then packet from PTX, so I’ve changed it to 2Mbps, but it seems that it’s correct.(signal3.jpg)

I’m using PIC24 as PTX(drone will be based on PIC chip) and arduino as PRX.

First I wanted to write my own library but I had same issue so I thought that I made mistake somewhere and I’m using now this library: pic-libraries/nrf24l01.c at master · simonbarker/pic-libraries · GitHub

To get the register values from PTX(PIC) before and after transmission I’m using Serial3.

So this is Arduino(PRX) code(pin 10 is interrupt pin):

#include "nrf24l01.h"


bool RX_buffer_empty;




void setup()
{
 pinMode(CSN , OUTPUT);
 pinMode(CE, OUTPUT);
 pinMode(4, OUTPUT);
 pinMode(10, INPUT);
 digitalWrite(4, LOW);

 digitalWrite(CE, LOW);
 digitalWrite(CSN, HIGH);
 Serial3.begin(115200);
 Serial.begin(256000);
 SPI.begin();
 SPI.setBitOrder(MSBFIRST);
 SPI.setDataMode(SPI_MODE0);
 RX_buffer_empty = 1;
 unsigned char config = (nrf24l01_CONFIG_PWR_UP |
 nrf24l01_CONFIG_CRCO | nrf24l01_CONFIG_EN_CRC | nrf24l01_CONFIG_PRIM_RX);

 nrf24l01_initialize(config, 1, nrf24l01_EN_AA_ENAA_P0 | nrf24l01_EN_AA_ENAA_P1, nrf24l01_EN_RXADDR_ERX_ALL, nrf24l01_SETUP_AW_5BYTES, 0b01000010, 3,
 nrf24l01_RF_SETUP_RF_PWR_12 , NULL, NULL, NULL, NULL, NULL, NULL, NULL, 32, 32, 32, 32, 32, 32);
 nrf24l01_cd_active();
 nrf24l01_set_as_rx(1);
 nrf24l01_set_ce();

}


void loop()
{
 if (Serial.available() > 0)
 {
 if (readchar == 'm')
 {
 
 unsigned char dat[35];

 nrf24l01_get_all_registers(dat);

 for (int i = 0; i < 35; i++)
 {
 Serial.println(dat[i]);
 }

 Serial.print("FIFO_STATUS: ");
 Serial.println(nrf24l01_get_fifo_status());
 
 }
 
 }
 
 

if (digitalRead(10) == 0)
 {
 
 unsigned char dat[255];
 nrf24l01_read_rx_payload(dat, 32); //read the packet into data 
 
 for (int i = 0; i < 255; i++)
 {
 Serial.print(dat[i]);
 }
 Serial.println(nrf24l01_IRQ_IOREGISTER);
 nrf24l01_irq_clear_all();
 nrf24l01_rx_standby_to_active();
 
 }

 if(Serial3.available()>0)
 {
 Serial.println(Serial3.read());
 }
}

NOW registers values(sorry for that hard to read format, it’s registers from 0x0 to 0x17 adressed, but if any register value is higher than one byte it’s shown in new line so for example
231
231
231
231
231

is RX_0 pipe address 0xe7e7e7e7e7

PRX registers after configuration:

15
3
63
3
66
3
2
14
0
0
231
231
231
231
231
194
194
194
194
194
0
0
0
0
231
231
231
231
231
32
32
32
32
32
32
FIFO_STATUS: 17

PRX registers during data receiving (IRQ becoming active):

14
63
63
3
118
3
15
3
63
3
66
3
2
64
0
0
231
231
231
231
231
194
194
194
194
194
0
0
0
0
231
231
231
231
231
32
32
32
32
32
32
FIFO_STATUS: 16
8081828384858687888990919293949596979899100101102103104105106107108109110111
15
3
63
3
66
3
2
78
0
0
231
231
231
231
231
194
194
194
194
194
0
0
0
0
231
231
231
231
231
32
32
32
32
32
32
FIFO_STATUS: 17

It’s even visible here that the PRX entered TX mode (CONFIG=14)

Now PTX PIC code:

#include "mcc_generated_files/system.h"

#include "motors.h"
#include "mcc_generated_files/oc1.h"
#include "mcc_generated_files/oc2.h"
#include "mcc_generated_files/uart1.h"


#include "nrf24l01.h"
#include <libpic30.h>

#include "LEDS.h"
#include "nrf24l01_macros.h"


bool RX_buffer_empty;
uint8_t RX_buffer[255];

unsigned char data[255];


unsigned char RX_P0_addr[5];

int main(void)
{
    // initialize the device
    SYSTEM_Initialize();
    Motors_Initialize();
    TRISCbits.TRISC2=1;
    OC1_SecondaryValueSet(0x0);
    OC2_SecondaryValueSet(0x0);
    OC3_SecondaryValueSet(0x0);
    OC4_SecondaryValueSet(0x0);
    DelayUS(1000);
    
    unsigned char config= (nrf24l01_CONFIG_PRIM_RX | nrf24l01_CONFIG_PWR_UP | 
    nrf24l01_CONFIG_CRCO | nrf24l01_CONFIG_EN_CRC) ;
    nrf24l01_initialize(config,1,nrf24l01_EN_AA_ENAA_ALL,nrf24l01_EN_RXADDR_ERX_ALL,nrf24l01_SETUP_AW_5BYTES,0b01110110,3,
            nrf24l01_RF_SETUP_RF_PWR_18,NULL,NULL,NULL,NULL,NULL,NULL,NULL,32,32,32,32,32,32);
    
    nrf24l01_set_as_tx();
    DelayMS(6000);

while (1)
    {
        int i;
        unsigned char da[32];
        unsigned char a=0x50;
        for(i=0;i<32;i++){
            da[i]=a;
            a++;
        }
        unsigned char regs[35];
        if(nrf24l01_irq_pin_active()==true){
        UART1_Write(1);
        }
        else{
            UART1_Write(0);
        }
        nrf24l01_get_all_registers(regs);
        UART1_WriteBuffer(regs,35);
        nrf24l01_write_tx_payload(da, 32, true);
        DelayMS(1000);
        nrf24l01_get_all_registers(regs);
        UART1_WriteBuffer(regs,35);
        DelayUS(2000);
        if(nrf24l01_irq_pin_active()==true){
        UART1_Write(1);
        }
        else{
            UART1_Write(0);
        }
        
       while(!nrf24l01_irq_tx_ds_active() || !nrf24l01_irq_max_rt_active()); 
       nrf24l01_flush_tx();
              nrf24l01_flush_rx();

       nrf24l01_irq_clear_all();
}
}

Don’t bother with those IRQ’s while it was for testing as you will see in registers values the COUNT LOST packets in OBSERVE_TX register(0x8) becomes 1. (whole register value is 22)

And the registers:

PTX before transmitting:

IRQ PIN->>>>>0
14
63
63
3
118
3
0
14
0
0
231
231
231
231
231
194
194
194
194
194
0
0
0
0
231
231
231
231
231
32
32
32
32
32
32

PTX after transmitting:

14
63
63
3
118
3
0
30
22
0
231
231
231
231
231
194
194
194
194
194
0
0
0
0
231
231
231
231
231
32
32
32
32
32
32
IRQ PIN--->>>1

Have a look at this Simple nRF24L01+ Tutorial.

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

The examples are as simple as I could make them and they have worked for other Forum members. If you get stuck it will be easier to help with code that I am familiar with. Start by getting the first example to work

...R

I can't use this library because PIC doesn't support C++ (RF24 library uses classes)

kamilkarp: I can't use this library because PIC doesn't support C++ (RF24 library uses classes)

Why are you asking a question about PIC programming on the Arduino Forum? Arduinos don't use PIC microprocessors.

...R

Thought maybe it's something on the RX side, for RX I'm using Arduino. Thought when I paste the code here and registers values maybe someone would catch an error I made.

There is no reason not to use the TMRh20 library on the Arduino. The only purpose of the library is to make a convenient interface to the nRF24 module. Once the data gets to the nRF24 it won't matter how it got there.

You need to ensure that the settings for the receiving module match those of the transmitting module.

...R

Ok, I think that I know what is happening. I think that the device that can’t ACK is mulfunctioning. I’ve used that library what you mentioned.
First I set everything as before using this library. Same thing happened. I could receive first packet but nothing else until reset. At RF signal I’ve been seeing same thing: ACKs weren’t being recognised.

So I’ve decided to set that device as PTX and trying to send the same packet. Now I couldn’t receive it.

RF signal shows the same packet being transmited. Upper side with device I could receive packed and the lower one which I can’t. It’s clearly visible that these signals are different.
I think that the mulfuncioning device has TX side damaged. It seems that it can’t modulate the signal. Looks like it’s sending just the carrier.

I’ll buy new module and will tell in few days if it was the case.

Ehh so much time wasted…