Wireless echo response using 24g -- Code question

I’ve slightly modified SF’s code to get a rf24g to respond (i.e. echo) a response when it receives something, but it’s not working; any ideas?

Basically, the two (so far) rf24g’s are sitting there, one connected to a PC. When the PC sends something to the rf24g, an F88 sends that character to the other transceiver, which in turn echoes it back, and they just keep echoing.

Here’s my code (abbreviated to exclude things common to the SF code):

#define CE       PORTB.6	// Always output
#define CS       PORTB.3	// Always output
#define CLK1     PORTB.4	// Always output
#define DATA     PORTB.1	// Must toggle -- Input for receive
#define DR       PORTB.0	// Always input

#define  Send_data() TRISB = TRISB & 0b.0000.0101 // DATA must be output when writing
#define  Read_data() TRISB = TRISB | 0b.0000.0111 // DATA must be input when reading

uns8 data_array[4];

void main()
{
	char rec;
    boot_up();

	CE = 1;							// Start monitoring the air
	RCIF = 0;

	while(1)						// Loop indefinitely
	{
		if ( RCIF )					// is it the serial port receive interrupt ?
		{
			rec = RCREG;			// Get the received character
			printf("\n\rPacket received from PC: %h\n\r", rec);
			data_array[0] = rec;	// Store character in data_array; prepare to send
			data_array[1] = rec;	// Store character in data_array; prepare to send
			data_array[2] = rec;	// Store character in data_array; prepare to send
			data_array[3] = rec;	// Store character in data_array; prepare to send
			RCIF = 0;				// Reset serial port receive interrupt flag
			transmit_data();		// Transmit the data through transceiver
		}
		
		if( DR == 1 )				// We have data!
		{
			receive_data();			// Receive data and unload it
		
			printf("\n\rEchoing data...\n\r", 0);
			transmit_data();
			delay_ms(1000);			// Delay between transmissions for evaluation
		}							// If nothing happened by this time, loop back around
	}
}

void boot_up(void)
{
    OSCCON = 0b.0111.0000; //Setup internal oscillator for 8MHz
    while(OSCCON.2 == 0); //Wait for frequency to stabilize

    ANSEL = 0b.0000.0000; //Turn pins to Digital instead of Analog
    CMCON = 0b.0000.0111; //Turn off comparator on RA port

    PORTA = 0b.0000.0000;  
    TRISA = 0b.0000.0000;  //0 = Output, 1 = Input (RX_DR is on RA0)

    PORTB = 0b.0000.0000;  
    TRISB = 0b.0000.0101;  //0 = Output, 1 = Input (RX is an input)

    enable_uart_TX(0); //Setup the hardware UART for 20MHz at 9600bps
    enable_uart_RX(0); //Take a look at header files - it's not that hard to setup the UART
    
    printf("\n\rRF-24G Testing:\n\r", 0);
    
    delay_ms(100);

    configure_transmitter();
    configure_receiver();

}

I toggle the TRISB pin corresponding to DATA to be an input when I try to receive something, but it’s not shown here.

What happens is minimal–I do get the “Packet received from PC” message when I send something from the PC, but that’s it. Either the 1st transceiver isn’t sending or it’s not being received at the other end, but I see nothing after that. Because both nodes are sending out serial messages, I’ve connected a PC to the receive node (on the first transmit) to a PC as well, and receive nothing there.

I’m mainly wondering if my logic is correct in the ‘main’ function, but any help is appreciated.

Thanks very much,

Jeff

It been a few days maybe you already resolved the problem?

I am not completely clear about your HW setup but this code

    configure_transmitter(); 
    configure_receiver();

would not make much sense if you have just one module connected to a controller. The 24g can not be in send and recive mode at the same time. For your test you would need to configure_transmitter, send something, wait while it is on air, configure_receiver(), wait for a response and handle the response if there is one.

/Lars

Lajon, thanks for pointing that out. I just discovered that reconfiguring was necessary between Tx and Rx; my understanding is that you only need to resend the last byte of the config word, though–which includes 7:1 (rf_channel info) and <0> which is the RXEN bit. I’ve modified my code to do that, but haven’t yet tested it.

Thanks for reviewing my code.

Jeff

Yep–that was it. I’m resending the last byte of the config word before switching modes and it works like a charm now.

Jeff

MJ,

I just received my wireless modules! Can you send me your code for me to test?

It would be greatly appreciated!

SL