nRF24L01 not receiving data

Hi guys, this is my first post on this forum.

The problem I’m facing with nRF24L01 is that once configured as receiver, it does detect the packet in air (the bit in the carrier detect register sets accordingly.) But the Receiver FIFO Buffer is still empty! And the Rx_DR interrupt is also not set. I’m not able to understand why the packet is not being accepted into the buffer.I’m trying to send a 1 byte data from Tx to Rx.

Rf channel, data rate is same for both the transmitter and the receiver.

Any help would be appreciated!

:smiley:

Code?

Here is my code (in Mikrobasic) for the transmitter:


program Mikromedia_Transmit

'===============================================================================

dim TFT_DataPort as byte at LATE

TFT_RST as sbit at LATC1_bit

TFT_BLED as sbit at LATD2_bit

TFT_RS as sbit at LATB15_bit

TFT_CS as sbit at LATF12_bit

TFT_RD as sbit at LATD5_bit

TFT_WR as sbit at LATD4_bit

TFT_DataPort_Direction as byte at TRISE

TFT_RST_Direction as sbit at TRISC1_bit

TFT_BLED_Direction as sbit at TRISD2_bit

TFT_RS_Direction as sbit at TRISB15_bit

TFT_CS_Direction as sbit at TRISF12_bit

TFT_RD_Direction as sbit at TRISD5_bit

TFT_WR_Direction as sbit at TRISD4_bit

'SPI

dim nRF_CS as sbit at LATA6_bit

nRF_CS_Direction as sbit at TRISA6_bit

nRF_CE as sbit at LATA5_bit

nRF_CE_Direction as sbit at TRISA5_bit

nrf_irq as sbit at late9_bit

nRF_IRQ_Direction as sbit at TRISE9_bit

nrf_SCK_Direction as sbit at TRISG6_bit

nrf_MOSI as sbit at LATG8_bit

nrf_MOSI_Direction as sbit at TRISG8_bit

nrf_MISO as sbit at LATG7_bit

nrf_MISO_Direction as sbit at TRISG7_bit

read_value , byte1 , status ,status1 , result ,

config , setup_retr , rf_ch , rf_setup ,

fifo_status, setup_aw , detected , en_aa as byte

dim txt as string[3]

'===============================================================================

sub procedure PMPWaitBusy()

while(PMMODE.BUSY = 1)wend

end sub

sub procedure Set_Index(dim index as byte)

TFT_RS = 0

PMDIN = index

PMPWaitBusy()

end sub

sub procedure Write_Command(dim cmd as byte)

TFT_RS = 1

PMDIN = cmd

PMPWaitBusy()

end sub

sub procedure Write_Data(dim _data as word)

TFT_RS = 1

PMDIN = _data

PMPWaitBusy()

end sub

'===============================================================================

sub procedure Init_TFT()

PMMODE = 0x0604 ’ 16 bit mode

PMCON = 0x8300

TFT_Set_Default_Mode()

TFT_Set_Active(@Set_Index, @Write_Command, @Write_Data)

TFT_Init(320, 240)

Delay_ms(1000)

end sub

'====================================================================

sub procedure Init_RF()

spi2_init()

’ Initialize I/O ports

nRF_CS_Direction = 0

nRF_CE_Direction = 0

nRF_IRQ_Direction = 1

nRF_SCK_Direction = 0

nrf_MOSI_Direction = 0

nrf_MISO_Direction = 1

’ Set inital state for mRF connections

nRF_CE = 0

nRF_CS = 1

end sub

'===============================================================================

sub procedure Welcome()

TFT_Fill_Screen(CL_black)

TFT_Set_Pen(CL_white, 1)

TFT_Set_Font(@HandelGothic_BT21x22_Regular, CL_yellow, FO_HORIZONTAL)

TFT_Write_Text(“Welcome”, 35, 75)

delay_ms(1000)

end sub

'===============================================================================

sub procedure mikromedia_Transmit_Payload(dim value as byte)

nRF_CS = 0

SPI2_write(0xA0) 'command byte for transmitting Payload

SPI2_Write(value) '1 byte payload

nRF_CS = 1

nRF_CE = 1

delay_us(15) 'Toggle CE (high for atleast 10us) to send packet

nRF_CE =0

end sub

'===============================================================================

sub procedure Transmit(dim value as byte) 'if 1byte payload

nRF_SPI_Write_Reg(0x00, 0x5a) 'CONFIG:mask rx_dr and max_rt, enableCRC, 1byte crc, Power up,Transmitter

nRF_SPI_Write_Reg(0x01, 0x00) 'En_aa: Disable auto-ack

'nRF_SPI_Write_Reg(0x02, 0x01) 'En_RxAddr: Enable P0

nRF_SPI_Write_Reg(0x03, 0x02) 'Setup_AW: 4 bytes address width

'nRF_SPI_Write_Reg(0x04, 0x03) 'Setup_Retr: 3(default)not required if auto ack disabled

nRF_SPI_Write_Reg(0x05,5 ) 'Rf_Ch: Leave at default

nRF_SPI_Write_Reg(0x06, 0x07) 'Rf_Setup: DataRate 1Mbps, TxmodePower= 0dBm

nRF_SPI_Write_Reg(0x10,0XE7E7E7E7) 'Tx_Addr for P0

nRF_SPI_Write_Reg(0x11,1) 'Payload length for P0 (0 to 32)

end sub

'==============================================================================

main:

Init_TFT()

Init_RF()

Welcome()

Transmit(0x01)

nop

end.


I don’t use BASIC, so I can’t help. Here is my PIC C18 test code:

http://www.leonheller.com/MiRF%20V2/MIR … 520%29.zip

Thanks a lot. Will go through the code and hope I spot my mistake!

Hey, I didn’t understand why you have masked the same interrupts(Tx_Ds and Max_Rt) in both the cases.

//PRX, CRC enabled

spi_Send_Read(0x20);

spi_Send_Read(0x39);

SPI_CSN = 1;

SPI_CSN = 0;

and

// PTX, CRC enabled, mask a couple of ints

spi_Send_Read(0x20);

spi_Send_Read(0x38);

SPI_CSN = 1;

SPI_CSN = 0;

I think that must have been a mistake. I’ve got some later code which just uses:

	//PRX, CRC enabled
	spi_Send_Read(0x20);
	spi_Send_Read(0x39); 
	SPI_CSN = 1;   
	SPI_CSN = 0;
/*
** Rx.c
** Receive test program for PIC18F24J11 and nRF24L01+
** Uses the Microchip C18 compiler
**
** The LED is flashed five times when data are received.
** The received data in the buffer may be checked using the 
** debugger Watch window.*/

#include <p18cxxx.h>
#include <spi.h>
#include <timers.h>

// Pragmas
#pragma config WDTEN = OFF
#pragma config XINST = OFF
#pragma config OSC = INTOSC

//function prototypes
void init(void);
void reset_RX(void);
void configure_RX(void);
unsigned char spi_Send_Read(unsigned char);
void dly(unsigned int);

// Defines
#define SPI_SCK		LATCbits.LATC3		// Clock pin, PORTC pin 3 
#define SPI_SO		LATCbits.LATC5		// Serial output pin, PORTC pin 5 
#define SPI_SI		PORTCbits.RC4		// Serial input pin, PORTC pin 4 
#define SPI_CSN		LATCbits.LATC2		// CSN output pin, PORTC pin 2
#define SPI_CE		LATCbits.LATC1		// CE output pin, PORTC pin 1
#define SPI_IRQ		PORTBbits.RB0		// IRQ input pin, PORTB pin 0
#define SPI_SCALE	4   				// postscaling of signal 
#define LED			LATCbits.LATC0      // status LED     	
#define DLY_TIME 	0xF800

// Macros
#define nop() _asm nop _endasm

void main(void)
{
	unsigned char i;
	unsigned char data[4];

	init();
	configure_RX();
	while(1)
	{
   		if (SPI_IRQ == 0)    //wait for anything
        {
            for (i = 0; i < 5; i++)  //flash LED 5 times if data received
            {
                LED = 1;
                dly(DLY_TIME);		// 200 ms delay
                LED = 0;
                dly(DLY_TIME);	
            }
            reset_RX();            
        }
	}
}

// initialise 18F24J11
void init(void)
{
	// run internal oscillator at 8 MHz
	OSCCON = OSCCON | 0b01110000;
	while (!OSCCONbits.OSTS)	// wait for OSTS to go high
		;

	ANCON1 |= 0b00010000; 	// RB0 digital input
	TRISCbits.TRISC3 = 0;	// SDO output
	TRISCbits.TRISC5 = 0;   // SCK output
	TRISCbits.TRISC2 = 0;	// CSN output
	TRISCbits.TRISC1 = 0;	// CE output
	TRISBbits.TRISB0 = 1;	// IRQ input
	SPI_CSN = 1;			// CSN high
	SPI_SCK = 0;			// SCK low
	SPI_CE	= 0;			// CE low
	TRISCbits.TRISC0 = 0; 	// RC0 (LED) output

	OpenSPI(SPI_FOSC_16, MODE_00, SMPMID); //open SPI1
	OpenTimer0( TIMER_INT_OFF &
            	T0_16BIT &
            	T0_SOURCE_INT &
            	T0_PS_1_256 );

}

//configure nRF24L01 for receive
void configure_RX(void)
{
    unsigned char i, j;

    SPI_CSN = 0;
    SPI_CE = 0;
    
	//PRX, CRC enabled
	spi_Send_Read(0x20);
	spi_Send_Read(0x39); 
	SPI_CSN = 1;   
	SPI_CSN = 0;
    
	//disable auto-ack for all channels      
	spi_Send_Read(0x21);
	spi_Send_Read(0x00);     
	SPI_CSN = 1;    
	SPI_CSN = 0;
    
	//address width = 5 bytes  
  	spi_Send_Read(0x23);
	spi_Send_Read(0x03);    
    SPI_CSN = 1;    
    SPI_CSN = 0;
    
	//data rate = 1MB   
  	spi_Send_Read(0x26);
	spi_Send_Read(0x07);    
    SPI_CSN = 1;
  	SPI_CSN = 0;

	//4 byte payload  
 	spi_Send_Read(0x31);
	spi_Send_Read(0x04);    
    SPI_CSN = 1;    
    SPI_CSN = 0;

    //set channel 2 
   	spi_Send_Read(0x25);
	spi_Send_Read(0x02);    
    SPI_CSN = 1;     
    SPI_CSN = 0;

    //set address E7E7E7E7E7
    spi_Send_Read(0x30);
    for (j = 0; j < 5; j++)
 		spi_Send_Read(0xE7); 
    SPI_CSN = 1;  
    SPI_CSN = 0;
    
	//PWR_UP = 1   
 	spi_Send_Read(0x20);
	spi_Send_Read(0x3B);   
    SPI_CSN = 1;    
    SPI_CE = 1;     
}

void reset_RX(void)
{
    unsigned char i, j;
    unsigned char buffer[4];    
    
	//Read RX payload   
    SPI_CSN = 0;    
   	spi_Send_Read(0x61);    
    for (j = 0; j < 4; j++)
    {        
       	buffer[j] = spi_Send_Read(0);        
    }    
    SPI_CSN = 1;    
    
	//Flush RX FIFO    
    SPI_CSN = 0;    
 	spi_Send_Read(0xE2);    
    SPI_CSN = 1;
    SPI_CSN = 0;
 
	//reset int    
  	spi_Send_Read(0x27);
	spi_Send_Read(0x40);    
    SPI_CSN = 1;
}


unsigned char spi_Send_Read(unsigned char byte)
{
	SSPBUF = byte;	
	while(!DataRdySPI())
		;	
	return SSPBUF;
}	


void dly(unsigned int c)
{
	INTCONbits.TMR0IF = 0;
	WriteTimer0(c);
	while (!INTCONbits.TMR0IF)
		;
}

So for the transmitter, should it be this?

// PTX, CRC enabled, mask a couple of ints

spi_Send_Read(0x20);

spi_Send_Read(0x58);

SPI_CSN = 1;

SPI_CSN = 0;

I’ve modified my code according to yours, the IRQ pin still doesn’t go low!

At the transmitter side also, the Tx interrupt does set when I transmit the payload, but IRQ does not go low.

Wonder what the problem is. :think:

For Tx, it should be this:

   // PTX, CRC enabled, mask a couple of ints    
   spi_Send_Read(0x20);
   spi_Send_Read(0x38);
   SPI_CSN = 1; 
   SPI_CSN = 0;

PTX uses 0x38 and PRX uses 0x39.

Bit B6 of config register = Mask Rx_Dr

B5 = Mask Tx_Ds

B4 = Mask Max_Rt

Why have you set B5, B4 in both the cases?

I can’t remember, but it works.

Thanks a lot! I’ve got my code working now :smiley:

Glad I could help.

What was the problem?

I wasn’t setting the Tx_address and Rx_address correctly. Was writing 5 bytes of the address in one go which was incorrect.

Did it the way you did in your code, and it worked!

Leon:

Ported your code to AVR - with Atmega328P board as a receiver and an Atmega8 board as a transmitter. The status register returns 00001110 while transmitting - indicating that the TX FIFO is not full. The receiver board does not receive anything. What should I look for when the receiver does not receive anything?

Thanks in advance,