I am working on a project that involves 2 nordic nrf2401A devices that
are found at http://www.sparkfun.com/commerce/produc … cts_id=152 and was wondering if anyone could offer any assistance. I am programming it using C and using a HCS12 Dragon development board. I have constructed a circuit that steps down a 5V output from the HC12 to 2.9 for the nRF device and constructed a circuit that steps up a 3V from the nRF device to 5V for the HC12. I have also written the following 2 c files that write to the devices registers, transmits data and receives it, which is found below. I have tested the voltage to make sure they are at the proper levels for input and output, which they are, and tested the correct sequence of pin values using LED’s and comparing it the timing diagrams on the data sheet. The only problem is they fail to communicate among each other and I can not send a transmission. Using the printf statements I have been able to track where the code flows to and the place it is hung up on is reading the DR1 pin, which constantly says “no data yet.” I have also monitored that pin with a voltmeter and tried to see if that pin goes high, which it does not. So if anyone has any ideas or references that could offer some assistance I’d greatly appreciate it.
#include <mc9s12dp256.h>
#include <stdio.h>
void setupT(void);
void setupR(void);
void sendData(void);
void receiveData(void);
int get_bit(int decimal, int N);
void delayby100ms(int k);
void readLoop(void);
void delayby1ms(int);
/* Transmitter
PORT P
P0 = Chip Select
P1 = Chip Enable
P2 = Clock
P3 = Data Out
P4 = DR1
P5 = Data In
Receiver
PORT T
T0 = Chip Select
T1 = Chip Enable
T2 = Clock
T3 = Data Out
T4 = DR1
T5 = Data In
*/
void setupT(void) /************************************************/
{
int config[15] = {0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x22,
0x33,0x44,0x55,0x66,0xA3,0x4F,0xAE}; //Configure Registers
int x,i,j;
DDRP = 0x0F; // configures the lower part of Port P for output
// configures the upper part of Port P for input
PTP = 0x01; // Activate CS
delayby1ms(1); // Allow time for CS to settle - min 5us/max na
for(j=0;j<15;j++)
{
for(i=8;i>0;i--)
{
x = get_bit(config[j],i); // get value of bit in current char
//printf("x = %d, i = %d, j = %d",x,i,j);
//puts("\n\r");
if(x == 1) // if i bit of config[j] is 1 output a high on DAT
{
PTP = 0x09; // Puts a HIGH on CS (Data High, Clock Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTP = 0x0D; // Puts a HIGH on CS, DATA (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
else
{
PTP = 0x01; // Puts a HIGH on CS (Data Low, Clock Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTP = 0x05; // Puts a HIGH on CS (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
}
}
PTP = 0x00; // Deactivate CS to activate configuration
delayby1ms(1); // Allow time for all values to be low
puts("The Transmitter Registers are Set!\n\r");
} /****************************************************************/
void setupR(void) /************************************************/
{
char config[15] = {0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x22,
0x33,0x44,0x55,0x66,0xA3,0x4F,0xAF};
int x,i,j;
DDRT = 0x0F; // configures the lower part of Port T for output
// configures the upper part of Port T for input
PTT = 0x01; // Activate Chip Select
delayby1ms(1); // Allow time for Chip Enable to settle
for(j=0;j<15;j++)
{
for(i=8;i>0;i--)
{
x = get_bit(config[j],i); // get value of bit in current char
//printf("x = %d, i = %d, j = %d",x,i,j);
//puts("\n\r");
if(x == 1) // if i bit of config[j] is 1 output a high on DAT
{
PTT = 0x09; // Puts a HIGH on CS (Data High, Clock Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTT = 0x0D; // Puts a HIGH on CS, DATA (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
else
{
PTT = 0x01; // Puts a HIGH on CS (Data Low, Clock Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTT = 0x05; // Puts a HIGH on CS (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
}
}
PTT = 0x00; // Set all pin values low
delayby1ms(1); // Allow time for all pin values to be low
PTT = 0x02; // Activate CE to start monitoring air
puts("The Receiver Register are Set!\n\r");
} /****************************************************************/
void sendData(void) /**********************************************/
{
int data[10] = {0x34,0x52,0x19,0x00,0xFF,
0xAD,0xFA,0x04,0x19,0x47}; // 10 char code to be sent
int address[5] = {0x22,0x33,0x44,0x55,0x66}; // address of receiver
int x,i,j;
PTP = 0x02; // Activate CE
delayby1ms(1); // Allow time to settle - min 5 us/max na
for(j=0;j<5;j++) // Clocks in address to the nRF
{
for(i=8;i>0;i--) // Clocks in each bit of the current char of address
{
x = get_bit(address[j],i); // get value of bit in address
//printf("x = %d, i = %d, j = %d",x,i,j);
//puts("\n\r");
if(x == 1) // if i bit of config[j] is 1 output a high on DAT
{
PTP = 0x0A; // Puts a HIGH on CE (Data High, Clock Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTP = 0x0E; // Puts a HIGH on CE, DATA (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
else
{
PTP = 0x02; // Puts a HIGH on CE (Data Low, Clock Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTP = 0x06; // Puts a HIGH on CE (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
}
}
for(j=0;j<10;j++) // Clocks in data to the nRF
{
for(i=8;i>0;i--) // Clocks in each bit of the current char of data
{
x = get_bit(data[j],i); // get value of bit in current char
//printf("x = %d, i = %d, j = %d",x,i,j);
//puts("\n\r");
if(x == 1) // if i bit of config[j] is 1 output a high on DAT
{
PTP = 0x0A; // Puts a HIGH on CE (Data High)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTP = 0x0E; // Puts a HIGH on CE, DATA (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
else
{
PTP = 0x02; // Puts a HIGH on CE (Data Low)
delayby1ms(1); // Setup Delay - min 500ns/max na
PTP = 0x06; // Puts a HIGH on CE (Clock High)
delayby1ms(1); // Hold Delay - min 500ns/max na
} // Clock High for a min of 500ns/max na
}
}
puts("Data was sent!\n\r");
PTP = 0x00; // Deactivates CE to start transmission
} /****************************************************************/
void receiveData(void) /*******************************************/
{
char temp,x,DR1,data[10];
int i,j;
//PTT = 0x00; // turn off chip enable, deactivate RF front end
for(i=0;i<10;i++) // using 10 byte payloads
{
for(j=0;j<8;j++) // 8 bits per byte
{
temp <<= 1; // bitwise shift of one
//x = PTP&FE; // assign value of P0(data1) to x
//temp |= x; // Does bitwise OR of temp and value of x
temp |= PTT&0x20; // Takes value on T5 and ORS it with the bit of temp
PTT = 0x04; // cycle clock high
delayby1ms(1);
PTT = 0x00; // cycle clock low
delayby1ms(1);
}
data[i] = temp; // assign temp char to data array
}
x = PTT&0x10; // read T1(DR1); should be low after all payload data
if(x == 0x10) // is clocked out of transeiver
{
puts("DR1 went low!\n\r");
}
printf("\n\rData Received:\n\r", 0);
printf("[0] : %h\n\r", data[0]);
printf("[1] : %h\n\r", data[1]);
printf("[2] : %h\n\r", data[2]);
printf("[3] : %h\n\r", data[3]);
printf("[0] : %h\n\r", data[4]);
printf("[1] : %h\n\r", data[5]);
printf("[2] : %h\n\r", data[6]);
printf("[3] : %h\n\r", data[7]);
printf("[2] : %h\n\r", data[8]);
printf("[3] : %h\n\r", data[9]);
PTT = 0x02; // activates chip enable, and RF front end
} /****************************************************************/
void readLoop(void) /**********************************************/
{
char x;
while(1)
{
x = PTT&0x10; // Check to see if DR1 went high
if(x == 0x10) // Enter loop if DR1 went high
{
puts("DR1 went High!\n\r");
receiveData();
}
else
{
puts("No data yet\n\r");
}
delayby100ms(10);
}
} /****************************************************************/
int get_bit(int decimal, int N) /**********************************/
{
int constant = 1 << (N-1);
if( decimal & constant )
{
return 1;
}
return 0;
} /****************************************************************/
#include <mc9s12dp256.h>
#include <stdio.h>
void setupT(void);
void setupR(void);
void sendData(void);
void readLoop(void);
void main()
{
setupT();
setupR();
while(1)
{
sendData();
readLoop();
}
return;
}