Skip to content

Commit afdb084

Browse files
committed
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
1 parent d28323a commit afdb084

File tree

3 files changed

+44
-14
lines changed

3 files changed

+44
-14
lines changed

Diff for: RF24.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -579,15 +579,13 @@ void RF24::powerUp(void)
579579
bool RF24::write( const void* buf, uint8_t len )
580580
{
581581
//Start Writing
582-
startFastWrite(buf,len);
582+
startWrite(buf,len);
583583

584584
//Wait until complete or failed
585585
//ACK payloads that are handled improperly will cause this to hang
586586
//If autoAck is ON, a payload has to be written prior to reading a payload, else write after reading a payload
587587
while( ! ( get_status() & ( _BV(TX_DS) | _BV(MAX_RT) ))) { }
588588

589-
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
590-
591589
uint8_t status = write_register(STATUS,_BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) );
592590

593591
//Max retries exceeded

Diff for: RF24.h

+33-1
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ class RF24
263263
* timeout, and return 1 or 0 respectively. From a user perspective, just
264264
* keep trying to send the same data. The library will keep auto retrying
265265
* the current payload using the built in functionality.
266+
* @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto
267+
* retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
268+
* to clear by issuing txStandBy() or ensure appropriate time between transmissions.
266269
*
267270
* ONLY max retry interrupt flags will be cleared when writeFast is called
268271
*
@@ -292,6 +295,9 @@ class RF24
292295
* It will not block until the 3 FIFO buffers are filled with data.
293296
* If so the library will auto retry until a new payload is written
294297
* or the user specified timeout period is reached.
298+
* @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto
299+
* retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
300+
* to clear by issuing txStandBy() or ensure appropriate time between transmissions.
295301
*
296302
* ONLY max retry interrupt flags will be cleared when writeBlocking is called
297303
* @code
@@ -409,6 +415,9 @@ class RF24
409415
* @note Optimization: This function now leaves the CE pin high, so the radio
410416
* will remain in TX or STANDBY-II Mode until a txStandBy() command is issued.
411417
* This allows the chip to be used to its full potential in TX mode.
418+
* @warning It is important to never keep the nRF24L01 in TX mode for more than 4ms at a time. If the auto
419+
* retransmit is enabled, the nRF24L01 is never in TX mode long enough to disobey this rule. Allow the FIFO
420+
* to clear by issuing txStandBy() or ensure appropriate time between transmissions.
412421
*
413422
* @see write()
414423
* @see writeFast()
@@ -500,7 +509,20 @@ class RF24
500509
bool isValid() { return ce_pin != 0xff && csn_pin != 0xff; }
501510

502511
/**
512+
* The radio will generate interrupt signals when a transmission is complete,
513+
* a transmission fails, or a payload is received. This allows users to mask
514+
* those interrupts to prevent them from generating a signal on the interrupt
515+
* pin.
503516
*
517+
* @code
518+
* Mask all interrupts except the receive interrupt:
519+
*
520+
* radio.maskIRQ(1,1,0);
521+
* @endcode
522+
*
523+
* @param tx_ok Mask transmission complete interrupts
524+
* @param tx_fail Mask transmit failure interrupts
525+
* @param rx_ready Mask payload received interrupts
504526
*/
505527
void maskIRQ(bool tx_ok,bool tx_fail,bool rx_ready);
506528

@@ -995,7 +1017,8 @@ class RF24
9951017
* - Changes to read() functionality have increased reliability and response
9961018
* - Extended timeout periods have been added to aid in noisy or otherwise unreliable environments
9971019
* - Delays have been removed where possible to ensure maximum efficiency
998-
* - Untested: Arduino Due and ATTiny 84/85 support: Do NOT #include <SPI.h> with ATTiny.
1020+
* - Full Due support with extended SPI functions
1021+
* - Initial ATTiny support added (Untested)
9991022
* - More! See the links below and class documentation for more info.
10001023
*
10011024
* 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 @@ class RF24
10131036
* This chip uses the SPI bus, plus two chip control pins. Remember that pin 10 must still remain an output, or
10141037
* the SPI hardware will go into 'slave' mode.
10151038
*
1039+
* @section BoardSupport Board Support
1040+
*
1041+
* Most standard Arduino based boards are supported:
1042+
* - ATMega 328 based boards (Uno, Nano, etc)
1043+
* - Mega Boards (1280, 2560, etc)
1044+
* - 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
1045+
* hardware SS/CSN pins.
1046+
* - ATTiny boards (Not fully tested) Note: Do not include SPI.h. The SPI functions for ATTiny are already included.
1047+
*
10161048
* @section More More Information
10171049
*
10181050
* @section Info and Projects

Diff for: examples/pingpair_dyn/pingpair_dyn.pde renamed to examples/pingpair_dyn/pingpair_dyn.ino

+10-10
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <SPI.h>
1616
#include "nRF24L01.h"
1717
#include "RF24.h"
18-
#include "printf.h"
18+
//#include "printf.h"
1919

2020
//
2121
// Hardware configuration
@@ -27,7 +27,7 @@ RF24 radio(9,10);
2727

2828
// sets the role of this unit in hardware. Connect to GND to be the 'pong' receiver
2929
// Leave open to be the 'ping' transmitter
30-
const int role_pin = 7;
30+
const int role_pin = 5;
3131

3232
//
3333
// Topology
@@ -61,7 +61,7 @@ role_e role;
6161

6262
const int min_payload_size = 4;
6363
const int max_payload_size = 32;
64-
const int payload_size_increments_by = 2;
64+
const int payload_size_increments_by = 1;
6565
int next_payload_size = min_payload_size;
6666

6767
char receive_payload[max_payload_size+1]; // +1 to allow room for a terminating NULL char
@@ -74,7 +74,7 @@ void setup(void)
7474

7575
// set up the role pin
7676
pinMode(role_pin, INPUT);
77-
digitalWrite(role_pin,HIGH);
77+
digitalWrite(role_pin,LOW);
7878
delay(20); // Just to get a solid reading on the role pin
7979

8080
// read the address pin, establish our role
@@ -88,7 +88,7 @@ void setup(void)
8888
//
8989

9090
Serial.begin(57600);
91-
printf_begin();
91+
//printf_begin();
9292
printf("\n\rRF24/examples/pingpair_dyn/\n\r");
9393
printf("ROLE: %s\n\r",role_friendly_name[role]);
9494

@@ -102,7 +102,7 @@ void setup(void)
102102
radio.enableDynamicPayloads();
103103

104104
// optionally, increase the delay between retries & # of retries
105-
radio.setRetries(15,15);
105+
radio.setRetries(5,15);
106106

107107
//
108108
// Open pipes to other nodes for communication
@@ -189,7 +189,7 @@ void loop(void)
189189
next_payload_size = min_payload_size;
190190

191191
// Try again 1s later
192-
delay(1000);
192+
delay(100);
193193
}
194194

195195
//
@@ -204,11 +204,11 @@ void loop(void)
204204
// Dump the payloads until we've gotten everything
205205
uint8_t len;
206206
bool done = false;
207-
while (!done)
207+
while (radio.available())
208208
{
209209
// Fetch the payload, and see if this was the last one.
210210
len = radio.getDynamicPayloadSize();
211-
done = radio.read( receive_payload, len );
211+
radio.read( receive_payload, len );
212212

213213
// Put a zero at the end for easy printing
214214
receive_payload[len] = 0;
@@ -229,4 +229,4 @@ void loop(void)
229229
}
230230
}
231231
}
232-
// vim:cin:ai:sts=2 sw=2 ft=cpp
232+
// vim:cin:ai:sts=2 sw=2 ft=cpp

0 commit comments

Comments
 (0)