Look, I want to send the (original) 4 bytes from the web page sample to a node with address 0xAB. Here the code:
SENDER:
/*
nRF2401 test code to run on the 24G demo board, V01
This code will generate AUTOMATICALLY send and recieve packets from another demo board running the same V01 code.
This code does not accept user input.
Compiles with the free version of CC5X
Pete Dokter, 2/22/06
config_setup word 16 bits found on pages 13-15
23: 0 Payloads have an 8 bit address
22: 0
21: 1
20: 0
19: 0
18: 0
17: 1 16-Bit CRC
16: 1 CRC Enabled
15: 0 One channel receive
14: 1 ShockBurst Mode
13: 0 250K Transmission Rate
12: 0
11: 1
10: 1
9: 1 RF Output Power
8: 0 RF Output Power
7: 0 Channel select (channel 2)
6: 0
5: 0
4: 0
3: 0
2: 1
1: 0
0: 0 Transmit mode
*/
#define Clock_8MHz
#define Baud_9600
#include “16F88.h”
#pragma config |= 0x3F30 //Internal Oscillator, No WDT, MCLR Enabled
#define CS PORTA.0 //out
#define CLK1 PORTA.1 //out
#define DATA1 PORTA.2 //I/O
#define DR1 PORTA.3 //in
#define DATA2 PORTA.4 //in
#define CE PORTA.6 //out
#define CLK2 PORTA.7 //out
#define DR2 PORTB.0 //in
#define stat1 PORTB.1 //out
#define stat2 PORTB.3 //out
#define stat3 PORTB.4 //out
uns8 data_array[4];
void configure_transmitter(void);
void transmit_data(void);
void delay_ms(uns16);
void main()
{
//CONFIGURATION OF THE HARDWARE
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.0011.1100; //0 = Output, 1 = Input
PORTB = 0b.0000.0000;
TRISB = 0b.1100.0101; //0 = Output, 1 = Input
//END OF HARDWARE CONFIGURATION
while(1)
{
stat1 = 0;
delay_ms(100);
configure_transmitter();
transmit_data();
stat1 = 1;
delay_ms(250);
}
}
//This sends out the data stored in the data_array
//data_array must be setup before calling this function
void transmit_data(void)
{
uns8 i, j, temp, rf_address;
data_array[0] = 0x12;
data_array[1] = 0x34;
data_array[2] = 0xAB;
data_array[3] = 0xCD;
CE = 1; //Temos dados para enviar por isso activamos o onboard data processing
delay_ms(1);
//Clock in address of the receiving module
rf_address = 0xAB;
for(i = 0 ; i < 8 ; i++)
{
DATA1 = rf_address.7;
CLK1 = 1;
CLK1 = 0;
rf_address <<= 1;
}
//Clock in the data_array (data playload)
for(i = 0 ; i < 4 ; i++) //4 bytes
{
temp = data_array*;*
for(j = 0 ; j < 8 ; j++) //One bit at a time
{
DATA1 = temp.7;
CLK1 = 1;
CLK1 = 0;
temp <<= 1;
}
}
CE = 0; //Start transmission
}
//2.4G Configuration - Transmitter
//This sets up one RF-24G for shockburst transmission
void configure_transmitter(void)
{
uns8 i,j;
uns8 temp;
uns8 config_setup[15];
PORTA = 0b.0000.0000;
TRISA = 0b.0011.1000; //0 = Output, 1 = Input (DR1 is on RA3) (DATA1 is on RA2)
//Config Mode
CE = 0; //Chip enable. Activa o TX ou o RX. Desliga para configuração
CS = 1; //Activates the configuration mode. In this mode a word of 15 bytes is downloaded to the nRF2401. Para isso são usados o CS, CLK1 e Data wires
delay_ms(1);
//Delay of 5us from CS to Data (page 30) is taken care of by the for loop
//Setup configuration word
//config_setup = 0b.0010.0011.0100.1110.0000.0100; //Look at pages 13-15 for more bit info
config_setup[0] = 0b.0000.0100;
config_setup[1] = 0b.0100.1110;
config_setup[2] = 0b.0010.0011;
//ADDR1=0,0,0,0,AB
config_setup[3] = 0xAB;
config_setup[4] = 0x00;
config_setup[5] = 0x00;
config_setup[6] = 0x00;
config_setup[7] = 0x00;
//ADDR2
config_setup[8] = 0x00;
config_setup[9] = 0x00;
config_setup[10] = 0x00;
config_setup[11] = 0x00;
config_setup[12] = 0x00;
//LENS
config_setup[13] = 0b.0000.0100;
config_setup[14] = 0b.0000.0000;
//free version
for (j = 3; j > 0; j–)
{
for(i = 0 ; i < 8 ; i++)
{
DATA1 = config_setup[j-1].7;
CLK1 = 1;
CLK1 = 0;
config_setup[j-1] <<= 1;
}
}
delay_ms(1);
//Configuration is actived on falling edge of CS (page 10)
CE = 0; CS = 0;
}
//General short delay
void delay_ms(uns16 x)
{
uns8 y, z;
for ( ; x > 0 ; x–)
for ( y = 0 ; y < 4 ; y++)
for ( z = 0 ; z < 176 ; z++);
}
RECEIVER:
/*
nRF2401 test code to run on the 24G demo board, V01
This code will generate AUTOMATICALLY send and recieve packets from another demo board running the same V01 code.
This code does not accept user input.
Compiles with the free version of CC5X
Pete Dokter, 2/22/06
config_setup word 16 bits found on pages 13-15
23: 0 Payloads have an 8 bit address
22: 0
21: 1
20: 0
19: 0
18: 0
17: 1 16-Bit CRC
16: 1 CRC Enabled
15: 0 One channel receive
14: 1 ShockBurst Mode
13: 0 250K Transmission Rate
12: 0
11: 1
10: 1
9: 1 RF Output Power
8: 0 RF Output Power
7: 0 Channel select (channel 2)
6: 0
5: 0
4: 0
3: 0
2: 1
1: 0
0: 0 Transmit mode
*/
#define Clock_8MHz
#define Baud_9600
#include “16F88.h”
#pragma config |= 0x3F30 //Internal Oscillator, No WDT, MCLR Enabled
#define CS PORTA.0 //out
#define CLK1 PORTA.1 //out
#define DATA1 PORTA.2 //I/O
#define DR1 PORTA.3 //in
#define DATA2 PORTA.4 //in
#define CE PORTA.6 //out
#define CLK2 PORTA.7 //out
#define DR2 PORTB.0 //in
#define stat1 PORTB.1 //out
#define stat2 PORTB.3 //out
#define stat3 PORTB.4 //out
uns8 data_array[4];
void boot_up(void);
void configure_receiver(void);
void receive_data(void);
void delay_ms(uns16);
void main()
{
uns8 x;
//HARDWARE INITIALIZATION
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.0011.1100; //0 = Output, 1 = Input
PORTB = 0b.0000.0000;
TRISB = 0b.1100.0101; //0 = Output, 1 = Input
//END OF HARDWARE INITIALIZATION
stat1 = 1;
while(1)
{
stat1 = 0;
stat2 = 0;
configure_receiver();
delay_ms(50);
if(DR1 == 1) //We have data!
{
stat1 = 1;
receive_data();
if ((data_array[0] == 0x12) && (data_array[1] == 0x34) && (data_array[2] == 0xAB) && (data_array[3] == 0xCD))
{
stat2 = 1;
}
delay_ms(200);
}
}
}
//This will clock out the current payload into the data_array
void receive_data(void)
{
uns8 i, j, temp;
CE = 0;//Power down RF Front end
//Erase the current data array so that 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;
//Clock in data, we are setup for 32-bit payloads
for(i = 0 ; i < 4 ; i++) //4 bytes
{
for(j = 0 ; j < 8 ; j++) //8 bits each
{
temp <<= 1;
temp.0 = DATA1;
CLK1 = 1;
CLK1 = 0;
}
data_array = temp; //Store this byte
}
CE = 1; //Power up RF Front end
}
//2.4G Configuration - Receiver
//This setups up a RF-24G for receiving at 1mbps
void configure_receiver(void)
{
uns8 i,j;
uns8 temp;
//uns8 config_setup[3];
uns8 config_setup[15];
//During configuration of the receiver, we need DATA1 as an output
PORTA = 0b.0000.0000;
TRISA = 0b.0011.1000; //0 = Output, 1 = Input (DR1 is on RA3) (DATA1 is on RA2)
//Config Mode
CE = 0; CS = 1;
delay_ms(1);
//Setup configuration word, set up for 250k
//config_setup = 0b.0010.0011.0100.1110.0000.0101; //Look at pages 13-15 for more bit info
config_setup[0] = 0b.0000.0101; // freq _chanel+Rx
config_setup[1] = 0b.0100.1110; // 1canal+shockburst+256kbps+16Mhz±5db
config_setup[2] = 0b.0010.0011; // 8bits_endereço+16bit_crc+crc_om
//ADDR1=0,0,0,0,AB
config_setup[3] = 0xAB;
config_setup[4] = 0x00;
config_setup[5] = 0x00;
config_setup[6] = 0x00;
config_setup[7] = 0x00;
//ADDR2
config_setup[8] = 0x00;
config_setup[9] = 0x00;
config_setup[10] = 0x00;
config_setup[11] = 0x00;
config_setup[12] = 0x00;
//LENS
config_setup[13] = 0b.0000.0100;
config_setup[14] = 0b.0000.0000;
//Faz download da configuração para o chip
//for (j = 3; j > 0; j–)
for (j = 15; j > 0; j–)
{
for(i = 0 ; i < 8 ; i++)
{
DATA1 = config_setup[j-1].7;
CLK1 = 1;
CLK1 = 0;
config_setup[j-1] <<= 1;
}
}
//Configuration is actived on falling edge of CS (page 10)
CE = 0; CS = 0;
//After configuration of the receiver, we need DATA1 as an input
PORTA = 0b.0000.0000;
TRISA = 0b.0011.1100; //0 = Output, 1 = Input (DR1 is on RA3) (DATA1 is on RA2)
delay_ms(1);
//Start monitoring the air
CE = 1; CS = 0;
}
//General short delay
void delay_ms(uns16 x)
{
uns8 y, z;
for ( ; x > 0 ; x–)
for ( y = 0 ; y < 4 ; y++)
for ( z = 0 ; z < 176 ; z++);
}
Receiver never receives nothing… If I use the original code with only 3 bytes for configuration it works, but when I use 15 bytes with explicit node hardware configuration it does not receive nothing…
Please, consider help me. A sample source code for the TRF-2.4G v1.0 that uses the full 15 bytes would also be appreciated.
Thank you,
Alex
ENV:
win xp
trf-2.4G euk v1.0 with nRF2401
cc5x free edition