SparkFun Forums 

Where electronics enthusiasts find answers.

Your source for all things Atmel.
By sigve
#26153
HI!

I am having some problems with my code for the trf24g and find it cind of difficult to debug internaly in the reciver. The sender sends one byte of data into the tranciver, but the DR1 pin on the reciver doesent go high at any time.
I would apriciate any help i can get.

RX code :
Code: Select all
#include <mega16.h>    
#include <stdio.h>
#include <delay.h>


#define CE PORTB.0
#define CS PORTB.1


//*******************************************************************************************
 // configuration word :  (15 bytes)            


/*15*/    #define TRF24G_PAYLOAD_SIZE_1  1		// in bytes

/*14*/    #define TRF24G_PAYLOAD_SIZE_2  1		// in bytes

/*9-13*/  #define TRF24G_ADDR_2  0,0,0,0,0 		// 5 bytes (not in use)

/*4-8*/   #define TRF24G_ADDR_1  0,0,0,0,0xAA       // 5 bytes

/*3*/  	  #define TRF24G_ADDR_SIZE  1               // in bytes 
	      #define TRF24G_CRC_SIZE 0b01          // 8 bit CRC enabled

/*2*/	  #define TRF24G_RX2_EN 0                   // RX2 dissabled
	      #define TRF24G_SHOCK_EN 1             // shock burst enabled
	      #define TRF24G_DATARATE 0             // 0 for 250kbs or 1 for 1mbs
	      #define TRF24G_XTAL_FREQ 0b011        // 16mhz inside unit
	      #define TRF24G_TX_PWR 0b11            // FULL power !!
	  
/*1*/     #define TRF24G_CHANNEL 2		    // channel 2
	      #define TRF24G_RX 0                   // 0 for TX or 1 for RX
                 

// end of config word.  



//******************************************************************************************
// tabell for configurerings ordet.

static unsigned char trf24gConfig[15] =  {   
		

/*15*/	  TRF24G_PAYLOAD_SIZE_2 * 8,            // DATA2_W in bits

/*14*/    TRF24G_PAYLOAD_SIZE_1 * 8,            // DATA1_W in bits

/*9-13*/  TRF24G_ADDR_2,                        // ADDR2 (not in use)

/*4-8*/   TRF24G_ADDR_1,                        // ADDR1

/*3*/     ((TRF24G_ADDR_SIZE * 8) << 2) | TRF24G_CRC_SIZE,

/*2*/     (TRF24G_RX2_EN << 7) |                // RX2 active?
          (TRF24G_SHOCK_EN << 6) |              // Shockburst?
          (TRF24G_DATARATE << 5) |              // Datarate
          (TRF24G_XTAL_FREQ << 2) |             // xtal frequency
           TRF24G_TX_PWR , 			            // Tx power
                             
/*1*/     (TRF24G_CHANNEL << 1) | TRF24G_RX	// Channel and RX/TX select
 
};


//***************************************************************************************
 
void vent ()
 {
 delay_ms(5);
 }

//*********************************************************************************


void spiSend(unsigned char data)
{  
   #asm("cli")  // disable interrupts
   SPDR = data;
   while(SPSR == 0x00)
   {
    //wait for sending to finish
   }
   #asm("sei")  // enable interrupts   
}

//****************************************************************************************

void trf24gconfigure(unsigned char trf24gConfig[15]) {

   unsigned char i;
   

	delay_ms(3);      // 3ms startup

	CE = 0 ;
        vent() ;	  // enter config mode
	CS = 1 ;
       
   
   
   for(i = 0; i < sizeof(trf24gConfig); i++) 
   {
      spiSend(trf24gConfig[i]);		// sending...
   }
   

	CS = 0 ;      // exit config mode
	vent() ;

#if TRF24G_RX
        CE = 1 ;      // activate RX     
        vent() ;
#endif

}



//****************** RECIVING ***********************************************************


// External Interrupt 0 service routine   (interupts when data ready (DR =1) )
interrupt [EXT_INT0] void ext_int0_isr(void)
{
unsigned char data; 
int i ;
unsigned char size = TRF24G_PAYLOAD_SIZE_1;   
printf ("\n\r%d", 0x22 ) ;     // for debug

#asm("cli")    // disable interupt
                                    
printf ("\n\r%d", 0x21 ) ;            // for debug
   spiSend (0x00) ;			// sends 0, when finished SPI interrupts


 for(i = 0; i < size ; i++) 
   {
      
     data = SPDR ;   		   
     printf ("\n\r%d", 0x20 ) ;            // for debug
     printf ("\n\r%d", data ) ;
     spiSend (0x00) ;	
   
   }
   vent() ;

   
  #asm("sei")     // enable interupt
}


//*****************************************************************************************************
void main(void)
{

PORTB=0x00;
DDRB=0xB3;  

PORTD=0x00;
DDRD=0x02;

// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 62,000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x53;
SPSR=0x00;


//USART
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;


// External Interrupt(s) initialization
// INT0: On
// INT0 Mode: Rising Edge
// INT1: Off
// INT2: Off
GICR|=0x40;
MCUCR=0x03;
MCUCSR=0x00;
GIFR=0x40;
                            

// Clear the SPI interrupt flag
#asm
    in   r30,spsr
    in   r30,spdr
#endasm

// Global enable interrupts
#asm("sei")              




trf24gconfigure(trf24gConfig);		// configure RF24g


while (1)
{

//just let the interupt work(RX-mode)

}

}// main

TX code:
Code: Select all
// transmitter code for RF 24g

#include <mega8.h>    
#include <stdio.h>
#include <delay.h>


#define CE PORTB.6
#define CS PORTB.7


//*******************************************************************************************
 // configuration word :  (15 bytes)            


/*15*/    #define TRF24G_PAYLOAD_SIZE_1  1		// in bytes

/*14*/    #define TRF24G_PAYLOAD_SIZE_2  1		// in bytes

/*9-13*/  #define TRF24G_ADDR_2  0,0,0,0,0 		// 5 bytes (not in use)

/*4-8*/   #define TRF24G_ADDR_1  0,0,0,0,0xAA   // 5 bytes

/*3*/  	  #define TRF24G_ADDR_SIZE  1           // in bytes 
	      #define TRF24G_CRC_SIZE 0b01          // 8 bit CRC enabled

/*2*/	  #define TRF24G_RX2_EN 0               // RX2 dissabled
	      #define TRF24G_SHOCK_EN 1             // shock burst enabled
	      #define TRF24G_DATARATE 0             // 0 for 250kbs or 1 for 1mbs
	      #define TRF24G_XTAL_FREQ 0b011        // 16mhz inside unit
	      #define TRF24G_RX_PWR 0b11            // FULL power !!
	  
/*1*/     #define TRF24G_CHANNEL 2			    // channel 2
	      #define TRF24G_RX 0                   // 0 for TX or 1 for RX
                 

// end of config word.  



//******************************************************************************************


unsigned char trf24gConfig[15] =  {   // tabell for configurerings ordet.
		

/*15*/	  TRF24G_PAYLOAD_SIZE_2 * 8,            // DATA2_W in bits

/*14*/    TRF24G_PAYLOAD_SIZE_1 * 8,            // DATA1_W in bits

/*9-13*/  TRF24G_ADDR_2,                        // ADDR2 (not in use)

/*4-8*/   TRF24G_ADDR_1,                        // ADDR1

/*3*/     ((TRF24G_ADDR_SIZE * 8) << 2) | TRF24G_CRC_SIZE,

/*2*/     (TRF24G_RX2_EN << 7) |                // RX2 active?
          (TRF24G_SHOCK_EN << 6) |              // Shockburst?
          (TRF24G_DATARATE << 5) |              // Datarate
          (TRF24G_XTAL_FREQ << 2) |             // xtal frequency
           TRF24G_RX_PWR , 			            // Tx power
                             
/*1*/     (TRF24G_CHANNEL << 1) | TRF24G_RX	// Channel and RX/TX select
 
};


//***************************************************************************************
 

void vent ()
 {
 delay_us(5);
 }

//*********************************************************************************

void spiSend(unsigned char data)
{
   SPDR = data;
   while(SPSR == 0x00)
   {
    //wait for sending to finish
   }
      
}



//****************************************************************************************
void trf24gconfigure(unsigned char trf24gConfig[15])
{
   unsigned char i;
   

	delay_ms(3);      // 3ms startup

	CE = 0 ;
        vent() ;	  // enter config mode
	CS = 1 ;
       
   
   
   for(i = 0; i < sizeof(trf24gConfig); i++) 
   {
      spiSend(trf24gConfig[i]);		// sending...
   }
   
		 
	CS = 0 ;      // exit config mode
	vent() ;

#if TRF24G_RX
        CE = 1 ;      // activate RX
#endif

}

//******************************************************************************************


void trf24gSend(char data)    // for 1 byte data and address
{
  
   unsigned char addr = 0xAA;
   
  	CE = 1 ;
        vent() ;	 // enter sending mode
	CS = 0 ;

     spiSend(addr);     //adress    
     vent () ;
     spiSend(data);     // DATA
     
     vent () ;
     
     CE = 0 ;         //back to standby
      
      
}   


//*****************************************************************************************************
void main(void)
{
 
PORTB=0x00;
DDRB=0xFF;

PORTC=0x00;
DDRC=0x00;


// SPI initialization
// SPI Type: Master
// SPI Clock Rate: 62,000 kHz
// SPI Clock Phase: Cycle Half
// SPI Clock Polarity: Low
// SPI Data Order: MSB First
SPCR=0x53;
SPSR=0x00;


//USART
UCSRA=0x00;
UCSRB=0x18;
UCSRC=0x86;
UBRRH=0x00;
UBRRL=0x33;


trf24gconfigure(trf24gConfig);		// configure RF24g


while (1)
{

trf24gSend(0x24) ;
delay_ms (1000) ;

}




}// main
By Lajon
#26207
You have
Code: Select all
        #define TRF24G_RX 0                   // 0 for TX or 1 for RX 
in the rx code, this should be 1 for rx.
/Lars
By montemor
#38704
This topic is a little old, but I'm wondering if anyone is still in touch with it?

Thanks

Monte
By Lajon
#38931
Well as you notice I don't read here every day but if you have a question go ahead and ask.
/Lars
By dizzey
#39065
Ok reading the code a bit closer i saw what you did. just sending the destination adress byte for byte and then payload
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]