This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF24L01 not Transmitting continously

Dear Sir, 

              I am interfacing nRF24L01 with Renesas R5F104 Microcontroller on transmitter side and my Reciever is nRF24L01 interfaced with Arduino Uno Board.The Transitter transmits some data depending the Key Pressed.The Trasnmission must be Continous but the Problem is i am not getting this values after some time interval.I have confirmed the isuue is with Transmitter side only.It is transmitting on large interval abd STATUS register always remains 0x0E.

Please Refer my Code

#include "r_cg_macrodriver.h"
#include "r_cg_port.h"
#include "externfunct.h"
#include "externvar.h"
#include "wrless.h"
unsigned char SPI_TX_Buffer;
unsigned char SPI_RX_Buffer;

// This data type sets the address data pipe 0.
//unsigned char ADDRESS_DATA_PIPE0[5] = {0xE1,0xF0,0xF0,0xE8,0xE8};//E8E8F0F0E1
unsigned char ADDRESS_DATA_PIPE0[5] = {0xE7,0xE7,0xE7,0xE7,0xE7};//E8E8F0F0E1
void wrless_WriteByte(void)
{
     unsigned char loop_a;

	 for(loop_a=0;loop_a<8;loop_a++)
	 {
         if(SPI_TX_Buffer&0x80)
		 	 nRF_OUT=1;//SI = 1;
		 else
		 	 nRF_OUT=0;	//SI = 0;

		 nRF_CLK=1;	//SCLK = 1;
		 SPI_TX_Buffer <<=1;
		 nRF_CLK=0;	//SCLK = 0;
	 }

}
void SPI1_Write(unsigned char spi_data)
{
	
	SPI_TX_Buffer=spi_data;
	while(nRF_IN==1);
	wrless_WriteByte();
}
//-----------------------------------------------------------------------------
// MCU read one byte 
//-----------------------------------------------------------------------------
unsigned char SPI1_Read(const unsigned char regAddr)
{
	unsigned char SPICount;                                       // Counter used to clock out the data
	//unsigned char SPIData;                  
  
	nRF_CSN = 1;                                                   // Make sure we start with active-low CS high
	nRF_CLK = 0;                                                   // and CK low
  	SPI_RX_Buffer = regAddr;                                            // Preload the data to be sent with Address and Data

  	nRF_CSN = 0;                                                   // Set active-low CS low to start the SPI cycle
  	for (SPICount = 0; SPICount < 8; SPICount++)                  // Prepare to clock out the Address and Data
  	{
    		if (SPI_RX_Buffer & 0x80)
      			nRF_OUT = 1;
    		else
      			nRF_OUT = 0;
    			nRF_CLK=1;//SPI_CK = 1;
    			nRF_CLK=0;//SPI_CK = 0;
    			SPI_RX_Buffer <<= 1;
  	}                                                             // and loop back to send the next bit
  			nRF_OUT=0;//SPI_MOSI = 0;                                                 // Reset the MOSI data line
  
  			SPI_RX_Buffer = 0;
  	for (SPICount = 0; SPICount < 8; SPICount++)                  // Prepare to clock in the data to be read
  	{
    		SPI_RX_Buffer <<=1;                                               // Rotate the data
   		nRF_CLK=1;//SPI_CK = 1;                                                 // Raise the clock to clock the data out of the MAX7456
    		SPI_RX_Buffer += nRF_IN;                                        // Read the data bit
    		nRF_CLK=0;//SPI_CK = 0;                                                 // Drop the clock ready for the next bit
  	}                                                             // and loop back
    		nRF_CSN=1;//SPI_CS = 1;                                                   // Raise CS
                      
  return ((unsigned char)SPI_RX_Buffer);                              // Finally return the read data
}

void NRF24L01_WriteRegister(unsigned char Mnemonic, unsigned char value)
{
	nRF_CSN=0;//NRF24L01_CSN = 0;
	while(nRF_IN==1);
	SPI1_Write(W_REGISTER | Mnemonic);
	SPI1_Write(value);
	nRF_CSN=1;//NRF24L01_CSN = 1;       
}

unsigned char NRF24L01_ReadRegister(unsigned char Mnemonic)
{
	unsigned char byte0;
	nRF_CSN=0;//NRF24L01_CSN = 0; 
	while(nRF_IN==1);
	byte0 = SPI1_Read(R_REGISTER | Mnemonic);
	nRF_CSN=1;//NRF24L01_CSN = 1; 
	return byte0;
}

void NRF24L01_WriteBuffer(unsigned char data, unsigned char *buffer, unsigned char bytes)
{
	unsigned char i;
	nRF_CSN=0;//NRF24L01_CSN = 0;  
	while(nRF_IN==1);
	SPI1_Write(data);                       
	for(i = 0; i < bytes; i++)     
   	{
    		SPI1_Write(buffer[i]);
    		//buffer++;
   	}
	nRF_CSN=1;//NRF24L01_CSN = 1;  
}

void NRF24L01_ReadBuffer(unsigned char data, unsigned char *buffer, unsigned char bytes)
{
	unsigned char i;
	nRF_CSN=0;//NRF24L01_CSN = 0;  
	while(nRF_IN==1);
	SPI1_Write(data);                       
	for(i = 0; i < bytes; i++)     
   	{
    		*buffer = SPI1_Read(0);
    		buffer++;
   	}
	*buffer = NULL;
	nRF_CSN=1;//NRF24L01_CSN = 1;  
}

void NRF24L01_Init(unsigned char mode, unsigned char rf_channel)
{
	//NRF24L01_TRIS_CSN = 0; 
	//NRF24L01_TRIS_CE = 0;
	nRF_CSN=1;//NRF24L01_CSN = 1;
	nRF_CE=0;//NRF24L01_CE = 0;
	Delay_ms(100);  
	NRF24L01_WriteRegister(CONFIG, 0xFE);
	Delay_ms(10);
	NRF24L01_WriteRegister(EN_AA, 0x3F);
	NRF24L01_WriteRegister(EN_RXADDR, 0x3F);
	NRF24L01_WriteRegister(SETUP_AW, 0x07);
	NRF24L01_WriteRegister(SETUP_RETR, 0x0A);
	NRF24L01_SetChannel(rf_channel);
	NRF24L01_WriteRegister(RF_SETUP, 0x03);
	NRF24L01_WriteRegister(FEATURE, 0x01);
	NRF24L01_WriteRegister(DYNPD, 0x00);
	
	
	//NRF24L01_WriteRegister(STATUS, 0x70);
	NRF24L01_WriteBuffer(W_REGISTER | RX_ADDR_P0, ADDRESS_DATA_PIPE0, 5);
	NRF24L01_WriteBuffer(W_REGISTER | TX_ADDR, ADDRESS_DATA_PIPE0, 5); 
	NRF24L01_WriteRegister(RX_PW_P0, PAYLOAD_BYTES); 
	//NRF24L01_Flush();
	Delay_ms(100);
	NRF24L01_SetMode(mode);
	Delay_ms(100);
}

void NRF24L01_SetMode(unsigned char mode)
{
	NRF24L01_Flush();
	NRF24L01_WriteRegister(STATUS, 0x70); // Clear STATUS.    
	switch(mode)
      	{
       		case 1:
              	NRF24L01_WriteRegister(CONFIG, 0xF3);  // RX Control
              	nRF_CE=1;//NRF24L01_CE = 1;
       		break;
       		case 2:
              	NRF24L01_WriteRegister(CONFIG, 0x7E);  // TX Control 
              	nRF_CE=0;//NRF24L01_CE = 0;
       		break;
      }
}

void NRF24L01_SendData(unsigned char *buffer)
{
	unsigned char status;
	NRF24L01_SetMode(TX_MODE); 
	//nRF_CSN=0;
	NRF24L01_WriteBuffer(W_TX_PAYLOAD, buffer, PAYLOAD_BYTES);
	nRF_CE=1;//NRF24L01_CE = 1;
	Delay_ms(1); 
	nRF_CE=0;//NRF24L01_CE = 0;	
	status=NRF24L01_ReadRegister(STATUS);
	if(status&TX_DS)	/*tx_ds == 0x20*/
	{
		dsp_str5(letrt,letry,letrt,letre,one);
		//SPI_RW_Reg(WRITE_REG_NRF24L01 + STATUS, 0x20);   
		NRF24L01_WriteRegister(STATUS, 0x20);	
	}
	else if(status&MAX_RT)
	{
		dsp_str5(letrr,letrt,letrt,letre,one);
		NRF24L01_WriteRegister(STATUS, 0x10);
	//SPI_RW_Reg(WRITE_REG_NRF24L01 + STATUS, 0x10);     			
	}
	nRF_CE=1;//CE(1);
//	status=20;

	
}

void NRF24L01_SendByte(unsigned char buffer)
{
	NRF24L01_WriteRegister(W_TX_PAYLOAD, buffer);
	nRF_CE=1;//NRF24L01_CE = 1;
	Delay_ms(1); 
	nRF_CE=0;//NRF24L01_CE = 0;
	
}

unsigned char NRF24L01_DataReady(void)
{
	if((NRF24L01_ReadRegister(STATUS) & 0x40) == 0x40)
  	{
   		return 0; 
  	}
		return 1;
}

void NRF24L01_ReadData(unsigned char *buffer)
{
	NRF24L01_ReadBuffer(R_RX_PAYLOAD, buffer, PAYLOAD_BYTES);
	NRF24L01_WriteRegister(STATUS, 0x70); // Clear STATUS.
	NRF24L01_Flush();
}

void NRF24L01_SetChannel(unsigned char rf_channel)
{
	NRF24L01_WriteRegister(RF_CH, rf_channel);
}

unsigned char NRF24L01_GetChannel(void)
{
	return NRF24L01_ReadRegister(RF_CH);
}

void NRF24L01_StandbyI(void)
{   
	NRF24L01_WriteRegister(CONFIG, 0x0A);
	Delay_ms(10);
}

void NRF24L01_Flush(void)
{
	nRF_CSN=0;//NRF24L01_CSN = 0; 
	SPI1_Write(FLUSH_TX);
	nRF_CSN=1;//NRF24L01_CSN = 1; 
	nRF_CSN=0;//NRF24L01_CSN = 0; 
	SPI1_Write(FLUSH_RX);
	nRF_CSN=1;//NRF24L01_CSN = 1; 
}

void Delay_ms(int count)
{
	unsigned int i;
	for(i=0;i<count;i++)	
	{
		//while(!msflag)
		 Clr_WatchDog();
		//msflag=0;
	}
}




Related