nRF2401A Transmit & Receive

Hi. I changed a sample CC5x code to C18.

The code is from

http://www.sparkfun.com/commerce/pro … d=152

Instead of printing the data using USART, I tried to connect it to LCD

and display data on LCD. The program is re-written in C18 and separate

into TX and RX part.

But the problem is that RX doesn’t seem to be receiving data from TX.

In order to receive data, RX_DR has to go high. But it never does seem

to go high. I am using PIC18F1320 because I need to use 3.3V for

nRF2401A RF sensor. PIC18F1320 runs at 3.3V and at 8MHz internal

oscillator.

Another problem is with TX code. I’m trying to display the TX time.

elapsed_time

rf_address.U8 = 0b11100111;

for (i=0; i<8; i++)

{

TX_DATA = rf_address.b7;

TX_CLK = 1;

TX_CLK = 0;

rf_address.U8 <<= 1;

}

Above code shifts one bit at a time. But I am not sure how I can set

TX_DATA = rf_address.b7.

[b]TX[/b]
#include <p18f1320.h>
#include <delays.h>

#pragma config OSC = INTIO2
#pragma romdata CONFIG1H = 0b00001000
#pragma romdata CONFIG3H = 0
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
#pragma config MCLRE = OFF

#pragma	interrupt MyHighInt
#pragma	code high_vector=0x08

#define TX_CE PORTBbits.RB0
#define TX_CS PORTBbits.RB1
#define TX_CLK PORTBbits.RB3
#define TX_DATA PORTBbits.RB4

/*
#define RX_CE PORTAbits.RA2
#define RX_CS PORTAbits.RA3
#define RX_CLK PORTAbits.RA4
#define RX_DATA PORTAbits.RA1
#define RX_DR PORTAbits.RA5
*/

#define rs PORTAbits.RA0
#define rw PORTAbits.RA6
#define en PORTAbits.RA7

#define DR PORTBbits.RB5   // connect it to pin 14 on 74HC594
#define SH_CP PORTBbits.RB6	// pin 11 on 74HC594
#define ST_CP PORTBbits.RB7	// pin 12 on 74HC594

void sendData(unsigned char data); 
void writeData(unsigned char data); 
void writeString(const char rom *str); 
void putdec( unsigned int n );
void READ(void);
void boot_up(void);
void configure_transmitter(void);
void transmit_data(void);
void OutPORT(unsigned char D);
void MyHighInt(void);

typedef union u16tag
{
	unsigned int U16;
	struct
   {
   		unsigned char LOBYTE;
   		unsigned char HIBYTE;
   };
} U16_t;

typedef union u8bitstag
{
	unsigned char U8;
	struct
   	{
   		unsigned int b0:1;
   		unsigned int b1:1;
   		unsigned int b2:1;
   		unsigned int b3:1;
   		unsigned int b4:1;
   		unsigned int b5:1;
   		unsigned int b6:1;
   		unsigned int b7:1;
  	};
} U8_t;

typedef union u24bitstag
{
	unsigned char U24;
	struct
   	{
   		unsigned int b0:1;
   		unsigned int b1:1;
   		unsigned int b2:1;
   		unsigned int b3:1;
   		unsigned int b4:1;
   		unsigned int b5:1;
   		unsigned int b6:1;
   		unsigned int b7:1;
   		unsigned int b8:1;
   		unsigned int b9:1;
   		unsigned int b10:1;
   		unsigned int b11:1;
   		unsigned int b12:1;
   		unsigned int b13:1;
   		unsigned int b14:1;
   		unsigned int b15:1;
   		unsigned int b16:1;
   		unsigned int b17:1;
   		unsigned int b18:1;
   		unsigned int b19:1;
   		unsigned int b20:1;
   		unsigned int b21:1;
   		unsigned int b22:1;
   		unsigned int b23:1;
  	};
} U24_t;

unsigned char counter;
unsigned char data_array[4];

void high_vector(void)
{
	_asm GOTO MyHighInt _endasm
}

#pragma code

void MyHighInt(void)
{
}

void main(void)
{
	U16_t elapsed_time;
	counter = 0;

	// 74HC594
	TRISBbits.TRISB5 = 0;		// DR
	TRISBbits.TRISB6 = 0;		// SHCP
	TRISBbits.TRISB7 = 0;		// STCP

	// LCD
               TRISAbits.TRISA0 = 0;
               TRISAbits.TRISA6 = 0;
               TRISAbits.TRISA7 = 0;
	rs = 0;
	rw = 0;
	en = 0;
	
	boot_up();
	
	while(1)
	{
		counter++;
		data_array[0] = 0b00010010;
		data_array[1] = 0b00110100;
		data_array[2] = 0b10101011;
		data_array[3] = counter;

		transmit_data();		

		PIR1bits.TMR1IF = 0;
		TMR1L = 0;
		TMR1H = 0;
		T1CONbits.TMR1ON = 1;

		while(RX_DR == 0)
		{
			if (PIR1bits.TMR1IF == 1);	 			break;
		}
		T1CONbits.TMR1ON = 0;

		TMR1H = elapsed_time.HIBYTE;
		TMR1L = elapsed_time.LOBYTE;
		writeString("Time to receive");
		sendData(0xC0);
		putdec(elapsed_time);
		Delay1KTCYx(1000);
	}	
}

void boot_up(void)
{
	OSCCON = 0b01110011;// internal osillator for 8MHz
	while (OSCCONbits.IOFS == 0);
		ADCON0 = 0;
		ADCON1 = 0xFF;
		CCP1CON = 0;
		//PORTA = 0;
		//TRISA = 0b00100000; // RX_DR is an input
		PORTB = 0;
		TRISB = 0b00000100;   // RX is an input
		
		READ();
		writeString("RF Testing");
		Delay100TCYx(100);
		
	configure_transmitter();
}

// this sends out the data stored in the data_array
// data array must be setup before calling this function
void transmit_data(void)
{
	unsigned char i, j; //, temp;
	U8_t rf_address;
	U8_t temp;
	
	TX_CE = 1;

	// clock in address
	rf_address.U8 = 0b11100111; // power on default for all units
	for (i=0; i<8; i++)
	{
		TX_DATA = rf_address.b7;
		TX_CLK = 1;
		TX_CLK = 0;

		rf_address.U8 <<= 1;
	}

	// clock in the data_array
	for (i=0; i<4; i++)		// 4 bytes
	{
		temp.U8 = data_array[i];
		for (j=0; j<8; j++)	// one bit at a time
		{
			TX_DATA = temp.b7;
			TX_CLK = 1;
			TX_CLK = 0;

			temp.U8 <<= 1;
		}
	}
	
	TX_CE = 0;	// start transmission
}

// 2.4G configuration - Transmitter
// this sets up one RF-2.4G for shockburst transmission
void configure_transmitter(void)
{
	unsigned char i;
	U24_t config_setup;

	// confige mode
	TX_CE = 0;
	TX_CS = 1;

	// setup configuration word
	config_setup.U24 = 0b001000110110111000000100;

	for (i=0; i<24; i++)
	{
		TX_DATA = config_setup.b23;
		TX_CLK = 1;
		TX_CLK = 0;

		config_setup.U24 <<= 1;
	}

	// configuration is activated on falling edge of CS
	TX_CE = 0;
	TX_CS = 0;

	READ();
	writeString("TX config finish");
	Delay1KTCYx(1000);
}


void putdec(unsigned int n)
{
    unsigned int rem  = n % 10;
    unsigned int quot = n / 10;
    if (quot > 0) 
    {
    	putdec(quot);
    }
   	writeData(rem + '0');
}

void READ()
{
	Delay1KTCYx(250);          // Wait 20ms 
  	sendData(0x38);     
  	Delay1KTCYx(250);          // Wait 2ms 
  	sendData(0x0E);       	
                Delay1KTCYx(750);          // Wait 2ms 
  	sendData(0x01);         // Clear LCD display 
  	Delay1KTCYx(15);          // Wait 2ms 
  	sendData(0x06);       	
                Delay1KTCYx(15);         // Wait 2ms 
  	sendData(0x80); 	// start at line 1, position 0	
}


void sendData(unsigned char data) { 
  OutPORT(data); 	
  rs = 0; 
  rw = 0;
  en = 1; 
  Delay1KTCYx(1); 
  en = 0; 
  return;
} 

void writeData(unsigned char data) { 
  OutPORT(data); 	
  rs = 1; 
  rw = 0;
  en = 1; 
  Delay1KTCYx(1); 
  en = 0; 
  return;
  //rs = 0; 
} 

void writeString(const char rom *str) { 
  while( *str ) { 
  writeData(*str); 
  str++;    
  } 
  return;
}

void OutPORT(unsigned char D) { 
   unsigned char bits; 
   bits = 0;
   SH_CP = 0;
   ST_CP = 0;
   DR = 0;
   for (bits=0x80; bits!=0; bits >>= 1) 
   { 
      if ((bits & D) == bits) {           // send DR 
         DR = 1; 
      }   
      else { 
         DR = 0;
      }   
      SH_CP = 1;         // clock SHCP 
      SH_CP = 0; 
   } 
   ST_CP = 1;            // clock STCP 
   ST_CP = 0; 
}
[b]RX[/b]
#include <p18f1320.h>
#include <delays.h>

#pragma config OSC = INTIO2
#pragma romdata CONFIG1H = 0b00001000
#pragma romdata CONFIG3H = 0
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
#pragma config MCLRE = OFF

#pragma	interrupt MyHighInt
#pragma	code high_vector=0x08

/*
#define TX_CE PORTBbits.RB0
#define TX_CS PORTBbits.RB1
#define TX_CLK PORTBbits.RB3
#define TX_DATA PORTBbits.RB4
*/

#define RX_CE PORTAbits.RA2
#define RX_CS PORTAbits.RA3
#define RX_CLK PORTAbits.RA4
#define RX_DATA PORTAbits.RA1
#define RX_DR PORTAbits.RA5

#define rs PORTAbits.RA0
#define rw PORTAbits.RA6
#define en PORTAbits.RA7

#define DR PORTBbits.RB5   // connect it to pin 14 on 74HC594
#define SH_CP PORTBbits.RB6	// pin 11 on 74HC594
#define ST_CP PORTBbits.RB7	// pin 12 on 74HC594

void sendData(unsigned char data); 
void writeData(unsigned char data); 
void writeString(const char rom *str); 
void putdec( unsigned int n );
void READ(void);
void boot_up(void);
void configure_receiver(void);

void receive_data(void);
void OutPORT(unsigned char D);
void MyHighInt(void);

typedef union u16tag
{
	unsigned int U16;
	struct
   {
   		unsigned char LOBYTE;
   		unsigned char HIBYTE;
   };
} U16_t;

typedef union u8bitstag
{
	unsigned char U8;
	struct
   	{
   		unsigned int b0:1;
   		unsigned int b1:1;
   		unsigned int b2:1;
   		unsigned int b3:1;
   		unsigned int b4:1;
   		unsigned int b5:1;
   		unsigned int b6:1;
   		unsigned int b7:1;
  	};
} U8_t;

typedef union u24bitstag
{
	unsigned char U24;
	struct
   	{
   		unsigned int b0:1;
   		unsigned int b1:1;
   		unsigned int b2:1;
   		unsigned int b3:1;
   		unsigned int b4:1;
   		unsigned int b5:1;
   		unsigned int b6:1;
   		unsigned int b7:1;
   		unsigned int b8:1;
   		unsigned int b9:1;
   		unsigned int b10:1;
   		unsigned int b11:1;
   		unsigned int b12:1;
   		unsigned int b13:1;
   		unsigned int b14:1;
   		unsigned int b15:1;
   		unsigned int b16:1;
   		unsigned int b17:1;
   		unsigned int b18:1;
   		unsigned int b19:1;
   		unsigned int b20:1;
   		unsigned int b21:1;
   		unsigned int b22:1;
   		unsigned int b23:1;
  	};
} U24_t;

unsigned char counter;
unsigned char data_array[4];

void high_vector(void)
{
	_asm GOTO MyHighInt _endasm
}

#pragma code

void MyHighInt(void)
{
}

void main(void)
{
	U16_t elapsed_time;
	counter = 0;

	// 74HC594
	TRISBbits.TRISB5 = 0;		// DR
	TRISBbits.TRISB6 = 0;		// SHCP
	TRISBbits.TRISB7 = 0;		// STCP

	// LCD
                TRISAbits.TRISA0 = 0;
                TRISAbits.TRISA6 = 0;
                TRISAbits.TRISA7 = 0;
	rs = 0;
	rw = 0;
	en = 0;
	
	boot_up();
	
	while(1)
	{
		counter++;
		data_array[0] = 0b00010010;
		data_array[1] = 0b00110100;
		data_array[2] = 0b10101011;
		data_array[3] = counter;

		PIR1bits.TMR1IF = 0;
		TMR1L = 0;
		TMR1H = 0;
		T1CONbits.TMR1ON = 1;

		while(RX_DR == 0)
		{
			if (PIR1bits.TMR1IF == 1);				break;
		}
		T1CONbits.TMR1ON = 0;

		TMR1H = elapsed_time.HIBYTE;
		TMR1L = elapsed_time.LOBYTE;

		if (RX_DR == 1)
			receive_data();
		else
			READ();
			writeString("No Data");
			Delay100TCYx(10);
	}
}

void boot_up(void)
{
	OSCCON = 0b01110011;   // internal osillator for 8MHz
	while (OSCCONbits.IOFS == 0);
		ADCON0 = 0;
		ADCON1 = 0xFF;
		CCP1CON = 0;
		PORTA = 0;
		TRISA = 0b00100000;  // RX_DR is an input
		//PORTB = 0;
		//TRISB = 0b00000100;  // RX is an input
		
		READ();
		writeString("RF Testing");
		Delay100TCYx(1);

	configure_receiver();
}

void receive_data(void)
{
	unsigned char i, j, temp;
	U8_t Byte;
	RX_CE = 0;	// power down RF front end
	data_array[0] = 0;
	data_array[1] = 0;
	data_array[2] = 0;
	data_array[3] = 0;

	// clock in data, setup for 32-bit payloads
	for (i=0; i<4; i++)		// 4 bytes
	{
		for (j=0; j<8; j++)		// 8 bits each
		{
			temp <<= 1;
			Byte.U8 = temp;
			Byte.b0 = RX_DATA;
			temp = Byte.U8;
			RX_CLK = 1;
			RX_CLK = 0;
		}
	data_array[i] = temp;		// store this byte
	}

	if (RX_DR == 0)	
		READ();
		writeString("DR went low");
		READ();
		writeData(data_array[0]);
		READ();
		writeData(data_array[1]);
		READ();
		writeData(data_array[2]);
		READ();
		writeData(data_array[3]);		
	RX_CE = 1;	// power up RF front end
}

// 2.4G configuration - Receiver
// this setups 2.4G for receiving at 1mbps
void configure_receiver(void)
{
	unsigned char i;
	U24_t config_setup;

	PORTA = 0b00000000;
	TRISA = 0b00100000;	//RX_DR is on RA5

	// config mode
	RX_CE = 0;
	RX_CS = 1;

	config_setup.U24 = 0b001000110110111000000101;
	
	for (i=0; i<24; i++)
	{
		RX_DATA = config_setup.b23;
		RX_CLK = 1;
		RX_CLK = 0;

		config_setup.U24 <<= 1;
	}

	// configuration is activated on falling edge of CS
	RX_CE = 0;
	RX_CS = 0;

	PORTA = 0b00000000;
	TRISA = 0b00100010;	// RX_DR is on RA5

	// start monitoring the air
	RX_CE = 1;
	RX_CS = 0;

	READ();
	writeString("RX config finish");
}

void putdec(unsigned int n)
{
    unsigned int rem  = n % 10;
    unsigned int quot = n / 10;
    if (quot > 0) 
    {
    	putdec(quot);
    }
   	writeData(rem + '0');
}

void READ()
{
	Delay1KTCYx(250);          // Wait 20ms 
  	sendData(0x38);     
  	Delay1KTCYx(250);          // Wait 2ms 
  	sendData(0x0E);       	
                Delay1KTCYx(750);          // Wait 2ms 
  	sendData(0x01);     // Clear LCD display 
  	Delay1KTCYx(15);          // Wait 2ms 
  	sendData(0x06);     
  	Delay1KTCYx(15);         // Wait 2ms 
  	sendData(0x80); 	// start at line 1, position 0	
}


void sendData(unsigned char data) { 
  OutPORT(data); 	
  rs = 0; 
  rw = 0;
  en = 1; 
  Delay1KTCYx(1); 
  en = 0; 
  return;
} 
void writeData(unsigned char data) { 
  OutPORT(data); 	
  rs = 1; 
  rw = 0;
  en = 1; 
  Delay1KTCYx(1); 
  en = 0; 
  return;
  //rs = 0; 
} 

void writeString(const char rom *str) { 
  while( *str ) { 
  writeData(*str); 
  str++;    
  } 
  return;
}

void OutPORT(unsigned char D) { 
   unsigned char bits; 
   bits = 0;
   SH_CP = 0;
   ST_CP = 0;
   DR = 0;
   for (bits=0x80; bits!=0; bits >>= 1) 
   { 
      if ((bits & D) == bits) {           // send DR 
         DR = 1; 
      }   
      else { 
         DR = 0;
      }   
      SH_CP = 1;         // clock SHCP 
      SH_CP = 0; 
   } 
   ST_CP = 1;            // clock STCP 
   ST_CP = 0; 
}

newpic:
Hi. I changed a sample CC5x code to C18.

The code is from

http://www.sparkfun.com/commerce/pro … d=152

Instead of printing the data using USART, I tried to connect it to LCD

and display data on LCD. The program is re-written in C18 and separate

into TX and RX part.

But the problem is that RX doesn’t seem to be receiving data from TX.

In order to receive data, RX_DR has to go high. But it never does seem

to go high. I am using PIC18F1320 because I need to use 3.3V for

nRF2401A RF sensor. PIC18F1320 runs at 3.3V and at 8MHz internal

oscillator.

Another problem is with TX code. I’m trying to display the TX time.

elapsed_time

rf_address.U8 = 0b11100111;

for (i=0; i<8; i++)

{

TX_DATA = rf_address.b7;

TX_CLK = 1;

TX_CLK = 0;

rf_address.U8 <<= 1;

}

Above code shifts one bit at a time. But I am not sure how I can set

TX_DATA = rf_address.b7.

[b]TX[/b]

#include <p18f1320.h>
#include <delays.h>

#pragma config OSC = INTIO2
#pragma romdata CONFIG1H = 0b00001000
#pragma romdata CONFIG3H = 0
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
#pragma config MCLRE = OFF

#pragma interrupt MyHighInt
#pragma code high_vector=0x08

#define TX_CE PORTBbits.RB0
#define TX_CS PORTBbits.RB1
#define TX_CLK PORTBbits.RB3
#define TX_DATA PORTBbits.RB4

/*
#define RX_CE PORTAbits.RA2
#define RX_CS PORTAbits.RA3
#define RX_CLK PORTAbits.RA4
#define RX_DATA PORTAbits.RA1
#define RX_DR PORTAbits.RA5
*/

#define rs PORTAbits.RA0
#define rw PORTAbits.RA6
#define en PORTAbits.RA7

#define DR PORTBbits.RB5 // connect it to pin 14 on 74HC594
#define SH_CP PORTBbits.RB6 // pin 11 on 74HC594
#define ST_CP PORTBbits.RB7 // pin 12 on 74HC594

void sendData(unsigned char data);
void writeData(unsigned char data);
void writeString(const char rom *str);
void putdec( unsigned int n );
void READ(void);
void boot_up(void);
void configure_transmitter(void);
void transmit_data(void);
void OutPORT(unsigned char D);
void MyHighInt(void);

typedef union u16tag
{
unsigned int U16;
struct
{
unsigned char LOBYTE;
unsigned char HIBYTE;
};
} U16_t;

typedef union u8bitstag
{
unsigned char U8;
struct
{
unsigned int b0:1;
unsigned int b1:1;
unsigned int b2:1;
unsigned int b3:1;
unsigned int b4:1;
unsigned int b5:1;
unsigned int b6:1;
unsigned int b7:1;
};
} U8_t;

typedef union u24bitstag
{
unsigned char U24;
struct
{
unsigned int b0:1;
unsigned int b1:1;
unsigned int b2:1;
unsigned int b3:1;
unsigned int b4:1;
unsigned int b5:1;
unsigned int b6:1;
unsigned int b7:1;
unsigned int b8:1;
unsigned int b9:1;
unsigned int b10:1;
unsigned int b11:1;
unsigned int b12:1;
unsigned int b13:1;
unsigned int b14:1;
unsigned int b15:1;
unsigned int b16:1;
unsigned int b17:1;
unsigned int b18:1;
unsigned int b19:1;
unsigned int b20:1;
unsigned int b21:1;
unsigned int b22:1;
unsigned int b23:1;
};
} U24_t;

unsigned char counter;
unsigned char data_array[4];

void high_vector(void)
{
_asm GOTO MyHighInt _endasm
}

#pragma code

void MyHighInt(void)
{
}

void main(void)
{
U16_t elapsed_time;
counter = 0;

// 74HC594
TRISBbits.TRISB5 = 0;		// DR
TRISBbits.TRISB6 = 0;		// SHCP
TRISBbits.TRISB7 = 0;		// STCP

// LCD
           TRISAbits.TRISA0 = 0;
           TRISAbits.TRISA6 = 0;
           TRISAbits.TRISA7 = 0;
rs = 0;
rw = 0;
en = 0;

boot_up();

while(1)
{
	counter++;
	data_array[0] = 0b00010010;
	data_array[1] = 0b00110100;
	data_array[2] = 0b10101011;
	data_array[3] = counter;

	transmit_data();		

	PIR1bits.TMR1IF = 0;
	TMR1L = 0;
	TMR1H = 0;
	T1CONbits.TMR1ON = 1;

	while(RX_DR == 0)
	{
		if (PIR1bits.TMR1IF == 1);	 			break;
	}
	T1CONbits.TMR1ON = 0;

	TMR1H = elapsed_time.HIBYTE;
	TMR1L = elapsed_time.LOBYTE;
	writeString("Time to receive");
	sendData(0xC0);
	putdec(elapsed_time);
	Delay1KTCYx(1000);
}	

}

void boot_up(void)
{
OSCCON = 0b01110011;// internal osillator for 8MHz
while (OSCCONbits.IOFS == 0);
ADCON0 = 0;
ADCON1 = 0xFF;
CCP1CON = 0;
//PORTA = 0;
//TRISA = 0b00100000; // RX_DR is an input
PORTB = 0;
TRISB = 0b00000100; // RX is an input

	READ();
	writeString("RF Testing");
	Delay100TCYx(100);
	
configure_transmitter();

}

// this sends out the data stored in the data_array
// data array must be setup before calling this function
void transmit_data(void)
{
unsigned char i, j; //, temp;
U8_t rf_address;
U8_t temp;

TX_CE = 1;

// clock in address
rf_address.U8 = 0b11100111; // power on default for all units
for (i=0; i<8; i++)
{
	TX_DATA = rf_address.b7;
	TX_CLK = 1;
	TX_CLK = 0;

	rf_address.U8 <<= 1;
}

// clock in the data_array
for (i=0; i<4; i++)		// 4 bytes
{
	temp.U8 = data_array[i];
	for (j=0; j<8; j++)	// one bit at a time
	{
		TX_DATA = temp.b7;
		TX_CLK = 1;
		TX_CLK = 0;

		temp.U8 <<= 1;
	}
}

TX_CE = 0;	// start transmission

}

// 2.4G configuration - Transmitter
// this sets up one RF-2.4G for shockburst transmission
void configure_transmitter(void)
{
unsigned char i;
U24_t config_setup;

// confige mode
TX_CE = 0;
TX_CS = 1;

// setup configuration word
config_setup.U24 = 0b001000110110111000000100;

for (i=0; i<24; i++)
{
	TX_DATA = config_setup.b23;
	TX_CLK = 1;
	TX_CLK = 0;

	config_setup.U24 <<= 1;
}

// configuration is activated on falling edge of CS
TX_CE = 0;
TX_CS = 0;

READ();
writeString("TX config finish");
Delay1KTCYx(1000);

}

void putdec(unsigned int n)
{
unsigned int rem = n % 10;
unsigned int quot = n / 10;
if (quot > 0)
{
putdec(quot);
}
writeData(rem + ‘0’);
}

void READ()
{
Delay1KTCYx(250); // Wait 20ms
sendData(0x38);
Delay1KTCYx(250); // Wait 2ms
sendData(0x0E);
Delay1KTCYx(750); // Wait 2ms
sendData(0x01); // Clear LCD display
Delay1KTCYx(15); // Wait 2ms
sendData(0x06);
Delay1KTCYx(15); // Wait 2ms
sendData(0x80); // start at line 1, position 0
}

void sendData(unsigned char data) {
OutPORT(data);
rs = 0;
rw = 0;
en = 1;
Delay1KTCYx(1);
en = 0;
return;
}

void writeData(unsigned char data) {
OutPORT(data);
rs = 1;
rw = 0;
en = 1;
Delay1KTCYx(1);
en = 0;
return;
//rs = 0;
}

void writeString(const char rom *str) {
while( *str ) {
writeData(*str);
str++;
}
return;
}

void OutPORT(unsigned char D) {
unsigned char bits;
bits = 0;
SH_CP = 0;
ST_CP = 0;
DR = 0;
for (bits=0x80; bits!=0; bits >>= 1)
{
if ((bits & D) == bits) { // send DR
DR = 1;
}
else {
DR = 0;
}
SH_CP = 1; // clock SHCP
SH_CP = 0;
}
ST_CP = 1; // clock STCP
ST_CP = 0;
}






RX
#include <p18f1320.h>
#include <delays.h>

#pragma config OSC = INTIO2
#pragma romdata CONFIG1H = 0b00001000
#pragma romdata CONFIG3H = 0
#pragma config WDT = OFF
#pragma config LVP = OFF
#pragma config BOR = OFF
#pragma config MCLRE = OFF

#pragma interrupt MyHighInt
#pragma code high_vector=0x08

/*
#define TX_CE PORTBbits.RB0
#define TX_CS PORTBbits.RB1
#define TX_CLK PORTBbits.RB3
#define TX_DATA PORTBbits.RB4
*/

#define RX_CE PORTAbits.RA2
#define RX_CS PORTAbits.RA3
#define RX_CLK PORTAbits.RA4
#define RX_DATA PORTAbits.RA1
#define RX_DR PORTAbits.RA5

#define rs PORTAbits.RA0
#define rw PORTAbits.RA6
#define en PORTAbits.RA7

#define DR PORTBbits.RB5 // connect it to pin 14 on 74HC594
#define SH_CP PORTBbits.RB6 // pin 11 on 74HC594
#define ST_CP PORTBbits.RB7 // pin 12 on 74HC594

void sendData(unsigned char data);
void writeData(unsigned char data);
void writeString(const char rom *str);
void putdec( unsigned int n );
void READ(void);
void boot_up(void);
void configure_receiver(void);

void receive_data(void);
void OutPORT(unsigned char D);
void MyHighInt(void);

typedef union u16tag
{
unsigned int U16;
struct
{
unsigned char LOBYTE;
unsigned char HIBYTE;
};
} U16_t;

typedef union u8bitstag
{
unsigned char U8;
struct
{
unsigned int b0:1;
unsigned int b1:1;
unsigned int b2:1;
unsigned int b3:1;
unsigned int b4:1;
unsigned int b5:1;
unsigned int b6:1;
unsigned int b7:1;
};
} U8_t;

typedef union u24bitstag
{
unsigned char U24;
struct
{
unsigned int b0:1;
unsigned int b1:1;
unsigned int b2:1;
unsigned int b3:1;
unsigned int b4:1;
unsigned int b5:1;
unsigned int b6:1;
unsigned int b7:1;
unsigned int b8:1;
unsigned int b9:1;
unsigned int b10:1;
unsigned int b11:1;
unsigned int b12:1;
unsigned int b13:1;
unsigned int b14:1;
unsigned int b15:1;
unsigned int b16:1;
unsigned int b17:1;
unsigned int b18:1;
unsigned int b19:1;
unsigned int b20:1;
unsigned int b21:1;
unsigned int b22:1;
unsigned int b23:1;
};
} U24_t;

unsigned char counter;
unsigned char data_array[4];

void high_vector(void)
{
_asm GOTO MyHighInt _endasm
}

#pragma code

void MyHighInt(void)
{
}

void main(void)
{
U16_t elapsed_time;
counter = 0;

// 74HC594
TRISBbits.TRISB5 = 0;		// DR
TRISBbits.TRISB6 = 0;		// SHCP
TRISBbits.TRISB7 = 0;		// STCP

// LCD
            TRISAbits.TRISA0 = 0;
            TRISAbits.TRISA6 = 0;
            TRISAbits.TRISA7 = 0;
rs = 0;
rw = 0;
en = 0;

boot_up();

while(1)
{
	counter++;
	data_array[0] = 0b00010010;
	data_array[1] = 0b00110100;
	data_array[2] = 0b10101011;
	data_array[3] = counter;

	PIR1bits.TMR1IF = 0;
	TMR1L = 0;
	TMR1H = 0;
	T1CONbits.TMR1ON = 1;

	while(RX_DR == 0)
	{
		if (PIR1bits.TMR1IF == 1);				break;
	}
	T1CONbits.TMR1ON = 0;

	TMR1H = elapsed_time.HIBYTE;
	TMR1L = elapsed_time.LOBYTE;

	if (RX_DR == 1)
		receive_data();
	else
		READ();
		writeString("No Data");
		Delay100TCYx(10);
}

}

void boot_up(void)
{
OSCCON = 0b01110011; // internal osillator for 8MHz
while (OSCCONbits.IOFS == 0);
ADCON0 = 0;
ADCON1 = 0xFF;
CCP1CON = 0;
PORTA = 0;
TRISA = 0b00100000; // RX_DR is an input
//PORTB = 0;
//TRISB = 0b00000100; // RX is an input

	READ();
	writeString("RF Testing");
	Delay100TCYx(1);

configure_receiver();

}

void receive_data(void)
{
unsigned char i, j, temp;
U8_t Byte;
RX_CE = 0; // power down RF front end
data_array[0] = 0;
data_array[1] = 0;
data_array[2] = 0;
data_array[3] = 0;

// clock in data, setup for 32-bit payloads
for (i=0; i<4; i++)		// 4 bytes
{
	for (j=0; j<8; j++)		// 8 bits each
	{
		temp <<= 1;
		Byte.U8 = temp;
		Byte.b0 = RX_DATA;
		temp = Byte.U8;
		RX_CLK = 1;
		RX_CLK = 0;
	}
data_array[i] = temp;		// store this byte
}

if (RX_DR == 0)	
	READ();
	writeString("DR went low");
	READ();
	writeData(data_array[0]);
	READ();
	writeData(data_array[1]);
	READ();
	writeData(data_array[2]);
	READ();
	writeData(data_array[3]);		
RX_CE = 1;	// power up RF front end

}

// 2.4G configuration - Receiver
// this setups 2.4G for receiving at 1mbps
void configure_receiver(void)
{
unsigned char i;
U24_t config_setup;

PORTA = 0b00000000;
TRISA = 0b00100000;	//RX_DR is on RA5

// config mode
RX_CE = 0;
RX_CS = 1;

config_setup.U24 = 0b001000110110111000000101;

for (i=0; i<24; i++)
{
	RX_DATA = config_setup.b23;
	RX_CLK = 1;
	RX_CLK = 0;

	config_setup.U24 <<= 1;
}

// configuration is activated on falling edge of CS
RX_CE = 0;
RX_CS = 0;

PORTA = 0b00000000;
TRISA = 0b00100010;	// RX_DR is on RA5

// start monitoring the air
RX_CE = 1;
RX_CS = 0;

READ();
writeString("RX config finish");

}

void putdec(unsigned int n)
{
unsigned int rem = n % 10;
unsigned int quot = n / 10;
if (quot > 0)
{
putdec(quot);
}
writeData(rem + ‘0’);
}

void READ()
{
Delay1KTCYx(250); // Wait 20ms
sendData(0x38);
Delay1KTCYx(250); // Wait 2ms
sendData(0x0E);
Delay1KTCYx(750); // Wait 2ms
sendData(0x01); // Clear LCD display
Delay1KTCYx(15); // Wait 2ms
sendData(0x06);
Delay1KTCYx(15); // Wait 2ms
sendData(0x80); // start at line 1, position 0
}

void sendData(unsigned char data) {
OutPORT(data);
rs = 0;
rw = 0;
en = 1;
Delay1KTCYx(1);
en = 0;
return;
}
void writeData(unsigned char data) {
OutPORT(data);
rs = 1;
rw = 0;
en = 1;
Delay1KTCYx(1);
en = 0;
return;
//rs = 0;
}

void writeString(const char rom *str) {
while( *str ) {
writeData(*str);
str++;
}
return;
}

void OutPORT(unsigned char D) {
unsigned char bits;
bits = 0;
SH_CP = 0;
ST_CP = 0;
DR = 0;
for (bits=0x80; bits!=0; bits >>= 1)
{
if ((bits & D) == bits) { // send DR
DR = 1;
}
else {
DR = 0;
}
SH_CP = 1; // clock SHCP
SH_CP = 0;
}
ST_CP = 1; // clock STCP
ST_CP = 0;
}

I think your setup value gets truncated…

unsigned char U24;

config_setup.U24 = 0b001000110110111000000101;

You can’t assign more than 8 bits to an unsigned char. You need to use a data type that is at least 24 bits or an array of 3 unsigned chars and change the initialization appropriately.

Orin.