|
|
View previous topic :: View next topic |
Author |
Message |
yuripace
Joined: 26 Nov 2013 Posts: 21
|
|
Posted: Fri Jan 31, 2014 12:28 pm |
|
|
Eduardo__ wrote: | yes, I suggest you copy RF24_default_config() to your program, and change function name and parameters as you want to.
Try to not change driver files(only change if you want to improve something or fix some bug, in this case a new release). |
can you please give me an hand? :(
This is my custom config function
Code: |
void myRF24_default_config() { //Ititializes default configuration for chip nRF24L01+
#ifdef RF24_USE_DMA
DMA_default_config(); //Sets default DMA configuration
#endif
RF24_disable();
RF24_comm(W_REGISTER|CONFIGURATION, EN_CRC|CRC16|PWR_UP);
RF24_PWUPDELAY();
RF24_comm(W_REGISTER|EN_AUTOACK, 0b00011111); //autoack in pipe 0,1,2,3,4 and 5
RF24_comm(W_REGISTER|EN_RXPIPES, 0b00000011); //****enable only pipes 0 and 1(pipes 2 to 5 are not used)
RF24_comm(W_REGISTER|SETUP_ADDRESSWIDTH, 1);
RF24_comm(W_REGISTER|SETUP_AUTORETRANSMISSION, 0b00011111);
RF24_comm(W_REGISTER|RF_CHANNEL, 0x05);
RF24_comm(W_REGISTER|RF_SETUP, RF_DR_1Mbps|RF_PWR_0dBm);
RF24_comm(W_REGISTER|STATUS,IRQ_RX_dataready|IRQ_TX_datasent|IRQ_MAX_retransmit); //Clear these tree interrupts
RF24_comm_out(W_REGISTER|RX_ADDR_P0, '0x1c000', 5 );
RF24_comm_out(W_REGISTER|RX_ADDR_P1, '0x2c000', 5 );
RF24_comm_out(W_REGISTER|RX_ADDR_P2, '0x3c000', 5);
RF24_comm_out(W_REGISTER|RX_ADDR_P3, '0x4c000', 5);
RF24_comm_out(W_REGISTER|RX_ADDR_P4, '0x5c000', 5);
RF24_comm_out(W_REGISTER|RX_ADDR_P5, '0x6c000', 5);
RF24_comm_out(W_REGISTER|TX_ADDR, "0x1c000", 5 );
RF24_comm(W_REGISTER|RX_PW_P0, 32);
RF24_comm(W_REGISTER|RX_PW_P1, 32);
RF24_comm(W_REGISTER|RX_PW_P2, 32);
RF24_comm(W_REGISTER|RX_PW_P3, 32);
RF24_comm(W_REGISTER|RX_PW_P4, 32);
RF24_comm(W_REGISTER|RX_PW_P5, 32);
RF24_comm(W_REGISTER|EN_DYNAMIC_PAYLOAD, 0b00111111);
RF24_comm(W_REGISTER|DYN_PAYLOAD_CONFIG, EN_DPL|EN_ACK_PAY|EN_DYN_ACK);
RF24_comm(W_REGISTER|FLUSH_RX);
RF24_comm(W_REGISTER|FLUSH_TX);
RF24_STATUS_clr_IRQs(IRQ_ALL);
RF24_disable();
}//
|
is there any params missing or wrong according to the raspy config posted above? |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Sat Feb 01, 2014 11:30 am |
|
|
I´ve no time now for checking your code... but I detected an error here:
Code: | RF24_comm_out(W_REGISTER|RX_ADDR_P0, '0x1c000', 5 ); |
0x1c000 is only 20bits... but your are trying to write 40bits(5 bytes), So 0x1c000 will be a corrupted value.
To correct that You can write 5 bytes in string format(e.g. "chan0") or byte by byte in a buffer, for example:
Code: |
char buff[5];
buff[0]=0x0a; buff[1]=0x0a; buff[2]=0x0a; buff[3]=0x0a; buff[4]=0x01;
RF24_comm_out(W_REGISTER|RX_ADDR_P0, '0x1c000', 5 );
|
I´ve not tested, but maybe it can work in another way:
Code: | RF24_comm_out(W_REGISTER|RX_ADDR_P0, 0x0a0a0a0a01, 5 );
|
good luck _________________ Eduardo Guilherme Brandt |
|
|
Maniac0Maniac2
Joined: 26 Feb 2014 Posts: 6
|
MAX_Retrys_Reached causing chip to hang! |
Posted: Sat Mar 15, 2014 7:24 pm |
|
|
Hi Eduardo,
Thanks for the driver and all the work you've put into it... Works a treat!
I've been banging my head for weeks on this one and it's finally time to ask for help! I'm trying to get multiple transmitters sending to a single receiver on the same channel with about 1 second delay between transmissions. It works for the most part but I'm seeing lock-ups.
I have a transmitter (call it transmitter A) and receiver working perfectly using the first two code snippets. If I pull the power on the receiver, transmitter A hits the max retry, but recovers as soon as I power the receiver back on... all as expected.
The problem comes in when I run the third snippet of code on an additional transmitter (call it transmitter B). When I power Transmitter B up for 10 seconds, Transmitter A hits max retry because of the interference on the same RF channel - again as expected. However, when I remove power from Transmitter B, Transmitter A stays locked up for some reason, reporting IRQ_MAX_retransmit (0b00010000) on the status register.
I just don't know any more! Any help will be appreciated.
Code: | //Receiver
while (true) {
RF24_RX_getbuffer(&RXpipe, &RXdatasize, RXbuffer1);
} |
Code: | //Transmitter
while(1){
//Send data
ret = RF24_TX_putbuffer(false, 20, "La cucaracha!!, Fill"); //Transmit 32bytes data(text string) to actual address(default_config address)
while (true) {
while (RF24_IRQ_state() == false); //Waits for any interrupt
stat = RF24_get_status();
if (RF24_STATUS_TX_datasent_IRQ(stat)) break; //Fifo 1 transfered
else { //if (RF24_STATUS_MAX_retrys_reached_IRQ(stat)) {
RF24_FLUSH_TX();
delay_ms(1);
break;
}
}
RF24_STATUS_clr_IRQs(IRQ_ALL);
} |
Code: | //Interference
int stat=0,ret;
unsigned int xx;
xx = 0;
char Target[3];
while(1){
xx = xx + 1;
Target = "";
sprintf(Target,"%03u",xx);
RF24_TX_putbuffer(false,sizeof(Target), Target);
while(!RF24_IRQ_state()){;} //Waits for any interrupt.
stat=RF24_get_status(); //Read the status register
if (!RF24_STATUS_TX_datasent_IRQ(stat)){
RF24_FLUSH_TX(); //Clear TX buffer
delay_ms(1);
}
RF24_STATUS_clr_IRQs(IRQ_ALL); //Allows clearing all IRQs at the same time
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Mar 15, 2014 7:51 pm |
|
|
Quote: | char Target[3];
sprintf(Target,"%03u",xx); |
Your array is only 3 bytes long, but you have told printf to print
3 characters (and fill it out with leading zeros if necessary).
But then, sprintf creates a string. A string always ends with 0x00.
So in reality your sprintf line writes 4 bytes to an array that is only
declared as 3 bytes long. That means whatever variable that
comes after the Target array will be over-written and it's contents lost.
It could be one of your variables or it could be a compiler scratch variable
or anything. But it's not good.
Increase the array size to 4. |
|
|
Maniac0Maniac2
Joined: 26 Feb 2014 Posts: 6
|
|
Posted: Sun Mar 16, 2014 6:33 pm |
|
|
Ah... missed that one. Thanks for pointing it out PCM Programmer! Fixed it, and checked the rest of the code where it might have happened.
It did not fix the original problem, but you probably saved me a headache later on. |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Mon Mar 17, 2014 7:33 am |
|
|
Dear Maniac,
I'm very happy you're using the driver I developed. It's good to know I'm contributing to someone in this world!
Well, I've to tell you I'm very busy this time for helping you, so I'll help as I can. It's a long time I stopped playing with my nRF transmitters. Someday I've checked some wrong things like that you wrote, but I've not found what really was the problem.
I can suggest you try to turn of the power amplifier, wait a ms, and than turn on again and try to transmit.
Another trick can be check the state of the others nRF24 registers. There is a function for checking that inside the driver. It's name is "RF24_check_config()". If you've a debugger you'll be able to stop and see registers contents. Or you can create a RS232 serial output for checking that.
I think that the problem can comes from two things:
1-It can be some dust inside registers;
2-Maybe there is something configured wrongly in nRF startup. Sorry my driver is not perfect. ;(
Thanks for cooperation and let me know what happened after your new tests.
Good luck friend! _________________ Eduardo Guilherme Brandt |
|
|
kubanec
Joined: 19 Mar 2014 Posts: 2
|
ack payload NRF24l01+ problem |
Posted: Wed Mar 19, 2014 1:20 pm |
|
|
Hello everyone.
I have strange problem with my NRF24l01+ modules. I use two discovery boards with STM32F407 microcontrolers and modules are connected through standard SPI interface.
One way data transmition works as expected but ack packets with payload doesn't work for me.
Basically I have this configuration:
1) on PTX opened TX pipe TX_PIPE and RX_PIPE0 have same address
2) on PRX opened RX pipe RX_PIPE0 has same address as above
3) Enable Pipe0, Auto acknowledge
4) SETUP_RETR: 2000us, 10 retransmit
5) RF_SETUP: 1MBit/s (have tried with 2 mbps without success as well)
6) FEATURE: enable ack payload, dynamic payload
7) DYNPD: enable dynamic payload pipe 0 (have tried all pipes and every other single pipe - no success)
I suppose the ack packet with payload is send by PRX because I am able to put ack payload into the tx FIFO and fifo becomes NON empty, then PTX sends the packet, PRX recieves it (RX_DR becomes 1) and ack payload is also sent by PRX because TX_DS in STATUS becomes also 1 and the TX FIFO becomes empty... But on the PTX side there is no assert of RX_DR and the RX fifo is still empty.
There is also one issue I don't understand: I write value 0x6 to the FEATURE register (to enable dynamic packet and ack payload) and I read out value 0x4 (ACTIVATE,0x73 has no effect on this issue) - so I don't even know if this integrated circuit has the feature.
Then I have other NRF24L01+ modules with different serial number - I write to FEATURE register 0x6 and read out 0x0 - ACTIVATE has no effect. - I really don't understand this behavior.
Thank you for your help. |
|
|
Maniac0Maniac2
Joined: 26 Feb 2014 Posts: 6
|
|
Posted: Wed Mar 19, 2014 7:34 pm |
|
|
Hi Eduardo
I followed your advice on using RF24_check_config and noticed something odd on the status register... Hold on to your hat... This is a mouth full...
If I only use 1 transmitter, the status register looks like this (as expected) before and after transmission:
Before -- 00001110 (No IRQ's & RX_Buffer_Empty)
After ---- 00101110 (IRQ_TX_datasent & RX_Buffer_Empty)
When I power up the 2nd transmitter, I get the above sequence as expected, but then suddenly it looks like I received data from somewhere:
Before -- 00001110 (No IRQ's & RX_Buffer_Empty)
After ---- 01100000 (IRQ_RX_dataready,IRQ_TX_datasent)
Subsequent transmissions looks like this (same as with only 1 transmitter, but now there is data in the buffer);
Before -- 00000000 (No IRQ's & data on RX_PIPE0)
After ---- 00100000 (IRQ_TX_datasent & data on RX_PIPE0)
However if I receive this random data 2 more times (so 3 times in total - I guess it's filling up the RX buffer), the status register changes as below as soon as I try to transmit. When this happens, the IRQ_MAX_retransmit goes to 15 and no matter what I do I can't transmit any more.
Before -- 00000000 (No IRQ's & data on RX_PIPE0)
After ---- 00010000 (IRQ_MAX_retransmit & data on RX_PIPE0)
I'm a little stumped why this happens! I found that if I don't let the RX buffer fill up I can work around the problem, so I'm calling this at the end of each transmission. It kind of works but It's probably not the right solution.
if (RF24_STATUS_RX_dataready_IRQ(stat)){RF24_FLUSH_RX();}
Any thoughts?
After all of that I have another question to add if I may! In your example code, you show how to send by filling the TX FIFO buffers, but there is no example on how to receive additional data in the RX FIFO buffers.
In your RF24_RX_getbuffer routine you check that RF24_IRQ_state is true before running the routine, but am I right in thinking that RF24_IRQ_state gets cleared after reading RX FIFO 1? How do I read the other two transmissions stuck in the buffer?
Sorry for the long complicated post, and once again thanks for the help! |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
Re: ack payload NRF24l01+ problem |
Posted: Fri Mar 21, 2014 9:46 pm |
|
|
kubanec wrote: |
One way data transmition works as expected but ack packets with payload doesn't work for me.
. |
Dear Kubanec...
Do you mean payload with ack or ack with payload? I think the first.
I think your FEATURE_REGISTER is mine DYN_PAYLOAD_CONFIG(DYnamic Payload Configuration register).
In the 1st page of this forum, please save and read header file. It will help you very much. I constructed the header file with descriptions...
e.g.:
Code: | enum RF24_DYN_PAYLOAD_CONFIG { //(DPL)Dynamic payload length feature configuration register. Enable to be able to transmit variable data lenght packets(from 1 to 32 data bytes)
EN_DPL =0b00000100, //Enables Dynamic Payload Length(General DPL enable)
EN_ACK_PAY =0b00000010, //Enables Payload with ACK
EN_DYN_ACK =0b00000001, //Enables the W_TX_PAYLOAD_NOACK command
EN_DPL_ALL =0b00000111 //All DPL functions enabled
}; |
Good luck _________________ Eduardo Guilherme Brandt |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Fri Mar 21, 2014 10:08 pm |
|
|
Dear Maniac
Just one question? All of them are transmiting to just the same receiver, correct? So, you leave off all the receivers and transmitters, except one receiver and one transmitter at a time, do you? Broadcast is possible only without ack returning.
--
About fifo buffers, the function RF24_driver_use_example_RXdata() reads data from all the 3 buffers, while data there is, the function reads data.
Fifo buffers are automatic, dont worry about from what buffer you re reading. You ve enough time for reading nRF buffers while he is receiving and filling anothers.
With a 10MHz SPI, using a uC with DMA, 3 fifo buffers in nRF, I achieved about 2.2Mbps without ack and 750kbps with ack.
Stay in touch friend. Good luck! _________________ Eduardo Guilherme Brandt |
|
|
kubanec
Joined: 19 Mar 2014 Posts: 2
|
|
Posted: Mon Mar 24, 2014 2:35 pm |
|
|
Dear Eduardo.
I looked into your codes and it didn't help me. I have also searched almost whole internet for this problem and I haven't found anything useful.
Will you please make a simple test for me?
Put value 0x7 to the register DYN_PAYLOAD_CONFIG a try read it back and tell me the value you have read.
Thank you |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Mon Mar 24, 2014 2:42 pm |
|
|
Dear Kubanec,
My examples will not work for your microcontroller.
If you see the 1st page of this forum,.. you will see that I´ve included examples at the botom of the driver main file.
If the header file I made not helps you, you should read nRF datasheet file.
Good luck. _________________ Eduardo Guilherme Brandt |
|
|
Maniac0Maniac2
Joined: 26 Feb 2014 Posts: 6
|
|
Posted: Sun Mar 30, 2014 4:43 pm |
|
|
Hi Eduardo
Yes, it is one receiver, with multiple transmitters, transmitting at random times.
It took me a while, but I think I figured it out! The key was in the random data received in the transmitter's RX buffer that should not be there in the first place!
I'm using Enhanced ShockBurst, so the transmitters flicks into receive mode for a short period to receive the acknowledge, than back to transmitter. It seems that if TX1 is waiting for the ACK, and another transmitter TX2 sends data to the receiver during this period, TX1 will intercept this transmission, because its acting as a receiver!
Now that I know it's happening, I can work around the problem!
--
About the buffers. It looks like I have to read the received data out of the buffer before a second RX buffer entry occurs.
This is what I think is happening:
Data comes in and goes to RXBuffer1...
Some more data comes in and goes to RXBuffer2
Now I call "RF24_RX_getbuffer" to read the first entry...
-- It checks "RF24_STATUS_RX_dataready_IRQ", and finds data waiting.
-- It reads the first buffer entry and runs RF24_STATUS_clr_IRQs(IRQ_RX_dataready)"
Now, I call "RF24_RX_getbuffer" to read the second buffer entry...
-- It checks "RF24_STATUS_RX_dataready_IRQ", and finds NO data waiting as the bit has been cleared when we read the firs buffer entry.
-- Now the data is stuck in the buffer!
... I think! |
|
|
Eduardo__
Joined: 23 Nov 2011 Posts: 197 Location: Brazil
|
|
Posted: Mon Mar 31, 2014 7:19 am |
|
|
Dear maniac, thanks for feedback.
I´ve not worked with my nRF modules anymore for about 1 year... sorry if I´ve no more exact answers for you. But I appreciate the comunity feedback too much.
About transmittion/ack collision, give-me a feedback on how do you solved the protocol problem,... it is of my interest also.
About receiver triple buffer, I´m not sure about how to manage buffers data discharging. Have you looked sth into nRF datasheet?
I´m sorry I´ve not too much time for checking that as I´focused in my master degree studies now...
Thanks a lot my friend!!!
Eduardo _________________ Eduardo Guilherme Brandt |
|
|
jgschmidt
Joined: 03 Dec 2008 Posts: 184 Location: Gresham, OR USA
|
16F690 version of Dezso code |
Posted: Fri May 09, 2014 11:49 am |
|
|
Hi Muhammad (MAKInnovation)
I see from your other posts that maybe you do not have much experience with PIC hardware and software debugging. Even though the codes and hardware setups from both Eduardo and Dezso work, they are not for beginners.
Are you sure your LCD is working? For example do both circuits post a hello message on the LCD when they power up?
I do not use the 16F876A or LCD in my projects so I can not comment on those. I use 16F690 and serial terminals for debugging. For the serial connection I use a USB to Serial cable that has a DB9 connector and then use a terminal program on the PC to display the debugging messages. Pin 5 of the DB9 goes to ground and pin 2 goes to the software uart TX pin.
Code: | // software serial debug port
#use rs232 (invert, baud=9600, xmit=PIN_A2, stream=JGS_DBG) |
is the uart setup. Please note the use of the "invert" parameter. This does not require and interface chips! This is the cheapest, easiest way to get debug output from a PIC.
Below is my Dezso code for the 16F690, formatted in my style. Same file is used for sending and receiving, just change the comments on lines 25 & 26. Current setup continuously sends alternate messages to light alternate LEDs. I used this for range testing so I could walk around with the receiver. There is also code in there for using push buttons. The range on these things is terrible! 2.4GHz is best for line of sight. Thick walls, dirt and trees interfere, even with whip antennas. I've abandoned these radios and gone on to others with better penetration (433 and 915 mhz).
I recommend you start with my or dezso's code WITHOUT MAKING ANY CHANGES. Once they work, make very a small change and test. Keep repeating. As you can see from the file date, it's been a year since I looked at this. I still have the prototype boards though and they still work fine.
Good luck.
Code: | #case
//------ 690NRF-A.c ------
//------ from DevXP (dezso) - CCS Forum Code Library #47351
//------ prom page 9, 8 MAR 2013
//
// ************ 3.3 V O L T S ******************
//
// 2013.05.10 - JGS modified for 16F690
//
#include <16F690.h>
#FUSES NOMCLR //Master Clear pin used for I/O
#FUSES NOPROTECT
#FUSES NOWDT //No Watch Dog Timer
#FUSES INTRC //Internal RC Osc, no output
#use delay(internal=8M)
// software serial debug port
#use rs232 (invert, baud=9600, xmit=PIN_A2, stream=JGS_DBG)
//-----------------------------------------------------------------------------
//------ change this for Rx/Tx ------
//#define TX_Mode // setup as Rx
#define TX_Mode // setup as Tx
//-----------------------------------------------------------------------------
//------ NRF24L01+ Defines ------
#define W_REGISTER 0x20
#define R_RX_PAYLOAD 0x61
#define W_TX_PAYLOAD 0xa0
//-----------------------------------------------------------------------------
//------ define ports
#define SPI_MISO PIN_C6
#define SPI_MOSI PIN_B5
#define SPI_CLK PIN_C7
#define RF24_IRQ PIN_B4
#define RF24_CS PIN_B6
#define RF24_CE PIN_B7
#define LED1 PIN_A5
#define LED2 PIN_A4
#define PB1 PIN_A0 // push buttons
#define PB2 PIN_A3
#define MINDB 3 // debounce count required for button press
int16 b1, b2; // debounce counters
#define RF24_xfer(xdata) bb_xfer(xdata) //Send/receive data through SPI
#define RTX_CSN_Low() output_low(RF24_CS) //Controls bit Chipselect
#define RTX_CSN_High() output_high(RF24_CS) //Controls bit Chipselect
#define RTX_CE_Low() output_low(RF24_CE) //Controls bit Chipenable
#define RTX_CE_High() output_high(RF24_CE) //Controls bit Chipenable
#define RF24_IRQ_state() !input(RF24_IRQ)
static int8 RF_Data[4];
#include <STDLIB.H>
//-----------------------------------------------------------------------------
void pulse_CSN()
{
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
}
int bb_xfer(spi_data)
{
// SPI_MISO
// SPI_MOSI
// SPI_CLK
delay_us(50);
int rt;
int result = 0;
int1 d = 0;
for(rt=0;rt<8;rt++)
{
d = bit_test(spi_data,7-rt);
if(d)
{
output_high(SPI_MOSI);
}
else
{
output_low(SPI_MOSI);
}
delay_us(10);
output_high(SPI_CLK);
delay_us(60);
output_low(SPI_CLK);
delay_us(10);
if(input(SPI_MISO))
{
bit_set(result,6-rt);
}
else
{
bit_clear(result,6-rt);
}
}
output_low(SPI_MOSI);
return(result);
}
//-----------------------------------------------------------------------------
void configure_TX()
{
int i;
RTX_CSN_Low();
RTX_CE_Low();;
bb_xfer(W_REGISTER); // PTX, CRC enabled, mask a couple of ints
bb_xfer(0x38);
pulse_CSN();
delay_ms(2);
//-----------
bb_xfer(0x24); //auto retransmit off
bb_xfer(0x00);
pulse_CSN();;
//-----------
bb_xfer(0x23); //address width = 5
bb_xfer(0x03);
pulse_CSN();
//-----------
bb_xfer(0x26); //data rate = 1MB
bb_xfer(0x07);
pulse_CSN();
//-----------
bb_xfer(0x25); //set channel 2, this is default
bb_xfer(0x02);
pulse_CSN();
//-----------
bb_xfer(0x30); //set address E7E7E7E7E7
for(i=0;i<5;i++)
{
bb_xfer(0xe7);
}
pulse_CSN();
//----------------
bb_xfer(0x21); //disable auto-ack, RX mode
bb_xfer(0x00);
RTX_CSN_High();;
}
//-----------------------------------------------------------------------------
void configure_RX()
{
int i;
RTX_CSN_Low();
RTX_CE_Low();;
bb_xfer(W_REGISTER); //PRX, CRC enabled
bb_xfer(0x39);
pulse_CSN();
delay_ms(2);
//-----------
bb_xfer(0x21); //dissable auto-ack for all channels
bb_xfer(0x00);
pulse_CSN();
//-----------
bb_xfer(0x23); //address width = 5 bytes
bb_xfer(0x03);
pulse_CSN();
//-----------
bb_xfer(0x26); //data rate = 1MB
bb_xfer(0x07);
pulse_CSN();
//-----------
bb_xfer(0x31); //4 byte payload
bb_xfer(0x04);
pulse_CSN();
//-----------
bb_xfer(0x25); //set channel 2
bb_xfer(0x02);
pulse_CSN();
//-----------
bb_xfer(0x30); //set address E7E7E7E7E7
for(i=0;i<=5;i++)
{
bb_xfer(0xe7);
}
pulse_CSN();
//----------------
bb_xfer(W_REGISTER); //PWR_UP = 1
bb_xfer(0x3b);
RTX_CSN_High();;
RTX_CE_High();
}
//-----------------------------------------------------------------------------
void read_Data()
{
int i;
RTX_CSN_Low();
bb_xfer(R_RX_PAYLOAD); //Read RX payload
for(i=0;i<4;i++)
{
RF_Data[i] = bb_xfer(0x00);
fprintf( JGS_DBG, "%c",RF_Data[i]);
}
fprintf( JGS_DBG, "\n");
pulse_CSN();
//-----------
bb_xfer(0xe2); //Flush RX FIFO
pulse_CSN();
//-----------
bb_xfer(0x27); //reset int
bb_xfer(0x40);
RTX_CSN_High();
}
//-----------------------------------------------------------------------------
void transmit_Data()
{
int i;
RTX_CSN_High();
RTX_CSN_Low();
// fprintf( JGS_DBG, "\n%u",bb_xfer(0x27)); //clear previous ints
bb_xfer(0x27);
bb_xfer(0x7e);
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
//-----------
bb_xfer(W_REGISTER); //PWR_UP = 1
bb_xfer(0x3a);
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
//-----------
bb_xfer(0xe1); //clear TX fifo
RTX_CSN_High();;
delay_us(20);
RTX_CSN_Low();
//-----------
// fprintf( JGS_DBG, "\n%u",bb_xfer(0xa0)); //4 byte payload
bb_xfer(W_TX_PAYLOAD);
for(i=0;i<4;i++)
{
bb_xfer(RF_Data[i]); //clock in payload
}
RTX_CSN_High();;
RTX_CE_High();
delay_us(50);
RTX_CE_Low();;
}
//-----------------------------------------------------------------------------
void main()
{
// weak pullups available on PORTA & PORTB
port_a_pullups(0b00001001); // A0, A3
output_toggle(LED1);
RTX_CE_Low();
RTX_CSN_High();
#if defined(TX_Mode)
fprintf( JGS_DBG, "\nTX Hello\n");
delay_ms(500);
output_toggle(LED1);
configure_TX();
delay_ms(100);
while( TRUE )
{
if( input( PB1 ) == 0) {
b1++;
} else {
b1=0;
}
if( input( PB2 ) == 0) {
b2++;
} else {
b2=0;
}
delay_ms(1500);
// if( b1 == MINDB ) {
RF_Data[0]="1";
RF_Data[1]="2";
RF_Data[2]="3";
RF_Data[3]="4";
transmit_Data();
output_toggle(LED1);
// }
delay_ms(1500);
// if( b2 == MINDB ) {
RF_Data[0]="a";
RF_Data[1]="b";
RF_Data[2]="c";
RF_Data[3]="d";
transmit_Data();
output_toggle(LED2);
// }
}
#else //must be rx :)
fprintf( JGS_DBG, "\nRX Hello\n");
delay_ms(500);
output_toggle(LED1);
configure_RX();
delay_ms(100);
while( TRUE )
{
// if( input( RF24_IRQ ) == 0) {
if(!input( RF24_IRQ ) )
{
read_Data();
}
output_toggle(LED1);
// delay_ms(250);
}
#endif
}
//-----------------------------------------------------------------------------
//------ end of 690NRF-A.c ------
|
_________________ Jürgen
www.jgscraft.com |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|