SparkFun Forums 

Where electronics enthusiasts find answers.

All things pertaining to wireless and RF links
By Haihong Li
#35788
Hi brennen
I transplanted some code from MIRF V2 according to what you have told me .
Now the transmitter can give the TX_DS interrupt but the reciever still can't gets the RX_DR interrupt and can't get any data in the RX FIFO.
I am able to communicate through SPI to the nrf24L01.I read Internal regs that i used and they are set right but the reciever wont recieve any bytes.
Please respond if you have any clue. I'm really stuck at the moment!
These are part of code.
tx mode:
Code: Select all
void config_ptx(void) 
{  
     
    //config PTX 
        CE_0;
        CSN_0; 
        SPI_MasterTransmit(0x20); 
        SPI_MasterTransmit(0x38); 
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x24); 
        SPI_MasterTransmit(0x00); 
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x23); 
        SPI_MasterTransmit(0x03); 
        CSN_1; 

        CSN_0; 
        SPI_MasterTransmit(0x26); 
        SPI_MasterTransmit(0x07); 
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x25); 
        SPI_MasterTransmit(0x02);
        CSN_1; 

        CSN_0; 
        SPI_MasterTransmit(0x30); 
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        CSN_1; 

        CSN_0; 
        SPI_MasterTransmit(0x21); 
        SPI_MasterTransmit(0x00); 
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x27); 
        SPI_MasterTransmit(0x7E); 
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x20); 
        SPI_MasterTransmit(0x5A);
        CSN_1;  
		         
}
void main(void)
{
    unsigned char i;
    SPI_MasterInit();
    config_ptx(); 
    while(1)
    {        
        while (1)  
        {
            transmit_data();
            LED = 1;
            delay_ms(10);
            LED = 0;           
            delay_ms(500);           
        }  
    }
}
void transmit_data(void)
{
    unsigned char i, data, cmd;   
    
    CSN_0;
	//clear previous ints
  	SPI_MasterTransmit(0x27);
 	SPI_MasterTransmit(0x7E);
    CSN_1;
    CSN_0;
    
	//PWR_UP = 1
   	SPI_MasterTransmit(0x20);
 	SPI_MasterTransmit(0x3A);
    CSN_1;
    CSN_0;
    
    //clear TX fifo
    //the data sheet says that this is supposed to come up 0 after POR, but that doesn't seem to be the case
   	SPI_MasterTransmit(0xE1);
    CSN_1;
    CSN_0;
    
	//4 byte payload
   	SPI_MasterTransmit(0xA0);
   	SPI_MasterTransmit(0x34);
  	SPI_MasterTransmit(0x33);
   	SPI_MasterTransmit(0x32);
  	SPI_MasterTransmit(0x31);
    CSN_1;
    
    //Pulse CE to start transmission
    CE_1;
    delay_ms(1);
    CE_0;
}
rx mode :
Code: Select all
void config_prx(void) 
{       
        CSN_1;
        delay_us(10);
        CSN_0;

        CE_0;
        SPI_MasterTransmit(0x20); 
        SPI_MasterTransmit(0x39);
        CSN_1;
        
		
        CSN_0; 
        SPI_MasterTransmit(0x21); 
        SPI_MasterTransmit(0x00);
        CSN_1; 
    
        CSN_0; 
        SPI_MasterTransmit(0x23); 
        SPI_MasterTransmit(0x03); 
        CSN_1; 
		
        CSN_0; 
        SPI_MasterTransmit(0x26); 
        SPI_MasterTransmit(0x07);
        CSN_1; 
       
        CSN_0; 
        SPI_MasterTransmit(0x31); 
        SPI_MasterTransmit(0x04); //接收4字节有效数据
     CSN_1; 
       
        CSN_0; 
        SPI_MasterTransmit(0x25); 
        SPI_MasterTransmit(0x02);
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x30); 
        SPI_MasterTransmit(0xE7);  
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        SPI_MasterTransmit(0xE7); 
        CSN_1; 
        
        CSN_0; 
        SPI_MasterTransmit(0x20); 
        SPI_MasterTransmit(0x3B);
        CSN_1; 

        CE_1; //activate receiver 
} 
void main(void)
{
	unsigned char i;
	SPI_MasterInit();
	config_prx();
	while(1)
	{
   	        if (SPI_IRQ == 0)    //wait for anything
        	        {
            		for (i = 0; i < 5; i++)  //flash LED 5 times if data received
            		{
                	LED = 1;
                	delay_ms(10);
                	LED = 0;
                	delay_ms(10);
            		}
            	         delay_ms(200);
            	         reset_RX();            
        	         }
	}
}
void reset_RX(void)
{
    unsigned char i, j;
    unsigned char buffer[4];
    
         //Read RX payload   
    CSN_0;    
    SPI_MasterTransmit(0x61);    
    for (j = 0; j < 4; j++)
    {        
       	buffer[j] = SPI_MasterTransmit(0);        
    }    
    CSN_1; 
    
    
	//Flush RX FIFO    
    CSN_0;    
 	SPI_MasterTransmit(0xE2);    
    CSN_1;
    CSN_0;
 
	//reset int    
  	SPI_MasterTransmit(0x27);
	SPI_MasterTransmit(0x40);    
    CSN_1;
}
//---------------------------外部中断0-----------------------------------//	 
#pragma interrupt_handler INT0_ovf_isr:2  
void INT0_ovf_isr(void)
	 {	unsigned int temp_data;
	 	
	 	SPI_IRQ == 0;
	 }
By brennen
#35795
Show me a dump of your register configurations for both the TX and RX module after you initialize them as they are read out of the 24L01. I may be able to see if I can figure something out.

Are you setting CE high on the RX side? If it is low, you cannot receive any packets, and that would be a possible explanation of your problems. If you were using my library, this would have been done for you. :wink:
By xuao
#35865
Hi brennen
Originally,i want to use your code directly,but i found my compiler can't compile your code.So i analyse your code you told me and according your flow i modify my own code.Unluckily the problem still exist.


I follow you flow config the PTX:

1.set no ACK(EN_AA = 0x00);
2.set RX_PW_P0 as 1 byte;
3.Set PWR_UP bit,also PTX(CONFIG = 0x0a);
Code: Select all
trans:
0A 00 03 03 03 02 0F 0E 00 00 E7 E7 E7 E7 E7 C2 C2 C2 C2 C2 C3 C4 C5 C6 E7 E7 E7 E7 E7 01 00 00 00 00 00 11 
4.delay 1.5ms,then CE=0;
5.when uart interrupt set an flag "en_send";
6.if en_send=1,write 1 byte data;
7.CE=1,delay 10us,CE=0;
8.if IRQ=0 and TX_DS=1,clear all IRQ.


the PRX:

1.set no ACK(EN_AA = 0x00);
2.set RX_PW_P0 as 1 byte;
3.Set PWR_UP bit,also PRX(CONFIG = 0x0b);
Code: Select all
receive:
0B 00 03 03 03 02 0F 0E 00 00 E7 E7 E7 E7 E7 C2 C2 C2 C2 C2 C3 C4 C5 C6 E7 E7 E7 E7 E7 01 00 00 00 00 00 11
4.delay 1.5ms,then CE=1;
5.wait until IRQ=0.

the 'code' is I dump of my register configurations for both the TX and RX module after I initialize them.

Maybe you can help me to see if my configurations is wrong.Thanks for your help!
By brennen
#35866
I think I found your problem. Your configuration is OK, but you are trying to send a 4-byte payload to a device that is set up to only receive a 1-byte payload. If you want to send it a 4-byte payload, you should set up the RX_PW_P0 register (address 0x11) to 4. Either that or you're only going to be able to send 1-byte payloads as you have it configured now.

As far as my library not compiling, this is almost certainly because of the register definitions and the need of SPI driver and microsecond delay functions. The SPI driver function is defined on lines 45 & 46 of nrf24l01.h:
Code: Select all
#include "spi1.h"
#define spi_send_read_byte(byte)	spi1_send_read_byte(byte)
What you have to do is define a function that takes one byte as an argument (byte) and first sends that byte over SPI. The function blocks until it receives a byte over SPI, then it returns that value (it does not handle the CSN signal, however, simply putting a byte on the bus and then receiving a byte). You need to change "#include "spi1.h"" to whatever file the prototype of this function is in.

The uS delay function is defined on lines 62 & 63 of nrf24l01.h:
Code: Select all
#include "delays.h"
#define delay_us(microseconds)		DelayUS(microseconds)
This function needs to take an integer and wait until that number of microseconds has completed before returning. The function has no return value (void). You need to change the #include to point to the header the function similar to the SPI driver function.

Finally, the register definitions are on lines 98 to 118:
Code: Select all
#include "lpc214x.h"

//defines for uC pins CE pin is connected to
//This is used so that the routines can send TX payload data and 
//	properly initialize the nrf24l01 in TX and RX states.
//Change these definitions (and then recompile) to suit your particular application.
#define nrf24l01_CE_IOREGISTER		FIO0PIN
#define nrf24l01_CE_PINMASK			0x200000

//defines for uC pins CSN pin is connected to
//This is used so that the routines can send properly operate the SPI interface
// on the nrf24l01.
//Change these definitions (and then recompile) to suit your particular application.
#define nrf24l01_CSN_IOREGISTER		FIO0PIN
#define nrf24l01_CSN_PINMASK		0x100000

//defines for uC pins IRQ pin is connected to
//This is used so that the routines can poll for IRQ or create an ISR.
//Change these definitions (and then recompile) to suit your particular application.
#define nrf24l01_IRQ_IOREGISTER		FIO0PIN
#define nrf24l01_IRQ_PINMASK		0x8000
What you need to do here is change the *_IOREGISTER #define's to the IO register that controls the hardware pins that are attached to your nRF24L01. The pinmask is just a mask that specifies the bit that each of the pins is on. For example, if the bit was on pin 6 of the register (starting from 0), your mask would be 0x40 (or 01000000 in binary). Finally, you need to change the #include file once again to reflect where the definitions of your IO registers are found.

This may help you out if you want to use the library in the future.
By xuao
#35868
thanks fo you reply!
I don't explain exactly.My code wasn't the same as above.In my code I send a 1-byte payload to a device.You said my configuration is OK.So now maybe my hardware have some problem.
Your code referred to I noticed.I modify your code in my way.But it still can't be compiled."error:address overflow...",I can't remember exactly.Maybe my compiler is not suit.
By brennen
#35869
xuao wrote:I don't explain exactly.My code wasn't the same as above.In my code I send a 1-byte payload to a device.You said my configuration is OK.So now maybe my hardware have some problem.
Your code referred to I noticed.I modify your code in my way.But it still can't be compiled."error:address overflow...",I can't remember exactly.Maybe my compiler is not suit.
Not sure why you can't send payloads, then, assuming you are sending them right (I can't see your code that you changed). The hardware could certainly be to blame, and I suggested methods previously as to ways to diagnose it, IIRC.

As for the compilation issues, I'm not really sure what the cause of that is. I've never compiled stuff for AVR.
By Haihong Li
#36066
Hi,
I am haihong.I get register configurations from the devices.
Code: Select all
rx: 3B 00 03 03 03 02 07 0E 00 00 E7 E7 E7 E7 E7 C2 C2 C2 C2 C2 C3 C4 C5 C6 E7 E7 E7 E7 E7 04 00 00 00 00 00 11 .
Code: Select all
tx:   5A 00 03 03 00 02 07 2E 00 00 E7 E7 E7 E7 E7 C2 C2 C2 C2 C2 C3 C4 C5 C6 E7 E7 E7 E7 E7 00 00 00 00 00 00 11 .
Please respond if you have any clue. I'm really stuck at the moment!