Im really lost rite now…I’ve connected my TRF 2.4g transiever to ATMEL 89c51ed2 microcontroller, the whole circuit is operating at about 3.2 volts, im using a self modified version of the sample code avalible in one of the forum topics but nothing is being recieved…
can Any one plz help me out…im posting the code here for u ppl…plz tell me if there is anything wrong
////Reciever code/////
#include <stdio.h>
#include <AT89X52.H>
#include<intrins.h>
//#include<spi.h>
unsigned char data_array[4];
#define RX_CE P0_3
#define RX_CS P0_2
#define RX_CLK1 P0_0
#define RX_DATA P0_1
#define RX_DR P0_4
#define status_LED P0_5
char bdata temp;
sbit abc=temp^0;
void ser_init(void);
void delay_ms(int x);
void spi_send(char c);
void configure_receiver(void)
{
printf(“Configuration started:::::\n”);
RX_CE = 0; //CE set for config
RX_CS = 1; //CS set for config only time CS is used is to configure
delay_ms(5);
spi_send(0x20); //Data1_W - 32 bits in payload 4Bytes
spi_send(0x00); //ADDR2 - 1 //Dont use Addr2 so set them all to zero
spi_send(0x00); //ADDR2 - 2
spi_send(0x00); //ADDR2 - 3
spi_send(0x00); //ADDR2 - 4
spi_send(0x00); //ADDR2 - 5
spi_send(0xAA); //ADDR1 - 1 //This is our Addr to rx on
spi_send(0x55); //ADDR1 - 2 //This must be the same addr transmitted
spi_send(0xFF); //ADDR1 - 3
spi_send(0x00); //ADDR1 - 4
spi_send(0xAA); //ADDR1 - 5
spi_send(0xA3); //ADDR_W - 40 bits wide - 16bits -CRC en
spi_send(0x4F); //RF Full pwr- 16mhzclk- 250kbs-shkburst-1 chan only
spi_send(0x05); //RF Channel #2 and direction & TX/RX - RX = 1
RX_CS=0; //CS Clr CE already clr
delay_ms(5);
//Start monitoring the air
RX_CE = 1; //CE set
printf(“Configuration Ended:::::\n”);
}
void receive_data(void)
{
int i,j;
//CE = 0;//Power down RF Front end CE up to you if you want to do this
//Erase data array so we know we are looking at actual received data
data_array[0] = 0x00;
data_array[1] = 0x00;
data_array[2] = 0x00;
data_array[3] = 0x00;
for(i = 0 ; i < 4 ; i++) //4 bytes
{
for(j = 0 ; j < 8 ; j++) //8 bits each
{
temp <<= 1;
abc = RX_DATA;
RX_CLK1 = 1;
RX_CLK1 = 0;
}
data_array = temp; //Store this byte
}
//CE = 1; //Power up RF Front end if you disabled it
}
// Declare your global variables here
void main(void)
{
// Input/Output Ports initialization
//Porta initialization set up with 8 led for output
ser_init();
status_LED=0;
configure_receiver(); //Set up the receiver
while (1)
{
if(RX_DR==1) //data pin goes high when it has data
{
status_LED=1;
receive_data(); //start transferring data from RF24g
printf(“\n\rData Received:\n\r”, 0);
printf(“[0] : %h\n\r”, data_array[0]);
printf(“[1] : %h\n\r”, data_array[1]);
printf(“[2] : %h\n\r”, data_array[2]);
printf(“[3] : %h\n\r”, data_array[3]);
delay_ms(100);
status_LED=0;
}
}
}
void delay_ms(int x)
{
int y, z;
for ( ; x > 0 ; x–)
for ( y = 0 ; y < 4 ; y++)
for ( z = 0 ; z < 176 ; z++);
}
void spi_send(char c)
{
unsigned int i;
unsigned char mask=0x80;
for(i=0;i<8;i++)
{
-
if(mask&c)*
-
RX_DATA=1;*
-
else RX_DATA=0;*
-
mask=cror(mask,1);*
RX_CLK1 = 1;
RX_CLK1 = 0; -
}*
}
void ser_init(void)
{
SCON = 0x50; /* SCON: mode 1, 8-bit UART, enable rcvr */
TMOD |= 0x20; /* TMOD: timer 1, mode 2, 8-bit reload */
TH1 = 0xFD; /* 9600 bauds at 11.059200 MHZ */
TL1 = 0xFD;
PCON = PCON & 0X80;
TCON |= 0x40;
TI=1;;
}
/////////////Transmitter code
#include<stdio.h>
#include<math.h>
#include <AT89X52.H>
#include<intrins.h>
#define TX_CE P0_3
#define TX_CS P0_2
#define TX_CLK1 P0_0
#define TX_DATA P0_1
#define TX_DR P0_4
#define status_LED P0_5
void ser_init(void);
void spi_send(char);
void configure_transmitter(void);
void delay_ms(int);
void transmit_data();
void main()
{
ser_init();
status_LED=0;
configure_transmitter(); -
while (1)*
-
{*
-
transmit_data(); //send addr and 4 bytes of data as per routine*
-
delay_ms(500); //wait .5 secs to send next packet*
-
status_LED=~status_LED;*
-
}*
}
void configure_transmitter(void)
{
//Config Mode
printf(“NOW CONFIGURING TRANSMITER:::\n”);
TX_CE = 0; TX_CS = 1;
//Delay of 5us from CS to Data (page 30)
delay_ms(5);
/*config word Gives u lowest error rate, if u want a 8 byte payload
just change Data1_W to 0b00001000. It operates in shockburst/250kbs
16 bit crc on channel #2, full rf pwr, 1 channel rx only, 16mhz rf24g clk
addr width 5 bytes IE 40bits
*/
//All this is the same setup in the receiver bit 0 is changed to rx/tx as req
spi_send(0X20); //Data1_W - 32 bits in payload 4 bytes
spi_send(0x00); //ADDR2 - 1 //We only use 1 addr so set this to zero
spi_send(0x00); //ADDR2 - 2
spi_send(0x00); //ADDR2 - 3
spi_send(0x00); //ADDR2 - 4
spi_send(0x00); //ADDR2 - 5
spi_send(0xAA); //ADDR1 - 1 //1 - 5 This is our tx and rx addr
spi_send(0x55); //ADDR1 - 2
spi_send(0xFF); //ADDR1 - 3
spi_send(0x00); //ADDR1 - 4
spi_send(0xAA); //ADDR1 - 5
spi_send(0XA3); //ADDR_W - 40 bits wide - CRC en 16bits
spi_send(0X4F); //Full pwr- 16mhzclk- 250kbs-shkburst-1 chan only
spi_send(0X04); //RF Channel #2 and TX/RX - TX = 0 bit 0;
//Configuration is actived on falling edge of CS (page 10)
TX_CE = 0; TX_CS = 0;
printf(“CONFIGURATION FINISHED\n”);
}
void delay_ms(int x)
{
int y, z;
for ( ; x > 0 ; x–)
for ( y = 0 ; y < 4 ; y++)
for ( z = 0 ; z < 176 ; z++);
}
void spi_send(char c)
{
unsigned int i;
unsigned char mask=0x80;
for(i=0;i<8;i++)
{ -
if(mask&c)*
-
TX_DATA=1;*
-
else TX_DATA=0;*
-
mask=cror(mask,1);*
-
TX_CLK1 = 1;*
TX_CLK1 = 0; *
}
}
void transmit_data(void)
{
TX_CE = 1; //set up for transmit
delay_ms(5);
printf(“SENDING ADRESS\n”);
spi_send(0xAA); //ADDR1 - 1 Send addr our receive is expecting
spi_send(0x55); //ADDR1 - 2
spi_send(0xFF); //ADDR1 - 3
spi_send(0x00); //ADDR1 - 4
spi_send(0xAA); //ADDR1 - 5
printf(“SENDING DATA\n”);
spi_send(0x12); //4 bytes data to transmit to the receiver
spi_send(0x34);
spi_send(0xAB);
spi_send(0xCD);
TX_CE = 0; //Start transmission
printf(“DONE”);
}
void ser_init(void)
{
_SCON = 0x50; / SCON: mode 1, 8-bit UART, enable rcvr /_
_TMOD |= 0x20; / TMOD: timer 1, mode 2, 8-bit reload /_
_TH1 = 0xFD; / 9600 bauds at 11.059200 MHZ */_
TL1 = 0xFD;
PCON = PCON & 0X80;
TCON |= 0x40;
TI=1;;
}
Any help will be highly appreciated …