About Addressing TRW-2.4G

Hi again!

I’ve got a doubt: When I send the address within the config word; the address bits are the most significant ones or the less significant?

I mean; let’s say I want the address to be 0x51 0x46 (2 bytes) should I send the 5 bytes address (config mode) like:

(MSB first in both cases)

0x00

0x00

0x00

0x51

0x46

or

0x51

0x46

0x00

0x00

0x00

So if the address is 0x51 0x46, then the Tx module should send:

0x51

0x46

data1

data2

data3

etc.

right?

Thx for the help.

PLUS: any tip wouldn’t be bad :wink:

MSB first. You can see this in the data sheet if you look at the default configuration (which has an 8 bit address).

/Lars

Thank you

That’s all I’ve been needing.

PS: One more thing. Would you mind taking a look at my code?:slight_smile: It’s not big, really, few lines. Because I can’t meke them work. I thought it was the addressing, but I don’t think so. PLEASE. The Code is in C language.

Thanks Again :wink:

Post the code here, I can take a look. How about my quesstion in your other thread - do you really have a 20MHz crystal in your RF-24G?

/Lars

The answer to that question is NO; I don’t have a 20Mhz Xtal inside the TRF. I’ve modify that part: Now using 16Mhz. Thanks

As you can see is a transcription of a prev code posted by Steven Cholewiak. I thought that if I use that code, the dive will work correctly. This is the configuration header

  byte Buffer_Config[15];   // Buffer for Configuration
  byte BCp;   // pointer for that buffer

#define numOfBytes
#define DATA2_W            numOfBytes*8
#define DATA1_W            numOfBytes*8

#define ADDR_CH2_4            0x10
#define ADDR_CH2_3            0x11
#define ADDR_CH2_2            0x42
#define ADDR_CH2_1            0x11
#define ADDR_CH2_0            0x42

#define ADDR_CH1_4            0x10
#define ADDR_CH1_3            0x11
#define ADDR_CH1_2            0x42
#define ADDR_CH1_1            0x11
#define ADDR_CH1_0            0x42

#define ADDR_W_5bytes      0xA0       //0b1010 0000
#define ADDR_W_4bytes      0x80       //0b1000 0000
#define ADDR_W_3bytes      0x60       //0b0110 0000
#define ADDR_W_2bytes      0x40       //0b01000000
#define ADDR_W_1bytes      0x20       //0b00100000

#define CRC_L16            0x20       //0b00000010
#define CRC_ENABLE          0x01       //0b00000001

#define RX2_DISABLE   0x00
#define CM_SB 0x40
#define RFDR_SB_250Kbps 0x00
#define XO_F_16MHz  0x0C
#define RF_PWR_0db    0x03  // 0db (Full Power)

#define RF_CH 0x80   // 2464MHz
#define RXEN_Tx 0x00
#define RXEN_Rx 0x01 

void WEN_Config_Rx (void){
  Buffer_Config[0]=DATA1_W;  
  Buffer_Config[1]=DATA2_W;
  Buffer_Config[2]=ADDR_CH2_4; 
  Buffer_Config[3]=ADDR_CH2_3;
  Buffer_Config[4]=ADDR_CH2_2;
  Buffer_Config[5]=ADDR_CH2_1;
  Buffer_Config[6]=ADDR_CH2_0;
  Buffer_Config[7]=ADDR_CH1_4;
  Buffer_Config[8]=ADDR_CH1_3;
  Buffer_Config[9]=ADDR_CH1_2;
  Buffer_Config[10]=ADDR_CH1_1;
  Buffer_Config[11]=ADDR_CH1_0;
  Buffer_Config[12]=ADDR_W_5bytes | CRC_L16 | CRC_ENABLE;  
  Buffer_Config[13]=RX2_DISABLE | CM_SB | RFDR_SB_250Kbps | XO_F_16MHz | RF_PWR_0db;
  Buffer_Config[14]=RF_CH | RXEN_Rx;  
}

void WEN_Config_Tx (void){
  Buffer_Config[0]=DATA1_W;  
  Buffer_Config[1]=DATA2_W;
  Buffer_Config[2]=ADDR_CH2_4; 
  Buffer_Config[3]=ADDR_CH2_3;
  Buffer_Config[4]=ADDR_CH2_2;
  Buffer_Config[5]=ADDR_CH2_1;
  Buffer_Config[6]=ADDR_CH2_0;
  Buffer_Config[7]=ADDR_CH1_4;
  Buffer_Config[8]=ADDR_CH1_3;
  Buffer_Config[9]=ADDR_CH1_2;
  Buffer_Config[10]=ADDR_CH1_1;
  Buffer_Config[11]=ADDR_CH1_0;
  Buffer_Config[12]=ADDR_W_5bytes | CRC_L16 | CRC_ENABLE;  
  Buffer_Config[13]=RX2_DISABLE | CM_SB | RFDR_SB_250Kbps | XO_F_16MHz | RF_PWR_0db;
  Buffer_Config[14]=RF_CH | RXEN_Tx;

CONNECTIONS:

DATA----------MOSI (SPI)

CE-------------SS (Slave Select, not config as SPI, but as general I/O)

CS-------------PortA_3

CLK------------SCLK (SPI)

DR1-----------LED (and uC IRQ pin)

:arrow:And now the main program: You’ll find it very short.

Rx:

You’ll see that some uC config is missing; that’s because I remove it so it would be shorter. I ASSURE (is it right? the spelling?) you that the uC is working with a Bus Freq=20Mhz with and external Xtla=4Mhz. All ports are well (I mean DDR) and the SPI is:

  • 250kbps

  • uC as Master

  • single wire (MISO as Output because I don’t receive data)

  • SS pin as general I/O (wich I use to command CE)

The following code only config the Rx module and sets CE high, it does not receive the data from that module. I’ve got a LED connected to DR1 so when a valid address and CRC arrive, it turns on.

“hab” is a variable I use to transmit via SPI. I command it via the emulator (CodeWarrior). So the SPI transmit whenever I want. “transmitiendo” tells me that the SPI is transmitting.

// States
#define LOW  0
#define HIGH  1

// SPI y Wenshing
byte hab=0;
byte transmitiendo=0;
byte rx=0;
byte RxTx=0;

/*****************************************************************************************/
void main(void) {
  WEN_Config_Rx();    // Configura al WENSHING como RECEPTOR
  
  SPI_config();
  
  WEN_CE=LOW;
  WEN_CS=LOW;
  
  // 1st time Config
  hab=1;          
  RxTx=1;         
  
  
  EnableInterrupts; 
  for(;;) {
    __RESET_WATCHDOG(); 
  
  
  if (hab && !transmitiendo){
      WEN_CS=HIGH;
      WEN_CE=LOW;
      SPI_Rx_Tx(RxTx);    // Enable Tx interrupt (SPI)
   }
   
   if(rx){                // TRF mode: Rx
    WEN_CS=LOW;
    WEN_CE=HIGH;    
   }
  } 
 }
/*****************************************************************************************/

		
/*******/
/* ISRs */
/*******/
// SPI ISR
#pragma TRAP_PROC
void SPI_ISR(void){
  if (SPI1S_SPTEF){         //Tx  
    transmitiendo=1;
    SPI1S;
    SPI1D=Buffer_Config[BCp];
    BCp++;
    if (BCp>14){
      WEN_CE=LOW;
      WEN_CS=LOW;
      SPI1C1=0x54;          // Disable Tx interrupt (SPI)
      
      rx=1;                 // TRF mode: Rx
      
      transmitiendo=0;      // Reset my flags
      BCp=0;
      hab=0;
    }
  }
  
  
  if (SPI1S_SPRF){         //Rx
    SPI1D;
  }
}

:arrow: And for the Tx module:

“hab” is a variable I use to transmit via SPI. I command it via the emulator (CodeWarrior). So the SPI transmit whenever I want. “transmitiendo” tells me that the SPI is transmitting.

// States
#define LOW  0
#define HIGH  1

#pragma DATA_SEG SHORT MY_ZEROPAGE

// SPI y Wenshing
byte hab=0;
byte transmitiendo=0;
byte config=0;
byte RxTx=0;
byte Buffer_Tx[5];
byte txp=0;

#pragma DATA_SEG DEFAULT

/**********************/  
/* RUTINAS AUXILIARES */
/**********************/

// Carga Buffer con los datos a transmitir por aire: ADDRESS+DATA
void load_data (void){
  Buffer_Tx[0]=ADDR_CH1_1;
  Buffer_Tx[1]=ADDR_CH1_0;
  Buffer_Tx[2]=0x57;
  Buffer_Tx[3]=0x58;
  Buffer_Tx[4]=0x65;
 }


/*****************************************************************************************/
void main(void) {
   WEN_Config_Tx();    // Configura al WENSHING como TRANSMISOR
  
  SPI_config();
  load_data();
    
  WEN_CE=LOW;
  WEN_CS=LOW;
  
  // 1st time config
  hab=1;          // enable Tx
  config=1;       // config mode
  RxTx=1;         // enable Tx interrupt (SPI)
  
  
  EnableInterrupts; 
  for(;;) {
    __RESET_WATCHDOG(); 
  
       
   if (hab && !transmitiendo){
      if (config){
        WEN_CS=HIGH;
        WEN_CE=LOW;
      }else{
        WEN_CS=LOW;
        WEN_CE=HIGH;
      }
      SPI_Rx_Tx(RxTx);    // Enable Tx interrupt
   }
  }
 }
/*****************************************************************************************/


/*****************************************/
/* Rutinas de Servicio de Interrupciones */
/*****************************************/
// SPI ISR
#pragma TRAP_PROC
void SPI_ISR(void){
  if (SPI1S_SPTEF){    //Tx  
    transmitiendo=1;
    if(config){
      SPI1S;
      SPI1D=Buffer_Config[BCp];
      BCp++;
    }else{
      SPI1S;
      SPI1D=Buffer_Tx[txp];
      txp++;
    }
    if (BCp>14 || txp>(numOfBytes+1)){
      WEN_CE=LOW;
      WEN_CS=LOW;
      SPI1C1=0x54;     // Disable SPI Tx interrupt
      
      transmitiendo=0;
      config=0;
      BCp=0;
      txp=0;
      hab=0;
    }
  }
  
}

If you need the full code, for a better understanding email me or ask for it in a reply

Once and allways THANK YOU

OOPS!!! :roll:

Now reviewing the last post, I found something I forget to change: In the config, I only use 2bytes for address

I repeat 2 BYTES FOR ADDRES, NOT 5 AS IT SAYS

It is not obvious if you are ok with the timing restrictions. In my code (in the AVR code forum) you will notice that I wait 5 micro seconds after setting CS and I wait 3ms for powerup. This is from the data sheet and it looks like Steven Cholewiak has this in his code also:

#define CSDELAY()          delay_us(10) 
#define PWUPDELAY()        delay_ms(3)

What SPI mode are you using? CPOL=0 and CPHA=0 is what works for me.

Also, if I were you, I would not make use of the SPI interrupt before i got something simpler to work. It might not even be worth the trouble to use the interrupt at all.

/Lars