Fix: txStandBy hang. Updated Transfer example
- txStandBy was hanging if the last of the data timed out. Now clears the MAX_RT flag if timed out - Finished updating example file Transfer.ino for demonstrating half-rate transfers using the FIFO buffers
This commit is contained in:
@@ -553,6 +553,10 @@ bool RF24::txStandBy(){
|
|||||||
ce(LOW);
|
ce(LOW);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
if( get_status() & _BV(MAX_RT)){
|
||||||
|
write_register(STATUS,_BV(MAX_RT) );
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -270,7 +270,7 @@ public:
|
|||||||
void stopListening(void);
|
void stopListening(void);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimization: Improved performance and reliability
|
* @note Optimization: Improved performance and reliability
|
||||||
* Write to the open writing pipe
|
* Write to the open writing pipe
|
||||||
*
|
*
|
||||||
* Be sure to call openWritingPipe() first to set the destination
|
* Be sure to call openWritingPipe() first to set the destination
|
||||||
@@ -293,16 +293,17 @@ public:
|
|||||||
bool write( const void* buf, uint8_t len );
|
bool write( const void* buf, uint8_t len );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimization: New Command
|
* @note Optimization: New Command
|
||||||
* Write to the open writing pipe filling up the FIFO buffers
|
* Write to the open writing pipe filling up the FIFO buffers
|
||||||
*
|
*
|
||||||
* Be sure to call openWritingPipe() first to set the destination
|
* Be sure to call openWritingPipe() first to set the destination
|
||||||
* of where to write to.
|
* of where to write to.
|
||||||
*
|
*
|
||||||
* This will not block until the 3 FIFO buffers are filled with data.
|
* This will not block until the 3 FIFO buffers are filled with data.
|
||||||
* Once the FIFOs are full, writeFast will simply return 0. From a user
|
* Once the FIFOs are full, writeFast will simply wait for success or
|
||||||
* perspective, just keep trying to send the same data. The library will
|
* timeout, and return 1 or 0 respectively. From a user perspective, just
|
||||||
* keep auto retrying the previous payload using the built in functionality.
|
* keep trying to send the same data. The library will keep auto retrying
|
||||||
|
* the current payload using the built in functionality.
|
||||||
*
|
*
|
||||||
* The maximum size of data written is the fixed payload size, see
|
* The maximum size of data written is the fixed payload size, see
|
||||||
* getPayloadSize(). However, you can write less, and the remainder
|
* getPayloadSize(). However, you can write less, and the remainder
|
||||||
@@ -317,7 +318,7 @@ public:
|
|||||||
bool writeFast( const void* buf, uint8_t len );
|
bool writeFast( const void* buf, uint8_t len );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimization: New Command
|
* @note Optimization: New Command
|
||||||
* Write to the open writing pipe
|
* Write to the open writing pipe
|
||||||
*
|
*
|
||||||
* Be sure to call openWritingPipe() first to set the destination
|
* Be sure to call openWritingPipe() first to set the destination
|
||||||
@@ -344,7 +345,7 @@ public:
|
|||||||
bool writeBlocking( const void* buf, uint8_t len );
|
bool writeBlocking( const void* buf, uint8_t len );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Optimization: New Command
|
* @note Optimization: New Command
|
||||||
* This function should be called as soon as transmission is finished to
|
* This function should be called as soon as transmission is finished to
|
||||||
* drop the radio back to STANDBY-I mode. If not issued, the radio will
|
* drop the radio back to STANDBY-I mode. If not issued, the radio will
|
||||||
* remain in STANDBY-II mode which, per the data sheet, is not a recommended
|
* remain in STANDBY-II mode which, per the data sheet, is not a recommended
|
||||||
@@ -781,8 +782,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @example GettingStarted.pde
|
* @example GettingStarted.ino
|
||||||
*
|
* Updated: TMRh20
|
||||||
* This is an example which corresponds to my "Getting Started" blog post:
|
* This is an example which corresponds to my "Getting Started" blog post:
|
||||||
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>.
|
* <a style="text-align:center" href="http://maniacbug.wordpress.com/2011/11/02/getting-started-rf24/">Getting Started with nRF24L01+ on Arduino</a>.
|
||||||
*
|
*
|
||||||
@@ -793,6 +794,17 @@ public:
|
|||||||
* node can then see how long the whole cycle took.
|
* node can then see how long the whole cycle took.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @example Transfer.ino
|
||||||
|
* Updated: TMRh20
|
||||||
|
* This example demonstrates half-rate transfer using the FIFO buffers
|
||||||
|
*
|
||||||
|
* It is an example of how to use the RF24 class. Write this sketch to two
|
||||||
|
* different nodes. Put one of the nodes into 'transmit' mode by connecting
|
||||||
|
* with the serial monitor and sending a 'T'. The data transfer will begin,
|
||||||
|
* with the receiver displaying the payload count. (32Byte Payloads)
|
||||||
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @example nordic_fob.pde
|
* @example nordic_fob.pde
|
||||||
*
|
*
|
||||||
@@ -812,7 +824,7 @@ public:
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @example pingpair.pde
|
* @example pingpair.ino
|
||||||
*
|
*
|
||||||
* This is an example of how to use the RF24 class. Write this sketch to two
|
* This is an example of how to use the RF24 class. Write this sketch to two
|
||||||
* different nodes, connect the role_pin to ground on one. The ping node sends
|
* different nodes, connect the role_pin to ground on one. The ping node sends
|
||||||
|
|||||||
@@ -19,105 +19,92 @@ TMRh20 2014
|
|||||||
#include "RF24.h"
|
#include "RF24.h"
|
||||||
#include "printf.h"
|
#include "printf.h"
|
||||||
|
|
||||||
|
/************* USER Configuration *****************************/
|
||||||
// Hardware configuration
|
// Hardware configuration
|
||||||
// Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
RF24 radio(48,49); // Set up nRF24L01 radio on SPI bus plus pins 9 & 10
|
||||||
|
boolean RADIO_NO = 0; //SET THIS TO 0 or 1 for 1st or 2nd radio
|
||||||
|
|
||||||
RF24 radio(48,49);
|
/***************************************************************/
|
||||||
|
|
||||||
// Topology
|
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL }; // Radio pipe addresses for the 2 nodes to communicate.
|
||||||
// Radio pipe addresses for the 2 nodes to communicate.
|
|
||||||
const uint64_t pipes[2] = { 0xABCDABCD71LL, 0x544d52687CLL };
|
|
||||||
|
|
||||||
// Role management
|
byte data[32]; //Data buffer for testing data transfer speeds
|
||||||
// Set up role. This sketch uses the same software for all the nodes
|
|
||||||
// in this system. Doing so greatly simplifies testing.
|
|
||||||
|
|
||||||
// The various roles supported by this sketch
|
unsigned long counter, rxTimer; //Counter and timer for keeping track transfer info
|
||||||
typedef enum { role_TX = 1, role_RX } role_e;
|
|
||||||
|
|
||||||
// The debug-friendly names of those roles
|
|
||||||
const char* role_friendly_name[] = { "invalid", "Ping out", "Pong back"};
|
|
||||||
|
|
||||||
//Set this to determine the default role of the current running sketch
|
|
||||||
role_e role = role_RX;
|
|
||||||
|
|
||||||
//Data buffer for testing data transfer speeds
|
|
||||||
byte data[32];
|
|
||||||
|
|
||||||
//Counter and timer for keeping track transfer info
|
|
||||||
unsigned long counter, rxTimer;
|
|
||||||
float startTime, stopTime;
|
float startTime, stopTime;
|
||||||
|
bool TX=1,RX=0,role=0;
|
||||||
|
|
||||||
void setup(void)
|
void setup(void) {
|
||||||
{
|
|
||||||
|
|
||||||
Serial.begin(57600);
|
Serial.begin(57600);
|
||||||
printf_begin();
|
printf_begin();
|
||||||
printf("\n\rRF24/examples/GettingStarted/\n\r");
|
|
||||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
|
||||||
printf("*** PRESS 'T' to begin transmitting to the other node\n\r");
|
|
||||||
|
|
||||||
radio.begin(); // Setup and configure rf radio
|
radio.begin(); // Setup and configure rf radio
|
||||||
radio.setChannel(1);
|
radio.setChannel(1);
|
||||||
radio.setPALevel(RF24_PA_MAX);
|
radio.setPALevel(RF24_PA_MAX);
|
||||||
radio.setAutoAck(1); // Ensure autoACK is enabled
|
radio.setAutoAck(1); // Ensure autoACK is enabled
|
||||||
radio.setRetries(2,3); // Optionally, increase the delay between retries & # of retries
|
radio.setRetries(1,1); // Optionally, increase the delay between retries & # of retries
|
||||||
//radio.disableCRC();
|
|
||||||
radio.setCRCLength(RF24_CRC_8);
|
radio.setCRCLength(RF24_CRC_8);
|
||||||
|
|
||||||
|
if(RADIO_NO){ //Lets the two radios choose the correct pipes depending on user selection
|
||||||
|
radio.openWritingPipe(pipes[0]);
|
||||||
|
radio.openReadingPipe(1,pipes[1]);
|
||||||
|
}else{
|
||||||
radio.openWritingPipe(pipes[1]);
|
radio.openWritingPipe(pipes[1]);
|
||||||
radio.openReadingPipe(1,pipes[0]);
|
radio.openReadingPipe(1,pipes[0]);
|
||||||
|
}
|
||||||
|
|
||||||
radio.startListening(); // Start listening
|
radio.startListening(); // Start listening
|
||||||
radio.printDetails(); // Dump the configuration of the rf unit for debugging
|
radio.printDetails(); // Dump the configuration of the rf unit for debugging
|
||||||
|
|
||||||
|
printf("\n\rRF24/examples/Transfer Rates/\n\r");
|
||||||
|
printf("*** PRESS 'T' to begin transmitting to the other node\n\r");
|
||||||
|
|
||||||
randomSeed(analogRead(0)); //Seed for random number generation
|
randomSeed(analogRead(0)); //Seed for random number generation
|
||||||
|
|
||||||
for(int i=0; i<32; i++){
|
for(int i=0; i<32; i++){
|
||||||
data[i] = random(255); //Load the buffer with random data
|
data[i] = random(255); //Load the buffer with random data
|
||||||
}
|
}
|
||||||
radio.powerUp();
|
radio.powerUp(); //Power up the radio
|
||||||
}
|
}
|
||||||
|
|
||||||
void loop(void){
|
void loop(void){
|
||||||
|
|
||||||
|
|
||||||
//TX with pre-blocking writes
|
if(role == TX){
|
||||||
if(role == role_TX){
|
|
||||||
|
|
||||||
delay(1500);
|
delay(1500);
|
||||||
|
|
||||||
printf("Initiating Basic Data Transfer\n\r");
|
printf("Initiating Basic Data Transfer\n\r");
|
||||||
|
|
||||||
|
|
||||||
float cycles = 10000;
|
float cycles = 1000; //Change this to a higher or lower number.
|
||||||
|
|
||||||
startTime = millis();
|
startTime = millis();
|
||||||
|
|
||||||
for(int i=0; i<cycles; i++){
|
for(int i=0; i<cycles; i++){ //Loop through a number of cycles
|
||||||
if(!radio.writeFast(&data,32)){
|
data[0] = i; //Change the first byte of the payload for identification
|
||||||
counter++;
|
if(!radio.writeFast(&data,32)){ //Write to the FIFO buffers
|
||||||
|
counter++; //Keep count of failed payloads
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
stopTime = millis();
|
stopTime = millis();
|
||||||
|
|
||||||
while(!radio.txStandBy()){ }
|
while(!radio.txStandBy()){ } //This should be called to wait for completion and put the radio in standby mode after transmission
|
||||||
|
|
||||||
float numBytes = cycles * 32;
|
float numBytes = cycles * 32;
|
||||||
float rate = numBytes / (stopTime - startTime) / cycles;
|
float rate = numBytes / (stopTime - startTime) / cycles;
|
||||||
|
|
||||||
|
|
||||||
printf("Transfer complete at "); Serial.print(rate); printf(" KB/s \n\r");
|
printf("Transfer complete at "); Serial.print(rate); printf(" KB/s \n\r");
|
||||||
printf("%d of ",counter); Serial.print(cycles); printf(" Packets Failed to Send\n\r");
|
printf("%d of ",counter); Serial.print(cycles); printf(" Packets Failed to Send\n\r");
|
||||||
counter = 0;
|
counter = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if(role == role_RX){
|
if(role == RX){
|
||||||
while(radio.available()){
|
while(radio.available()){
|
||||||
radio.read(&data,32);
|
radio.read(&data,32);
|
||||||
counter++;
|
counter++;
|
||||||
@@ -130,9 +117,7 @@ void loop(void){
|
|||||||
printf("Payload Count: %d \n\r", counter);
|
printf("Payload Count: %d \n\r", counter);
|
||||||
counter = 0;
|
counter = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Change roles
|
// Change roles
|
||||||
//
|
//
|
||||||
@@ -140,23 +125,17 @@ void loop(void){
|
|||||||
if ( Serial.available() )
|
if ( Serial.available() )
|
||||||
{
|
{
|
||||||
char c = toupper(Serial.read());
|
char c = toupper(Serial.read());
|
||||||
if ( c == 'T' && role == role_RX )
|
if ( c == 'T' && role == RX )
|
||||||
{
|
{
|
||||||
printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r");
|
printf("*** CHANGING TO TRANSMIT ROLE -- PRESS 'R' TO SWITCH BACK\n\r");
|
||||||
radio.stopListening();
|
radio.stopListening();
|
||||||
role = role_TX; // Become the primary transmitter (ping out)
|
role = TX; // Become the primary transmitter (ping out)
|
||||||
//radio.openWritingPipe(pipes[0]);
|
|
||||||
//radio.openReadingPipe(1,pipes[1]);
|
|
||||||
}
|
}
|
||||||
else if ( c == 'R' && role == role_TX )
|
else if ( c == 'R' && role == TX )
|
||||||
{
|
{
|
||||||
radio.startListening();
|
radio.startListening();
|
||||||
printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r");
|
printf("*** CHANGING TO RECEIVE ROLE -- PRESS 'T' TO SWITCH BACK\n\r");
|
||||||
|
role = RX; // Become the primary receiver (pong back)
|
||||||
role = role_RX; // Become the primary receiver (pong back)
|
|
||||||
|
|
||||||
//radio.openWritingPipe(pipes[1]);
|
|
||||||
//radio.openReadingPipe(1,pipes[0]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user