Fix: Due write() issues.
Found that Due would send multiple payloads or fail in writing in some cases. Change ensures single-payload transmission using write(). - Updated pingpair_dyn.ino example sketch to conform with available() changes - Slight doc update
This commit is contained in:
@@ -579,15 +579,13 @@ void RF24::powerUp(void)
|
|||||||
bool RF24::write( const void* buf, uint8_t len )
|
bool RF24::write( const void* buf, uint8_t len )
|
||||||
{
|
{
|
||||||
//Start Writing
|
//Start Writing
|
||||||
startFastWrite(buf,len);
|
startWrite(buf,len);
|
||||||
|
|
||||||
//Wait until complete or failed
|
//Wait until complete or failed
|
||||||
//ACK payloads that are handled improperly will cause this to hang
|
//ACK payloads that are handled improperly will cause this to hang
|
||||||
//If autoAck is ON, a payload has to be written prior to reading a payload, else write after reading a payload
|
//If autoAck is ON, a payload has to be written prior to reading a payload, else write after reading a payload
|
||||||
while( ! ( get_status() & ( _BV(TX_DS) | _BV(MAX_RT) ))) { }
|
while( ! ( get_status() & ( _BV(TX_DS) | _BV(MAX_RT) ))) { }
|
||||||
|
|
||||||
ce(LOW); //Set the radio back to STANDBY-I mode since we can only fill one buffer at a time using this method, and tx is complete
|
|
||||||
|
|
||||||
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
|
||||||
|
|
||||||
//Max retries exceeded
|
//Max retries exceeded
|
||||||
|
|||||||
@@ -263,6 +263,9 @@ public:
|
|||||||
* timeout, and return 1 or 0 respectively. From a user perspective, just
|
* timeout, and return 1 or 0 respectively. From a user perspective, just
|
||||||
* keep trying to send the same data. The library will keep auto retrying
|
* keep trying to send the same data. The library will keep auto retrying
|
||||||
* the current payload using the built in functionality.
|
* the current payload using the built in functionality.
|
||||||
|
* @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto
|
||||||
|
* retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
|
||||||
|
* to clear by issuing txStandBy() or ensure appropriate time between transmissions.
|
||||||
*
|
*
|
||||||
* ONLY max retry interrupt flags will be cleared when writeFast is called
|
* ONLY max retry interrupt flags will be cleared when writeFast is called
|
||||||
*
|
*
|
||||||
@@ -292,6 +295,9 @@ public:
|
|||||||
* It will not block until the 3 FIFO buffers are filled with data.
|
* It will not block until the 3 FIFO buffers are filled with data.
|
||||||
* If so the library will auto retry until a new payload is written
|
* If so the library will auto retry until a new payload is written
|
||||||
* or the user specified timeout period is reached.
|
* or the user specified timeout period is reached.
|
||||||
|
* @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto
|
||||||
|
* retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
|
||||||
|
* to clear by issuing txStandBy() or ensure appropriate time between transmissions.
|
||||||
*
|
*
|
||||||
* ONLY max retry interrupt flags will be cleared when writeBlocking is called
|
* ONLY max retry interrupt flags will be cleared when writeBlocking is called
|
||||||
* @code
|
* @code
|
||||||
@@ -409,6 +415,9 @@ public:
|
|||||||
* @note Optimization: This function now leaves the CE pin high, so the radio
|
* @note Optimization: This function now leaves the CE pin high, so the radio
|
||||||
* will remain in TX or STANDBY-II Mode until a txStandBy() command is issued.
|
* will remain in TX or STANDBY-II Mode until a txStandBy() command is issued.
|
||||||
* This allows the chip to be used to its full potential in TX mode.
|
* This allows the chip to be used to its full potential in TX mode.
|
||||||
|
* @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto
|
||||||
|
* retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
|
||||||
|
* to clear by issuing txStandBy() or ensure appropriate time between transmissions.
|
||||||
*
|
*
|
||||||
* @see write()
|
* @see write()
|
||||||
* @see writeFast()
|
* @see writeFast()
|
||||||
@@ -500,7 +509,20 @@ public:
|
|||||||
bool isValid() { return ce_pin != 0xff && csn_pin != 0xff; }
|
bool isValid() { return ce_pin != 0xff && csn_pin != 0xff; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* The radio will generate interrupt signals when a transmission is complete,
|
||||||
|
* a transmission fails, or a payload is received. This allows users to mask
|
||||||
|
* those interrupts to prevent them from generating a signal on the interrupt
|
||||||
|
* pin.
|
||||||
*
|
*
|
||||||
|
* @code
|
||||||
|
* Mask all interrupts except the receive interrupt:
|
||||||
|
*
|
||||||
|
* radio.maskIRQ(1,1,0);
|
||||||
|
* @endcode
|
||||||
|
*
|
||||||
|
* @param tx_ok Mask transmission complete interrupts
|
||||||
|
* @param tx_fail Mask transmit failure interrupts
|
||||||
|
* @param rx_ready Mask payload received interrupts
|
||||||
*/
|
*/
|
||||||
void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready);
|
void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready);
|
||||||
|
|
||||||
@@ -995,7 +1017,8 @@ private:
|
|||||||
* - Changes to read() functionality have increased reliability and response
|
* - Changes to read() functionality have increased reliability and response
|
||||||
* - Extended timeout periods have been added to aid in noisy or otherwise unreliable environments
|
* - Extended timeout periods have been added to aid in noisy or otherwise unreliable environments
|
||||||
* - Delays have been removed where possible to ensure maximum efficiency
|
* - Delays have been removed where possible to ensure maximum efficiency
|
||||||
* - Untested: Arduino Due and ATTiny 84/85 support: Do NOT #include <SPI.h> with ATTiny.
|
* - Full Due support with extended SPI functions
|
||||||
|
* - Initial ATTiny support added (Untested)
|
||||||
* - More! See the links below and class documentation for more info.
|
* - More! See the links below and class documentation for more info.
|
||||||
*
|
*
|
||||||
* If issues are discovered with the documentation, please report them here: <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a>
|
* If issues are discovered with the documentation, please report them here: <a href="https://github.com/TMRh20/tmrh20.github.io/issues"> here</a>
|
||||||
@@ -1013,6 +1036,15 @@ private:
|
|||||||
* This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
|
* This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
|
||||||
* the SPI hardware will go into 'slave' mode.
|
* the SPI hardware will go into 'slave' mode.
|
||||||
*
|
*
|
||||||
|
* @section BoardSupport Board Support
|
||||||
|
*
|
||||||
|
* Most standard Arduino based boards are supported:
|
||||||
|
* - ATMega 328 based boards (Uno, Nano, etc)
|
||||||
|
* - Mega Boards (1280, 2560, etc)
|
||||||
|
* - ARM based boards (Arduino Due) Note: Do not include printf.h or use printf begin. This functionality is already present. Must use one of the
|
||||||
|
* hardware SS/CSN pins.
|
||||||
|
* - ATTiny boards (Not fully tested) Note: Do not include SPI.h. The SPI functions for ATTiny are already included.
|
||||||
|
*
|
||||||
* @section More More Information
|
* @section More More Information
|
||||||
*
|
*
|
||||||
* @section Info and Projects
|
* @section Info and Projects
|
||||||
|
|||||||
@@ -15,7 +15,7 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include "nRF24L01.h"
|
#include "nRF24L01.h"
|
||||||
#include "RF24.h"
|
#include "RF24.h"
|
||||||
#include "printf.h"
|
//#include "printf.h"
|
||||||
|
|
||||||
//
|
//
|
||||||
// Hardware configuration
|
// Hardware configuration
|
||||||
@@ -27,7 +27,7 @@ RF24 radio(9,10);
|
|||||||
|
|
||||||
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
|
||||||
// Leave open to be the 'ping' transmitter
|
// Leave open to be the 'ping' transmitter
|
||||||
const int role_pin = 7;
|
const int role_pin = 5;
|
||||||
|
|
||||||
//
|
//
|
||||||
// Topology
|
// Topology
|
||||||
@@ -61,7 +61,7 @@ role_e role;
|
|||||||
|
|
||||||
const int min_payload_size = 4;
|
const int min_payload_size = 4;
|
||||||
const int max_payload_size = 32;
|
const int max_payload_size = 32;
|
||||||
const int payload_size_increments_by = 2;
|
const int payload_size_increments_by = 1;
|
||||||
int next_payload_size = min_payload_size;
|
int next_payload_size = min_payload_size;
|
||||||
|
|
||||||
char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char
|
char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char
|
||||||
@@ -74,7 +74,7 @@ void setup(void)
|
|||||||
|
|
||||||
// set up the role pin
|
// set up the role pin
|
||||||
pinMode(role_pin, INPUT);
|
pinMode(role_pin, INPUT);
|
||||||
digitalWrite(role_pin,HIGH);
|
digitalWrite(role_pin,LOW);
|
||||||
delay(20); // Just to get a solid reading on the role pin
|
delay(20); // Just to get a solid reading on the role pin
|
||||||
|
|
||||||
// read the address pin, establish our role
|
// read the address pin, establish our role
|
||||||
@@ -88,7 +88,7 @@ void setup(void)
|
|||||||
//
|
//
|
||||||
|
|
||||||
Serial.begin(57600);
|
Serial.begin(57600);
|
||||||
printf_begin();
|
//printf_begin();
|
||||||
printf("\n\rRF24/examples/pingpair_dyn/\n\r");
|
printf("\n\rRF24/examples/pingpair_dyn/\n\r");
|
||||||
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
printf("ROLE: %s\n\r",role_friendly_name[role]);
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ void setup(void)
|
|||||||
radio.enableDynamicPayloads();
|
radio.enableDynamicPayloads();
|
||||||
|
|
||||||
// optionally, increase the delay between retries & # of retries
|
// optionally, increase the delay between retries & # of retries
|
||||||
radio.setRetries(15,15);
|
radio.setRetries(5,15);
|
||||||
|
|
||||||
//
|
//
|
||||||
// Open pipes to other nodes for communication
|
// Open pipes to other nodes for communication
|
||||||
@@ -189,7 +189,7 @@ void loop(void)
|
|||||||
next_payload_size = min_payload_size;
|
next_payload_size = min_payload_size;
|
||||||
|
|
||||||
// Try again 1s later
|
// Try again 1s later
|
||||||
delay(1000);
|
delay(100);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
@@ -204,11 +204,11 @@ void loop(void)
|
|||||||
// Dump the payloads until we've gotten everything
|
// Dump the payloads until we've gotten everything
|
||||||
uint8_t len;
|
uint8_t len;
|
||||||
bool done = false;
|
bool done = false;
|
||||||
while (!done)
|
while (radio.available())
|
||||||
{
|
{
|
||||||
// Fetch the payload, and see if this was the last one.
|
// Fetch the payload, and see if this was the last one.
|
||||||
len = radio.getDynamicPayloadSize();
|
len = radio.getDynamicPayloadSize();
|
||||||
done = radio.read( receive_payload, len );
|
radio.read( receive_payload, len );
|
||||||
|
|
||||||
// Put a zero at the end for easy printing
|
// Put a zero at the end for easy printing
|
||||||
receive_payload[len] = 0;
|
receive_payload[len] = 0;
|
||||||
Reference in New Issue
Block a user