TX issue on TRW 24G

Hi… I recently bought a couple of these modules and it has been a couple of weeks since I finally received some data (noise I believe). Then I enabled the CRC and set it to 16 bits, along with a 40 bit address. So they are no longer receiving noise, it works!!!

So I went on to configure the other RF module in order to establish my own little RF wireless network, right? The configuration word is almost the same, I just changed the device address (so it is not the same as the rx_device address) and cleared the RX_EN.

I started one of the PIC’s timer so it interrupts on overflow and must send data via the tx_rf_module… but im not getting any data on the other side, my rx_rf_module doesn’t set DR1… Anyone know what is wrong with my routine???

I’m posting my tx_rf_ module configuration routines:

void tx_modulo(unsigned char dato_spi)

{

LATDbits.LATD0 = 1; //CE set high.

Delay10TCYx(5); //5us delay

OpenSPI(SPI_FOSC_64, MODE_11, SMPMID);

WriteSPI(0xa0);

WriteSPI(0xa0);

WriteSPI(0xa0);

WriteSPI(0x01);

WriteSPI(0x15);

WriteSPI(dato_spi);

WriteSPI(dato_spi);

WriteSPI(dato_spi);

WriteSPI(dato_spi);

WriteSPI(dato_spi);

WriteSPI(dato_spi);

CloseSPI();

LATDbits.LATD0 = 0; //CE set low

Delay10TCYx(185); //195us delays

}

void configurar_trf24g (void)

{

INTCON3bits.INT1IE = 0; conf_trf[1] = 0xff;

conf_trf[2] = 0x08;

conf_trf[3] = 0xff;

conf_trf[4] = 0xff;

conf_trf[5] = 0xff;

conf_trf[6] = 0xff;

conf_trf[7] = 0xff;

conf_trf[8] = 0xbb;

conf_trf[9] = 0xbb;

conf_trf[10] = 0xbb;

conf_trf[11] = 0xbb;

conf_trf[12] = 0xbb;

conf_trf[13] = 0b10100011;

conf_trf[14] = 0b01101111; conf_trf[15] = 0b00;

LATDbits.LATD0 = 0; //CE set low

Delay1KTCYx(30); //3 ms. delay

LATDbits.LATD1 = 1; //CS set high Delay10TCYx(5); //5us delay

i_trf = 1;

for(i_trf = 1 ; i_trf < 16 ; i_trf++)

{

salida = escribir_spi(conf_trf[i_trf]);

}

LATDbits.LATD1 = 0; //CS set low

Delay1TCY(); //100 ns delay LATDbits.LATD0 = 1; //CE set high, it is now active

}

Thanks for your help!!!

Hi,

Some things that may be problematic:

I think the delay

Delay1KTCYx(30); //3 ms. delay 

should be before you start to configure.

conf_trf[2] = 0x08; 

Thats the payload size I belive. It is in bits so this is only one byte payload (and you seem to send 6 bytes).

You are using the conf_trf starting at index 1. Thats ok as long as it is dimensioned with one extra entry (in your case it would need to be 16 bytes).

Hi…

Thanks for your advice, but I need to know one thing. When Im transmitting data to another RF module, shouldn’t I write first the adress of the receiving device??? Then the data???

In my code, I’ve configured the receiving module with a 40bits address, so that’s why i’m sending the address first and then the data.

Thanks for your help and concern, hope you help me… i’m stuck in this!!!

Yes, that is correct. But have you also configured the receiver payload size (48 bits to match your tx_modulo function). Maybe you could show the receiver code also. Or you could have a look at the code I have posted in the AVR Code forum here (ok, you use PIC but since it is C -code it could be useful to look at anyway).

/Lars

Lars:

I don’t know “C”. Is there a flow chart I can refer to? I want to write assembly code for a Motorola MCU.

Here is my latest receiver code…

#include <p18f452.h>

#include <delays.h>

#include <i2c.h>

#include <spi.h>

#define TAMANORF 16

unsigned char conf_trf[TAMANORF]= {0};

unsigned char escribir_spi(unsigned char dato_spi);

void configurar_trf24g (void);

void main (void);

unsigned char salida;

unsigned char i_trf;

void main()

{

TRISD = 0;

TRISC = 0b10011000;

TRISB = 0b00000111;

LATD = 0;

LATBbits.LATB5 = 1;

configurar_trf24g();

INTCON = 0b11100000;

INTCON2 = 0b00000000;

INTCONbits.GIEL = 1;

INTCON2bits.INTEDG1 = 0;

INTCON3bits.INT1IP = 0;

INTCON3bits.INT1IE = 1;

INTCON3bits.INT1IF = 0;

RCONbits.IPEN = 1;

Delay1TCY();

LATDbits.LATD0 = 1; //Set CE (high)

while(1)

{

LATBbits.LATB4 = !LATBbits.LATB4;

}

}

unsigned char escribir_spi(unsigned char dato_spi)

{

OpenSPI(SPI_FOSC_64, MODE_00, SMPMID);

WriteSPI(dato_spi);

CloseSPI();

return 0;

}

void configurar_trf24g (void)

{

conf_trf[1] = 0x44;

conf_trf[2] = 0x08;

conf_trf[3] = 0xff;

conf_trf[4] = 0xff;

conf_trf[5] = 0xff;

conf_trf[6] = 0xff;

conf_trf[7] = 0xff;

conf_trf[8] = 0xa0;

conf_trf[9] = 0xa0;

conf_trf[10] = 0xa0;

conf_trf[11] = 0x01;

conf_trf[12] = 0x01;

conf_trf[13] = 0b10100011 conf_trf[14] = 0b01101111;

conf_trf[15] = 0x01;

LATDbits.LATD0 = 0; //clear CE

LATDbits.LATD1 = 1; //set CS Delay10TCYx(10); //10us delay

i_trf = 1;

for(i_trf = 1 ; i_trf < 16 ; i_trf++)

{

salida = escribir_spi(conf_trf[i_trf]);

}

LATDbits.LATD1 = 0; //clear CS

Delay1TCY(); //100ns delay @ 40 Mhz

LATDbits.LATD0 = 1; //set CE

}

I’ll try and post later some sort of steps to follow in order to configure these modules, at least what i’m doing… don’t know if it is correct, though, John…

Good luck everyone and thanks again…

I’ve included the suggestions made by Lajon, changed the initial 3ms delay and added a couple more bits to receive… still not working…

#include <p18f452.h>

#include <delays.h>

#include <i2c.h>

#include <spi.h>

#define TAMANORF 16

void InterruptHandlerLow (void);

unsigned char conf_trf[TAMANORF]= {0};

unsigned char escribir_spi(unsigned char dato_spi);

void configurar_trf24g (void);

void main (void);

void tx_modulo(unsigned char dato_spi);

unsigned char salida;

unsigned char i_trf;

unsigned int i2_tx = 0;

unsigned int i_tx = 0;

void main()

{

TRISD = 0;

TRISC = 0b10010000;

TRISB = 0b00000111;

LATD = 0;

LATBbits.LATB5 = 1;

LATBbits.LATB6 = 0;

configurar_trf24g();

INTCON = 0b11100000;

INTCON2 = 0b00000000;

INTCONbits.GIEL = 1;

INTCON2bits.INTEDG1 = 0;

INTCON3bits.INT1IP = 0; INTCON3bits.INT1IE = 1;

INTCON3bits.INT1IF = 0;

RCONbits.IPEN = 1;

LATDbits.LATD0 = 1; //SET CE

while(1)

{

LATBbits.LATB4 = !LATBbits.LATB4;

if(i_tx==62)

{

i_tx=0;

i2_tx++;

if(i2_tx == 4) //a little loop, perhaps .5 Hz

{

tx_modulo(0b10101010);

LATBbits.LATB6 = !LATBbits.LATB6;

i2_tx=0;

}

}

i_tx++;

}

}

unsigned char escribir_spi(unsigned char dato_spi)

{

OpenSPI(SPI_FOSC_64, MODE_00, SMPMID);

WriteSPI(dato_spi);

CloseSPI();

return 0;

}

void tx_modulo(unsigned char dato_spi)

{

TRISCbits.TRISC3 = 0; LATDbits.LATD0 = 1; // SET CE

Delay10TCYx(5); //5us delay

OpenSPI(SPI_FOSC_64, MODE_00, SMPMID);

WriteSPI(0xa0);

WriteSPI(0xa0);

WriteSPI(0xa0);

WriteSPI(0x01);

WriteSPI(0x01);

WriteSPI(dato_spi);

CloseSPI();

LATDbits.LATD0 = 0; //CLEAR CE

Delay10TCYx(185); //195us delay

}

void configurar_trf24g (void)

{

INTCON3bits.INT1IE = 0; //disable ext_int1

conf_trf[1] = 0xff;

conf_trf[2] = 0x08;

conf_trf[3] = 0xff;

conf_trf[4] = 0xff;

conf_trf[5] = 0xff;

conf_trf[6] = 0xff;

conf_trf[7] = 0xff;

conf_trf[8] = 0xbb;

conf_trf[9] = 0xbb;

conf_trf[10] = 0xbb;

conf_trf[11] = 0xbb;

conf_trf[12] = 0xbb;

conf_trf[13] = 0b10100011;

conf_trf[14] = 0b01101111; conf_trf[15] = 0b00; LATDbits.LATD0 = 0; //CLEAR CE

Delay1KTCYx(30); //3ms delay

LATDbits.LATD1 = 1; //SET CS Delay10TCYx(5); //5us delay

i_trf = 1;

for(i_trf = 1 ; i_trf < 16 ; i_trf++)

{

salida = escribir_spi(conf_trf[i_trf]); }

LATDbits.LATD1 = 0; //CLEAR CS

Delay1TCY(); //100ns delay LATDbits.LATD0 = 1; //SET CE

INTCON3bits.INT1IE = 1; //enable ext_int1

}

// Low priority interrupt vector

#pragma code InterruptVectorLow = 0x18

void

InterruptVectorLow (void)

{

_asm

goto InterruptHandlerLow //jump to interrupt routine

_endasm

}

//----------------------------------------------------------------------------

#pragma code

#pragma interrupt InterruptHandlerLow

void

InterruptHandlerLow ()

{

if( INTCON3bits.INT1IF)

{

LATDbits.LATD1 = 0; //CLEAR CS

LATDbits.LATD0 = 0; //CLEAR CE

LATBbits.LATB5 = !LATBbits.LATB5 ;

OpenSPI(SPI_FOSC_64, MODE_00, SMPMID); salida = ReadSPI();

INTCON3bits.INT1IF = 0;

}

}

Still, not working… im not getting any significant data… HELP ANYONEE… please!!!

Good luck!!

In the tx is this your actual line?

LATDbits.LATD1 = 1; //SET CS Delay10TCYx(5); //5us delay 

or is it a problem with the post (you can mark your code and press the Code button to make it easier to read).

The line above comments out the 5us delay which is a problem.

I don’t see any immediate other problems but I don’t know PIC so it could be something with that or timing.

Also did you see the “Free nRF2401 Configuration Software” thread in this forum? Might be useful to verify the configuration.

/Lars

John at J&S:

I don’t have any other description but did you look at the data sheet? It is actually quite good with a step by step description of what needs to be done (and what the chip does) for the different modes.

Also, it should be possible to look at the code even if you don’t know C and you can use the program mentioned (the thread “Free nRF2401 Configuration Software”) to generate the config data.

/Lars