From ebd586217eebd355a0b8d9e1393c628913cf78d5 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 26 Apr 2025 15:49:20 -0700 Subject: [PATCH 01/15] refactor: migrate to `txAddress` from `openWritingPipe()` `stopListening()` now writes the TX address to pipe 0 (for reading and writing). This deprecates the need for `openWritingPipe()` by exposing the cached `txAddress` for public manipulation. All examples (and the python wrapper) have been updated to use the new public `txAddress` member accordingly. follow up to #1029 --- RF24.cpp | 10 +++++---- RF24.h | 22 ++++++++++++++++++- examples/GettingStarted/GettingStarted.ino | 4 ++-- .../InterruptConfigure/InterruptConfigure.ino | 4 ++-- .../ManualAcknowledgements.ino | 4 ++-- examples/MulticeiverDemo/MulticeiverDemo.ino | 18 +++++++-------- examples/StreamingData/StreamingData.ino | 4 ++-- examples_linux/acknowledgementPayloads.cpp | 4 ++-- examples_linux/acknowledgement_payloads.py | 4 ++-- examples_linux/getting_started.py | 4 ++-- examples_linux/gettingstarted.cpp | 4 ++-- examples_linux/interruptConfigure.cpp | 4 ++-- examples_linux/interrupt_configure.py | 4 ++-- examples_linux/manualAcknowledgements.cpp | 4 ++-- examples_linux/manual_acknowledgements.py | 4 ++-- examples_linux/multiceiverDemo.cpp | 18 +++++++-------- examples_linux/multiceiver_demo.py | 5 +++-- examples_linux/streamingData.cpp | 4 ++-- examples_linux/streaming_data.py | 4 ++-- examples_pico/acknowledgementPayloads.cpp | 4 ++-- examples_pico/gettingStarted.cpp | 4 ++-- examples_pico/interruptConfigure.cpp | 4 ++-- examples_pico/manualAcknowledgements.cpp | 4 ++-- examples_pico/multiceiverDemo.cpp | 18 +++++++-------- examples_pico/streamingData.cpp | 4 ++-- pyRF24/pyRF24.cpp | 17 ++++++++++++++ 26 files changed, 112 insertions(+), 72 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index bbd7df561..ceb8c1556 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -603,7 +603,8 @@ void RF24::_init_obj() _spi = &SPI; #endif // defined (RF24_SPI_PTR) - pipe0_reading_address[0] = 0; + memset(pipe0_reading_address, 0, 5); + memset(txAddress, 0xE7, 5); if (spi_speed <= 35000) { //Handle old BCM2835 speed constants, default to RF24_SPI_SPEED spi_speed = RF24_SPI_SPEED; } @@ -1186,7 +1187,8 @@ void RF24::stopListening(void) powerUp(); } #endif - write_register(RX_ADDR_P0, pipe0_writing_address, addr_width); + write_register(TX_ADDR, txAddress, addr_width); + write_register(RX_ADDR_P0, txAddress, addr_width); write_register(EN_RXADDR, static_cast(read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0])))); // Enable RX on pipe0 } @@ -1595,7 +1597,7 @@ void RF24::openWritingPipe(uint64_t value) write_register(RX_ADDR_P0, reinterpret_cast(&value), addr_width); write_register(TX_ADDR, reinterpret_cast(&value), addr_width); - memcpy(pipe0_writing_address, &value, addr_width); + memcpy(txAddress, &value, addr_width); } /****************************************************************************/ @@ -1606,7 +1608,7 @@ void RF24::openWritingPipe(const uint8_t* address) // expects it LSB first too, so we're good. write_register(RX_ADDR_P0, address, addr_width); write_register(TX_ADDR, address, addr_width); - memcpy(pipe0_writing_address, address, addr_width); + memcpy(txAddress, address, addr_width); } /****************************************************************************/ diff --git a/RF24.h b/RF24.h index 1b455470e..788339a2f 100644 --- a/RF24.h +++ b/RF24.h @@ -182,7 +182,6 @@ class RF24 uint8_t status; /* The status byte returned from every SPI transaction */ uint8_t payload_size; /* Fixed size of payloads */ uint8_t pipe0_reading_address[5]; /* Last address set on pipe 0 for reading. */ - uint8_t pipe0_writing_address[5]; /* Last address set on pipe 0 for writing. */ uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */ bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */ bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */ @@ -367,6 +366,24 @@ class RF24 */ void startListening(void); + /** + * The TX address to use on pipe 0 for writing. + * + * This is cached in the library to ensure proper auto-ack behavior on pipe 0, + * if pipe 0 is also used with a different RX address for receiving. + * + * Use this instead of calling openWritingPipe() + * + * ```cpp + * uint8_t rxNodeAddress[6] = "1Node"; + * memcpy(radio.txAddress, rxNodeAddress, 5); + * radio.stopListening(); + * ``` + * + * Previously, openWritingPipe() should be called after stopListening(). + */ + uint8_t txAddress[5]; + /** * Stop listening for incoming messages, and switch to transmit mode. * @@ -523,6 +540,9 @@ class RF24 * New: Open a pipe for writing via byte array. Old addressing format retained * for compatibility. * + * @deprecated Use `RF24::txAddress` instead. + * As of v1.5, using this function is slower than using `RF24::txAddress`. + * * Only one writing pipe can be opened at once, but this function changes * the address that is used to transmit (ACK payloads/packets do not apply * here). Be sure to call stopListening() prior to calling this function. diff --git a/examples/GettingStarted/GettingStarted.ino b/examples/GettingStarted/GettingStarted.ino index 4132c1035..ce27dcf40 100644 --- a/examples/GettingStarted/GettingStarted.ino +++ b/examples/GettingStarted/GettingStarted.ino @@ -74,8 +74,8 @@ void setup() { // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // float datatype occupies 4 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples/InterruptConfigure/InterruptConfigure.ino b/examples/InterruptConfigure/InterruptConfigure.ino index 48f6a4c9c..b55df4473 100644 --- a/examples/InterruptConfigure/InterruptConfigure.ino +++ b/examples/InterruptConfigure/InterruptConfigure.ino @@ -104,8 +104,8 @@ void setup() { radio.enableAckPayload(); // Fot this example, we use the same address to send data back and forth - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples/ManualAcknowledgements/ManualAcknowledgements.ino b/examples/ManualAcknowledgements/ManualAcknowledgements.ino index 3e8b8fc91..f9361ceae 100644 --- a/examples/ManualAcknowledgements/ManualAcknowledgements.ino +++ b/examples/ManualAcknowledgements/ManualAcknowledgements.ino @@ -88,8 +88,8 @@ void setup() { // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples/MulticeiverDemo/MulticeiverDemo.ino b/examples/MulticeiverDemo/MulticeiverDemo.ino index ee9bf9411..a095cbab9 100644 --- a/examples/MulticeiverDemo/MulticeiverDemo.ino +++ b/examples/MulticeiverDemo/MulticeiverDemo.ino @@ -27,13 +27,13 @@ RF24 radio(CE_PIN, CSN_PIN); // an identifying device destination // Notice that the last byte is the only byte that changes in the last 5 // addresses. This is a limitation of the nRF24L01 transceiver for pipes 2-5 -// because they use the same first 4 bytes from pipe 1. -uint64_t address[6] = { 0x7878787878LL, - 0xB3B4B5B6F1LL, - 0xB3B4B5B6CDLL, - 0xB3B4B5B6A3LL, - 0xB3B4B5B60FLL, - 0xB3B4B5B605LL }; +// because they use the same first 4 MSBytes from pipe 1. +uint8_t address[6][6] = { { 0x78, 0x78, 0x78, 0x78, 0x78 }, + { 0xF1, 0xB6, 0xB5, 0xB4, 0xB3 }, + { 0xCD, 0xB6, 0xB5, 0xB4, 0xB3 }, + { 0xA3, 0xB6, 0xB5, 0xB4, 0xB3 }, + { 0x0F, 0xB6, 0xB5, 0xB4, 0xB3 }, + { 0x05, 0xB6, 0xB5, 0xB4, 0xB3 } }; // role variable is used to control whether this node is sending or receiving char role = 'R'; // integers 0-5 = TX node; character 'R' or integer 82 = RX node @@ -183,9 +183,9 @@ void setRole() { payload.nodeID = role; payload.payloadID = 0; - // Set the address on pipe 0 to the RX node. + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[role], 5); radio.stopListening(); // put radio in TX mode - radio.openWritingPipe(address[role]); // According to the datasheet, the auto-retry features's delay value should // be "skewed" to allow the RX node to receive 1 transmission at a time. diff --git a/examples/StreamingData/StreamingData.ino b/examples/StreamingData/StreamingData.ino index 0c3d6458f..2bb8ccc1e 100644 --- a/examples/StreamingData/StreamingData.ino +++ b/examples/StreamingData/StreamingData.ino @@ -80,8 +80,8 @@ void setup() { // number of bytes we need to transmit radio.setPayloadSize(SIZE); // default value is the maximum 32 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/acknowledgementPayloads.cpp b/examples_linux/acknowledgementPayloads.cpp index 5412160f3..a73c706bb 100644 --- a/examples_linux/acknowledgementPayloads.cpp +++ b/examples_linux/acknowledgementPayloads.cpp @@ -96,8 +96,8 @@ int main(int argc, char** argv) // each other. radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/acknowledgement_payloads.py b/examples_linux/acknowledgement_payloads.py index d0fcb20f8..5966458c9 100644 --- a/examples_linux/acknowledgement_payloads.py +++ b/examples_linux/acknowledgement_payloads.py @@ -51,8 +51,8 @@ # usually run with nRF24L01 transceivers in close proximity of each other radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default -# set the TX address of the RX node into the TX pipe -radio.openWritingPipe(address[radio_number]) # always uses pipe 0 +# set the TX address of the RX node for use on the TX pipe (pipe 0) +radio.txAddress = address[radio_number] # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/getting_started.py b/examples_linux/getting_started.py index 6b91d0a13..abb4d281a 100644 --- a/examples_linux/getting_started.py +++ b/examples_linux/getting_started.py @@ -48,8 +48,8 @@ # usually run with nRF24L01 transceivers in close proximity of each other radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default -# set the TX address of the RX node into the TX pipe -radio.openWritingPipe(address[radio_number]) # always uses pipe 0 +# set the TX address of the RX node for use on the TX pipe (pipe 0) +radio.txAddress = address[radio_number] # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/gettingstarted.cpp b/examples_linux/gettingstarted.cpp index 752611f6b..2b2fc889c 100644 --- a/examples_linux/gettingstarted.cpp +++ b/examples_linux/gettingstarted.cpp @@ -87,8 +87,8 @@ int main(int argc, char** argv) // each other. radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/interruptConfigure.cpp b/examples_linux/interruptConfigure.cpp index fc68131a1..48499c8ca 100644 --- a/examples_linux/interruptConfigure.cpp +++ b/examples_linux/interruptConfigure.cpp @@ -109,8 +109,8 @@ int main(int argc, char** argv) // each other. radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/interrupt_configure.py b/examples_linux/interrupt_configure.py index 72f945c5a..2d34428fa 100644 --- a/examples_linux/interrupt_configure.py +++ b/examples_linux/interrupt_configure.py @@ -82,8 +82,8 @@ # usually run with nRF24L01 transceivers in close proximity of each other radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default -# set the TX address of the RX node into the TX pipe -radio.openWritingPipe(address[radio_number]) # always uses pipe 0 +# set the TX address of the RX node for use on the TX pipe (pipe 0) +radio.txAddress = address[radio_number] # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/manualAcknowledgements.cpp b/examples_linux/manualAcknowledgements.cpp index 621093250..b49d129ed 100644 --- a/examples_linux/manualAcknowledgements.cpp +++ b/examples_linux/manualAcknowledgements.cpp @@ -103,8 +103,8 @@ int main(int argc, char** argv) // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/manual_acknowledgements.py b/examples_linux/manual_acknowledgements.py index c38824103..8c1956669 100644 --- a/examples_linux/manual_acknowledgements.py +++ b/examples_linux/manual_acknowledgements.py @@ -54,8 +54,8 @@ # usually run with nRF24L01 transceivers in close proximity of each other radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default -# set the TX address of the RX node into the TX pipe -radio.openWritingPipe(address[radio_number]) # always uses pipe 0 +# set the TX address of the RX node for use on the TX pipe (pipe 0) +radio.txAddress = address[radio_number] # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/multiceiverDemo.cpp b/examples_linux/multiceiverDemo.cpp index aa8744736..3e50df4d0 100644 --- a/examples_linux/multiceiverDemo.cpp +++ b/examples_linux/multiceiverDemo.cpp @@ -47,13 +47,13 @@ RF24 radio(CE_PIN, CSN_PIN); // an identifying device destination // Notice that the last byte is the only byte that changes in the last 5 // addresses. This is a limitation of the nRF24L01 transceiver for pipes 2-5 -// because they use the same first 4 bytes from pipe 1. -uint64_t address[6] = {0x7878787878LL, - 0xB3B4B5B6F1LL, - 0xB3B4B5B6CDLL, - 0xB3B4B5B6A3LL, - 0xB3B4B5B60FLL, - 0xB3B4B5B605LL}; +// because they use the same first 4 MSBytes from pipe 1. +uint8_t address[6][6] = {{0x78, 0x78, 0x78, 0x78, 0x78}, + {0xF1, 0xB6, 0xB5, 0xB4, 0xB3}, + {0xCD, 0xB6, 0xB5, 0xB4, 0xB3}, + {0xA3, 0xB6, 0xB5, 0xB4, 0xB3}, + {0x0F, 0xB6, 0xB5, 0xB4, 0xB3}, + {0x05, 0xB6, 0xB5, 0xB4, 0xB3}}; // For this example, we'll be using a payload containing // a node ID number and a single integer number that will be incremented @@ -181,9 +181,9 @@ void master(unsigned int role) payload.nodeID = role; payload.payloadID = 0; - // Set the address on pipe 0 to the RX node. + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[role], 5); radio.stopListening(); // put radio in TX mode - radio.openWritingPipe(address[role]); // According to the datasheet, the auto-retry features's delay value should // be "skewed" to allow the RX node to receive 1 transmission at a time. diff --git a/examples_linux/multiceiver_demo.py b/examples_linux/multiceiver_demo.py index 66fa160e7..c2441e15d 100644 --- a/examples_linux/multiceiver_demo.py +++ b/examples_linux/multiceiver_demo.py @@ -74,9 +74,10 @@ def master(node_number): ((node_number * 3) % 12) + 3, 15 ) # maximum value is 15 for both args + # set the TX address of the RX node for use on the TX pipe (pipe 0) + radio.txAddress = addresses[node_number] radio.stopListening() # put radio in TX mode - # set the TX address to the address of the base station. - radio.openWritingPipe(addresses[node_number]) + counter = 0 failures = 0 while failures < 6: diff --git a/examples_linux/streamingData.cpp b/examples_linux/streamingData.cpp index 30ca66b92..a6a8f7ee2 100644 --- a/examples_linux/streamingData.cpp +++ b/examples_linux/streamingData.cpp @@ -149,8 +149,8 @@ int main(int argc, char** argv) // each other. radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/streaming_data.py b/examples_linux/streaming_data.py index eb38ab26c..5db2fa533 100644 --- a/examples_linux/streaming_data.py +++ b/examples_linux/streaming_data.py @@ -47,8 +47,8 @@ # usually run with nRF24L01 transceivers in close proximity of each other radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default -# set the TX address of the RX node into the TX pipe -radio.openWritingPipe(address[radio_number]) # always uses pipe 0 +# set the TX address of the RX node for use on the TX pipe (pipe 0) +radio.txAddress = address[radio_number] # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_pico/acknowledgementPayloads.cpp b/examples_pico/acknowledgementPayloads.cpp index 599e59ed8..31aebd433 100644 --- a/examples_pico/acknowledgementPayloads.cpp +++ b/examples_pico/acknowledgementPayloads.cpp @@ -78,8 +78,8 @@ bool setup() // this feature for all nodes (TX & RX) to use ACK payloads. radio.enableAckPayload(); - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_pico/gettingStarted.cpp b/examples_pico/gettingStarted.cpp index f7dfaacb4..d3ca3be9a 100644 --- a/examples_pico/gettingStarted.cpp +++ b/examples_pico/gettingStarted.cpp @@ -67,8 +67,8 @@ bool setup() // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // float datatype occupies 4 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_pico/interruptConfigure.cpp b/examples_pico/interruptConfigure.cpp index b1414d567..a63518b88 100644 --- a/examples_pico/interruptConfigure.cpp +++ b/examples_pico/interruptConfigure.cpp @@ -97,8 +97,8 @@ bool setup() radio.enableAckPayload(); // Fot this example, we use the same address to send data back and forth - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_pico/manualAcknowledgements.cpp b/examples_pico/manualAcknowledgements.cpp index c0362a8f4..ac4c4f28d 100644 --- a/examples_pico/manualAcknowledgements.cpp +++ b/examples_pico/manualAcknowledgements.cpp @@ -82,8 +82,8 @@ bool setup() // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_pico/multiceiverDemo.cpp b/examples_pico/multiceiverDemo.cpp index a187ab2c9..d17b4d2d7 100644 --- a/examples_pico/multiceiverDemo.cpp +++ b/examples_pico/multiceiverDemo.cpp @@ -27,13 +27,13 @@ RF24 radio(CE_PIN, CSN_PIN); // an identifying device destination // Notice that the last byte is the only byte that changes in the last 5 // addresses. This is a limitation of the nRF24L01 transceiver for pipes 2-5 -// because they use the same first 4 bytes from pipe 1. -uint64_t address[6] = {0x7878787878LL, - 0xB3B4B5B6F1LL, - 0xB3B4B5B6CDLL, - 0xB3B4B5B6A3LL, - 0xB3B4B5B60FLL, - 0xB3B4B5B605LL}; +// because they use the same first 4 MSBytes from pipe 1. +uint8_t address[6][6] = {{0x78, 0x78, 0x78, 0x78, 0x78}, + {0xF1, 0xB6, 0xB5, 0xB4, 0xB3}, + {0xCD, 0xB6, 0xB5, 0xB4, 0xB3}, + {0xA3, 0xB6, 0xB5, 0xB4, 0xB3}, + {0x0F, 0xB6, 0xB5, 0xB4, 0xB3}, + {0x05, 0xB6, 0xB5, 0xB4, 0xB3}}; // Because this example allow up to 6 nodes (specified by numbers 0-5) to // transmit and only 1 node to receive, we will use a negative value in our @@ -190,9 +190,9 @@ void setRole() payload.nodeID = role; payload.payloadID = 0; - // Set the address on pipe 0 to the RX node. + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[role], 5); radio.stopListening(); // put radio in TX mode - radio.openWritingPipe(address[role]); // According to the datasheet, the auto-retry features's delay value should // be "skewed" to allow the RX node to receive 1 transmission at a time. diff --git a/examples_pico/streamingData.cpp b/examples_pico/streamingData.cpp index 8e8d61138..916924e66 100644 --- a/examples_pico/streamingData.cpp +++ b/examples_pico/streamingData.cpp @@ -73,8 +73,8 @@ bool setup() // number of bytes we need to transmit radio.setPayloadSize(SIZE); // default value is the maximum 32 bytes - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/pyRF24/pyRF24.cpp b/pyRF24/pyRF24.cpp index 92ceeb158..ac100e328 100644 --- a/pyRF24/pyRF24.cpp +++ b/pyRF24/pyRF24.cpp @@ -39,6 +39,21 @@ int get_bytes_or_bytearray_ln(bp::object buf) return 0; } +void set_tx_address(RF24& ref, bp::object buf) +{ + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(ref.txAddress, get_bytes_or_bytearray_str(buf), get_bytes_or_bytearray_ln(buf)); +} + +bp::object get_tx_address(RF24& ref) +{ + char* buf = new char[6]; + memcpy(buf, ref.txAddress, 5); + bp::object py_ba(bp::handle<>(PyByteArray_FromStringAndSize(buf, 5))); + delete[] buf; + return py_ba; +} + bp::object read_wrap(RF24& ref, int maxlen) { char* buf = new char[maxlen + 1]; @@ -328,6 +343,8 @@ BOOST_PYTHON_MODULE(RF24) .def("openReadingPipe", (void(::RF24::*)(::uint8_t, ::uint64_t))(&::RF24::openReadingPipe), (bp::arg("number"), bp::arg("address"))) .def("openWritingPipe", &openWritingPipe_wrap, (bp::arg("address"))) .def("openWritingPipe", (void(::RF24::*)(::uint64_t))(&::RF24::openWritingPipe), (bp::arg("address"))) + .add_property("txAddress", &get_tx_address, &set_tx_address) + .add_property("tx_address", &get_tx_address, &set_tx_address) .def("powerDown", &RF24::powerDown) .def("powerUp", &RF24::powerUp) .def("printDetails", &RF24::printDetails) From d1d1795a53fcade3e898d606b2cb1a4261f442e8 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 26 Apr 2025 16:21:42 -0700 Subject: [PATCH 02/15] use correct buffer size in multiciever demos. --- examples/MulticeiverDemo/MulticeiverDemo.ino | 2 +- examples_linux/multiceiverDemo.cpp | 2 +- examples_pico/multiceiverDemo.cpp | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/examples/MulticeiverDemo/MulticeiverDemo.ino b/examples/MulticeiverDemo/MulticeiverDemo.ino index a095cbab9..fb4d7731c 100644 --- a/examples/MulticeiverDemo/MulticeiverDemo.ino +++ b/examples/MulticeiverDemo/MulticeiverDemo.ino @@ -28,7 +28,7 @@ RF24 radio(CE_PIN, CSN_PIN); // Notice that the last byte is the only byte that changes in the last 5 // addresses. This is a limitation of the nRF24L01 transceiver for pipes 2-5 // because they use the same first 4 MSBytes from pipe 1. -uint8_t address[6][6] = { { 0x78, 0x78, 0x78, 0x78, 0x78 }, +uint8_t address[6][5] = { { 0x78, 0x78, 0x78, 0x78, 0x78 }, { 0xF1, 0xB6, 0xB5, 0xB4, 0xB3 }, { 0xCD, 0xB6, 0xB5, 0xB4, 0xB3 }, { 0xA3, 0xB6, 0xB5, 0xB4, 0xB3 }, diff --git a/examples_linux/multiceiverDemo.cpp b/examples_linux/multiceiverDemo.cpp index 3e50df4d0..200d0eb53 100644 --- a/examples_linux/multiceiverDemo.cpp +++ b/examples_linux/multiceiverDemo.cpp @@ -48,7 +48,7 @@ RF24 radio(CE_PIN, CSN_PIN); // Notice that the last byte is the only byte that changes in the last 5 // addresses. This is a limitation of the nRF24L01 transceiver for pipes 2-5 // because they use the same first 4 MSBytes from pipe 1. -uint8_t address[6][6] = {{0x78, 0x78, 0x78, 0x78, 0x78}, +uint8_t address[6][5] = {{0x78, 0x78, 0x78, 0x78, 0x78}, {0xF1, 0xB6, 0xB5, 0xB4, 0xB3}, {0xCD, 0xB6, 0xB5, 0xB4, 0xB3}, {0xA3, 0xB6, 0xB5, 0xB4, 0xB3}, diff --git a/examples_pico/multiceiverDemo.cpp b/examples_pico/multiceiverDemo.cpp index d17b4d2d7..b38732da3 100644 --- a/examples_pico/multiceiverDemo.cpp +++ b/examples_pico/multiceiverDemo.cpp @@ -28,7 +28,7 @@ RF24 radio(CE_PIN, CSN_PIN); // Notice that the last byte is the only byte that changes in the last 5 // addresses. This is a limitation of the nRF24L01 transceiver for pipes 2-5 // because they use the same first 4 MSBytes from pipe 1. -uint8_t address[6][6] = {{0x78, 0x78, 0x78, 0x78, 0x78}, +uint8_t address[6][5] = {{0x78, 0x78, 0x78, 0x78, 0x78}, {0xF1, 0xB6, 0xB5, 0xB4, 0xB3}, {0xCD, 0xB6, 0xB5, 0xB4, 0xB3}, {0xA3, 0xB6, 0xB5, 0xB4, 0xB3}, From d5b6ca3c4ba2b223b1aee12c734a786b43c7bff6 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 26 Apr 2025 16:40:04 -0700 Subject: [PATCH 03/15] missed an autoAckPL example --- examples/AcknowledgementPayloads/AcknowledgementPayloads.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino b/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino index f4c7f1785..22a1dc858 100644 --- a/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino +++ b/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino @@ -84,8 +84,8 @@ void setup() { // this feature for all nodes (TX & RX) to use ACK payloads. radio.enableAckPayload(); - // set the TX address of the RX node into the TX pipe - radio.openWritingPipe(address[radioNumber]); // always uses pipe 0 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 From e6fd948006df440c04aa1111b9a094b2f9f376e2 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sun, 27 Apr 2025 00:53:40 -0700 Subject: [PATCH 04/15] overload `stopListening(tx_address)` --- RF24.cpp | 11 +++++++++-- RF24.h | 13 +++++++------ .../AcknowledgementPayloads.ino | 8 +++----- examples/GettingStarted/GettingStarted.ino | 12 +++++------- examples/InterruptConfigure/InterruptConfigure.ino | 13 ++++--------- .../ManualAcknowledgements.ino | 7 +++---- examples/MulticeiverDemo/MulticeiverDemo.ino | 3 +-- examples/StreamingData/StreamingData.ino | 12 +++++------- examples_linux/multiceiverDemo.cpp | 3 +-- examples_linux/multiceiver_demo.py | 3 +-- pyRF24/pyRF24.cpp | 8 +++++++- 11 files changed, 46 insertions(+), 47 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index ceb8c1556..f51747728 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1187,13 +1187,21 @@ void RF24::stopListening(void) powerUp(); } #endif - write_register(TX_ADDR, txAddress, addr_width); write_register(RX_ADDR_P0, txAddress, addr_width); write_register(EN_RXADDR, static_cast(read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0])))); // Enable RX on pipe0 } /****************************************************************************/ +void RF24::stopListening(const uint8_t* tx_address) +{ + memcpy(txAddress, tx_address, addr_width); + startListening(); + write_register(TX_ADDR, txAddress, addr_width); +} + +/****************************************************************************/ + void RF24::powerDown(void) { ce(LOW); // Guarantee CE is low on powerDown @@ -1608,7 +1616,6 @@ void RF24::openWritingPipe(const uint8_t* address) // expects it LSB first too, so we're good. write_register(RX_ADDR_P0, address, addr_width); write_register(TX_ADDR, address, addr_width); - memcpy(txAddress, address, addr_width); } /****************************************************************************/ diff --git a/RF24.h b/RF24.h index 788339a2f..41114421e 100644 --- a/RF24.h +++ b/RF24.h @@ -396,13 +396,15 @@ class RF24 * @warning When the ACK payloads feature is enabled, the TX FIFO buffers are * flushed when calling this function. This is meant to discard any ACK * payloads that were not appended to acknowledgment packets. - * - * @note For auto-ack purposes, the TX address passed to openWritingPipe() will be restored to - * RX pipe 0. This still means that `stopListening()` shall be called before - * calling openWritingPipe() because the TX address is cached in openWritingPipe(). */ void stopListening(void); + /** + * @brief Similar to startListening(void) but changes the TX address. + * @param tx_address The new TX address. This value will be cached to `txAddress` member. + */ + void stopListening(const uint8_t* tx_address); + /** * Check whether there are bytes available to be read * @code @@ -540,8 +542,7 @@ class RF24 * New: Open a pipe for writing via byte array. Old addressing format retained * for compatibility. * - * @deprecated Use `RF24::txAddress` instead. - * As of v1.5, using this function is slower than using `RF24::txAddress`. + * @deprecated Use `RF24::txAddress` or `RF24::stopListening(uint8_t*)` instead. * * Only one writing pipe can be opened at once, but this function changes * the address that is used to transmit (ACK payloads/packets do not apply diff --git a/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino b/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino index 22a1dc858..786eb750e 100644 --- a/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino +++ b/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino @@ -84,18 +84,16 @@ void setup() { // this feature for all nodes (TX & RX) to use ACK payloads. radio.enableAckPayload(); - // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); - // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + radio.stopListening(address[radioNumber]); // put radio in TX mode + // additional setup specific to the node's role if (role) { // setup the TX payload - memcpy(payload.message, "Hello ", 6); // set the payload message - radio.stopListening(); // put radio in TX mode } else { // setup the ACK payload & load the first response into the FIFO diff --git a/examples/GettingStarted/GettingStarted.ino b/examples/GettingStarted/GettingStarted.ino index ce27dcf40..db0bf98c0 100644 --- a/examples/GettingStarted/GettingStarted.ino +++ b/examples/GettingStarted/GettingStarted.ino @@ -74,16 +74,14 @@ void setup() { // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // float datatype occupies 4 bytes - // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); - // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // additional setup specific to the node's role - if (role) { - radio.stopListening(); // put radio in TX mode - } else { + // set the TX address of the RX node for use on the TX pipe (pipe 0) + radio.stopListening(address[radioNumber]); // put radio in TX mode + + // additional setup specific to the node's RX role + if (!role) { radio.startListening(); // put radio in RX mode } diff --git a/examples/InterruptConfigure/InterruptConfigure.ino b/examples/InterruptConfigure/InterruptConfigure.ino index b55df4473..f7956883d 100644 --- a/examples/InterruptConfigure/InterruptConfigure.ino +++ b/examples/InterruptConfigure/InterruptConfigure.ino @@ -102,20 +102,15 @@ void setup() { // Acknowledgement packets have no payloads by default. We need to enable // this feature for all nodes (TX & RX) to use ACK payloads. radio.enableAckPayload(); - // Fot this example, we use the same address to send data back and forth - - // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // additional setup specific to the node's role - if (role) { - // setup for TX mode - radio.stopListening(); // put radio in TX mode + // set the TX address of the RX node for use on the TX pipe (pipe 0) + radio.stopListening(address[radioNumber]); // put radio in TX mode - } else { + // additional setup specific to the node's RX role + if (!role) { // setup for RX mode // let IRQ pin only trigger on "data_ready" event in RX mode diff --git a/examples/ManualAcknowledgements/ManualAcknowledgements.ino b/examples/ManualAcknowledgements/ManualAcknowledgements.ino index f9361ceae..3ff8490d4 100644 --- a/examples/ManualAcknowledgements/ManualAcknowledgements.ino +++ b/examples/ManualAcknowledgements/ManualAcknowledgements.ino @@ -88,17 +88,16 @@ void setup() { // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes - // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); - // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + // set the TX address of the RX node for use on the TX pipe (pipe 0) + radio.stopListening(address[radioNumber]); // put radio in TX mode + if (role) { // setup the TX node memcpy(payload.message, "Hello ", 6); // set the outgoing message - radio.stopListening(); // put radio in TX mode } else { // setup the RX node diff --git a/examples/MulticeiverDemo/MulticeiverDemo.ino b/examples/MulticeiverDemo/MulticeiverDemo.ino index fb4d7731c..b5c68bea6 100644 --- a/examples/MulticeiverDemo/MulticeiverDemo.ino +++ b/examples/MulticeiverDemo/MulticeiverDemo.ino @@ -184,8 +184,7 @@ void setRole() { payload.payloadID = 0; // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[role], 5); - radio.stopListening(); // put radio in TX mode + radio.stopListening(address[role]); // put radio in TX mode // According to the datasheet, the auto-retry features's delay value should // be "skewed" to allow the RX node to receive 1 transmission at a time. diff --git a/examples/StreamingData/StreamingData.ino b/examples/StreamingData/StreamingData.ino index 2bb8ccc1e..6e340d27e 100644 --- a/examples/StreamingData/StreamingData.ino +++ b/examples/StreamingData/StreamingData.ino @@ -80,16 +80,14 @@ void setup() { // number of bytes we need to transmit radio.setPayloadSize(SIZE); // default value is the maximum 32 bytes - // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); - // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // additional setup specific to the node's role - if (role) { - radio.stopListening(); // put radio in TX mode - } else { + // set the TX address of the RX node for use on the TX pipe (pipe 0) + radio.stopListening(address[radioNumber]); // put radio in TX mode + + // additional setup specific to the node's RX role + if (!role) { radio.startListening(); // put radio in RX mode } diff --git a/examples_linux/multiceiverDemo.cpp b/examples_linux/multiceiverDemo.cpp index 200d0eb53..bc8fb2343 100644 --- a/examples_linux/multiceiverDemo.cpp +++ b/examples_linux/multiceiverDemo.cpp @@ -182,8 +182,7 @@ void master(unsigned int role) payload.payloadID = 0; // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[role], 5); - radio.stopListening(); // put radio in TX mode + radio.stopListening(address[role]); // put radio in TX mode // According to the datasheet, the auto-retry features's delay value should // be "skewed" to allow the RX node to receive 1 transmission at a time. diff --git a/examples_linux/multiceiver_demo.py b/examples_linux/multiceiver_demo.py index c2441e15d..1f3fe17fb 100644 --- a/examples_linux/multiceiver_demo.py +++ b/examples_linux/multiceiver_demo.py @@ -75,8 +75,7 @@ def master(node_number): ) # maximum value is 15 for both args # set the TX address of the RX node for use on the TX pipe (pipe 0) - radio.txAddress = addresses[node_number] - radio.stopListening() # put radio in TX mode + radio.stopListening(addresses[node_number]) # put radio in TX mode counter = 0 failures = 0 diff --git a/pyRF24/pyRF24.cpp b/pyRF24/pyRF24.cpp index ac100e328..0e2cbddf5 100644 --- a/pyRF24/pyRF24.cpp +++ b/pyRF24/pyRF24.cpp @@ -113,6 +113,11 @@ void openWritingPipe_wrap(RF24& ref, const bp::object address) ref.openWritingPipe((const uint8_t*)(get_bytes_or_bytearray_str(address))); } +void stopListening_wrap(RF24& ref, const bp::object address) +{ + ref.stopListening((const uint8_t*)(get_bytes_or_bytearray_str(address))); +} + void openReadingPipe_wrap(RF24& ref, uint8_t number, const bp::object address) { ref.openReadingPipe(number, (const uint8_t*)(get_bytes_or_bytearray_str(address))); @@ -368,7 +373,8 @@ BOOST_PYTHON_MODULE(RF24) .def("startFastWrite", &startFastWrite_wrap2, (bp::arg("buf"), bp::arg("len"), bp::arg("multicast"), bp::arg("startTx"))) .def("startListening", &RF24::startListening) .def("startWrite", &startWrite_wrap, (bp::arg("buf"), bp::arg("len"), bp::arg("multicast"))) - .def("stopListening", &RF24::stopListening) + .def("stopListening", (void(::RF24::*)(void))(&RF24::stopListening)) + .def("stopListening", &stopListening_wrap, (bp::arg("tx_address"))) .def("testCarrier", &RF24::testCarrier) .def("testRPD", &RF24::testRPD) .def("toggleAllPipes", &RF24::toggleAllPipes) From 62f14495598f875e602b66b37654faff70fb3cad Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Wed, 30 Apr 2025 14:27:01 -0700 Subject: [PATCH 05/15] openReadingPipe(0) should not overwrite TX address in TX mode explain logic in comment --- RF24.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index f51747728..5e98ac245 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1196,7 +1196,7 @@ void RF24::stopListening(void) void RF24::stopListening(const uint8_t* tx_address) { memcpy(txAddress, tx_address, addr_width); - startListening(); + stopListening(); write_register(TX_ADDR, txAddress, addr_width); } @@ -1635,12 +1635,14 @@ void RF24::openReadingPipe(uint8_t child, uint64_t address) if (child <= 5) { // For pipes 2-5, only write the LSB - if (child < 2) { - write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast(&address), addr_width); - } - else { + if (child > 1) { write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast(&address), 1); } + // avoid overwriting the TX address on pipe 0 while still in TX mode. + // NOTE, the cached RX address on pipe 0 is written when startListening() is called. + else if (static_cast(config_reg & _BV(PRIM_RX)) || child != 0) { + write_register(pgm_read_byte(&child_pipe[child]), reinterpret_cast(&address), addr_width); + } // Note it would be more efficient to set all of the bits for all open // pipes at once. However, I thought it would make the calling code @@ -1677,12 +1679,14 @@ void RF24::openReadingPipe(uint8_t child, const uint8_t* address) } if (child <= 5) { // For pipes 2-5, only write the LSB - if (child < 2) { - write_register(pgm_read_byte(&child_pipe[child]), address, addr_width); - } - else { + if (child > 1) { write_register(pgm_read_byte(&child_pipe[child]), address, 1); } + // avoid overwriting the TX address on pipe 0 while still in TX mode. + // NOTE, the cached RX address on pipe 0 is written when startListening() is called. + else if (static_cast(config_reg & _BV(PRIM_RX)) || child != 0) { + write_register(pgm_read_byte(&child_pipe[child]), address, addr_width); + } // Note it would be more efficient to set all of the bits for all open // pipes at once. However, I thought it would make the calling code From d1a0168620122b1e3bacc9091fbe29855a40e2dd Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Wed, 30 Apr 2025 14:43:44 -0700 Subject: [PATCH 06/15] update examples --- .../AcknowledgementPayloads/AcknowledgementPayloads.ino | 6 +++--- examples/GettingStarted/GettingStarted.ino | 6 +++--- examples/InterruptConfigure/InterruptConfigure.ino | 6 +++--- .../ManualAcknowledgements/ManualAcknowledgements.ino | 6 +++--- examples/StreamingData/StreamingData.ino | 6 +++--- examples_linux/acknowledgementPayloads.cpp | 2 +- examples_linux/acknowledgement_payloads.py | 2 +- examples_linux/getting_started.py | 2 +- examples_linux/gettingstarted.cpp | 2 +- examples_linux/interruptConfigure.cpp | 2 +- examples_linux/interrupt_configure.py | 2 +- examples_linux/manualAcknowledgements.cpp | 2 +- examples_linux/manual_acknowledgements.py | 2 +- examples_linux/streamingData.cpp | 2 +- examples_linux/streaming_data.py | 2 +- examples_pico/acknowledgementPayloads.cpp | 2 +- examples_pico/gettingStarted.cpp | 2 +- examples_pico/interruptConfigure.cpp | 8 ++------ examples_pico/manualAcknowledgements.cpp | 3 +-- examples_pico/multiceiverDemo.cpp | 3 +-- examples_pico/streamingData.cpp | 7 ++----- 21 files changed, 33 insertions(+), 42 deletions(-) diff --git a/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino b/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino index 786eb750e..af0d7db92 100644 --- a/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino +++ b/examples/AcknowledgementPayloads/AcknowledgementPayloads.ino @@ -84,12 +84,12 @@ void setup() { // this feature for all nodes (TX & RX) to use ACK payloads. radio.enableAckPayload(); - // set the RX address of the TX node into a RX pipe - radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // set the TX address of the RX node for use on the TX pipe (pipe 0) radio.stopListening(address[radioNumber]); // put radio in TX mode + // set the RX address of the TX node into a RX pipe + radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + // additional setup specific to the node's role if (role) { // setup the TX payload diff --git a/examples/GettingStarted/GettingStarted.ino b/examples/GettingStarted/GettingStarted.ino index db0bf98c0..5da9321bc 100644 --- a/examples/GettingStarted/GettingStarted.ino +++ b/examples/GettingStarted/GettingStarted.ino @@ -74,12 +74,12 @@ void setup() { // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // float datatype occupies 4 bytes - // set the RX address of the TX node into a RX pipe - radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // set the TX address of the RX node for use on the TX pipe (pipe 0) radio.stopListening(address[radioNumber]); // put radio in TX mode + // set the RX address of the TX node into a RX pipe + radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + // additional setup specific to the node's RX role if (!role) { radio.startListening(); // put radio in RX mode diff --git a/examples/InterruptConfigure/InterruptConfigure.ino b/examples/InterruptConfigure/InterruptConfigure.ino index f7956883d..09c2fcf40 100644 --- a/examples/InterruptConfigure/InterruptConfigure.ino +++ b/examples/InterruptConfigure/InterruptConfigure.ino @@ -103,12 +103,12 @@ void setup() { // this feature for all nodes (TX & RX) to use ACK payloads. radio.enableAckPayload(); - // set the RX address of the TX node into a RX pipe - radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // set the TX address of the RX node for use on the TX pipe (pipe 0) radio.stopListening(address[radioNumber]); // put radio in TX mode + // set the RX address of the TX node into a RX pipe + radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + // additional setup specific to the node's RX role if (!role) { // setup for RX mode diff --git a/examples/ManualAcknowledgements/ManualAcknowledgements.ino b/examples/ManualAcknowledgements/ManualAcknowledgements.ino index 3ff8490d4..8cb1c6da2 100644 --- a/examples/ManualAcknowledgements/ManualAcknowledgements.ino +++ b/examples/ManualAcknowledgements/ManualAcknowledgements.ino @@ -88,12 +88,12 @@ void setup() { // number of bytes we need to transmit a float radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes - // set the RX address of the TX node into a RX pipe - radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // set the TX address of the RX node for use on the TX pipe (pipe 0) radio.stopListening(address[radioNumber]); // put radio in TX mode + // set the RX address of the TX node into a RX pipe + radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + if (role) { // setup the TX node diff --git a/examples/StreamingData/StreamingData.ino b/examples/StreamingData/StreamingData.ino index 6e340d27e..0ce15b620 100644 --- a/examples/StreamingData/StreamingData.ino +++ b/examples/StreamingData/StreamingData.ino @@ -80,12 +80,12 @@ void setup() { // number of bytes we need to transmit radio.setPayloadSize(SIZE); // default value is the maximum 32 bytes - // set the RX address of the TX node into a RX pipe - radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 - // set the TX address of the RX node for use on the TX pipe (pipe 0) radio.stopListening(address[radioNumber]); // put radio in TX mode + // set the RX address of the TX node into a RX pipe + radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 + // additional setup specific to the node's RX role if (!role) { radio.startListening(); // put radio in RX mode diff --git a/examples_linux/acknowledgementPayloads.cpp b/examples_linux/acknowledgementPayloads.cpp index a73c706bb..e2dd26464 100644 --- a/examples_linux/acknowledgementPayloads.cpp +++ b/examples_linux/acknowledgementPayloads.cpp @@ -97,7 +97,7 @@ int main(int argc, char** argv) radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/acknowledgement_payloads.py b/examples_linux/acknowledgement_payloads.py index 5966458c9..5bc494679 100644 --- a/examples_linux/acknowledgement_payloads.py +++ b/examples_linux/acknowledgement_payloads.py @@ -52,7 +52,7 @@ radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default # set the TX address of the RX node for use on the TX pipe (pipe 0) -radio.txAddress = address[radio_number] +radio.stopListening(address[radio_number]) # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/getting_started.py b/examples_linux/getting_started.py index abb4d281a..e289a0158 100644 --- a/examples_linux/getting_started.py +++ b/examples_linux/getting_started.py @@ -49,7 +49,7 @@ radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default # set the TX address of the RX node for use on the TX pipe (pipe 0) -radio.txAddress = address[radio_number] +radio.stopListening(address[radio_number]) # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/gettingstarted.cpp b/examples_linux/gettingstarted.cpp index 2b2fc889c..c7f00ecae 100644 --- a/examples_linux/gettingstarted.cpp +++ b/examples_linux/gettingstarted.cpp @@ -88,7 +88,7 @@ int main(int argc, char** argv) radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/interruptConfigure.cpp b/examples_linux/interruptConfigure.cpp index 48499c8ca..9269d8808 100644 --- a/examples_linux/interruptConfigure.cpp +++ b/examples_linux/interruptConfigure.cpp @@ -110,7 +110,7 @@ int main(int argc, char** argv) radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/interrupt_configure.py b/examples_linux/interrupt_configure.py index 2d34428fa..18c0ee254 100644 --- a/examples_linux/interrupt_configure.py +++ b/examples_linux/interrupt_configure.py @@ -83,7 +83,7 @@ radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default # set the TX address of the RX node for use on the TX pipe (pipe 0) -radio.txAddress = address[radio_number] +radio.stopListening(address[radio_number]) # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/manualAcknowledgements.cpp b/examples_linux/manualAcknowledgements.cpp index b49d129ed..2a5fa02ef 100644 --- a/examples_linux/manualAcknowledgements.cpp +++ b/examples_linux/manualAcknowledgements.cpp @@ -104,7 +104,7 @@ int main(int argc, char** argv) radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/manual_acknowledgements.py b/examples_linux/manual_acknowledgements.py index 8c1956669..c03bcdcfd 100644 --- a/examples_linux/manual_acknowledgements.py +++ b/examples_linux/manual_acknowledgements.py @@ -55,7 +55,7 @@ radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default # set the TX address of the RX node for use on the TX pipe (pipe 0) -radio.txAddress = address[radio_number] +radio.stopListening(address[radio_number]) # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_linux/streamingData.cpp b/examples_linux/streamingData.cpp index a6a8f7ee2..836250464 100644 --- a/examples_linux/streamingData.cpp +++ b/examples_linux/streamingData.cpp @@ -150,7 +150,7 @@ int main(int argc, char** argv) radio.setPALevel(RF24_PA_LOW); // RF24_PA_MAX is default. // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_linux/streaming_data.py b/examples_linux/streaming_data.py index 5db2fa533..4309118a5 100644 --- a/examples_linux/streaming_data.py +++ b/examples_linux/streaming_data.py @@ -48,7 +48,7 @@ radio.setPALevel(RF24_PA_LOW) # RF24_PA_MAX is default # set the TX address of the RX node for use on the TX pipe (pipe 0) -radio.txAddress = address[radio_number] +radio.stopListening(address[radio_number]) # set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[not radio_number]) # using pipe 1 diff --git a/examples_pico/acknowledgementPayloads.cpp b/examples_pico/acknowledgementPayloads.cpp index 31aebd433..98aa4ccb0 100644 --- a/examples_pico/acknowledgementPayloads.cpp +++ b/examples_pico/acknowledgementPayloads.cpp @@ -79,7 +79,7 @@ bool setup() radio.enableAckPayload(); // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_pico/gettingStarted.cpp b/examples_pico/gettingStarted.cpp index d3ca3be9a..68e3ad48a 100644 --- a/examples_pico/gettingStarted.cpp +++ b/examples_pico/gettingStarted.cpp @@ -68,7 +68,7 @@ bool setup() radio.setPayloadSize(sizeof(payload)); // float datatype occupies 4 bytes // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 diff --git a/examples_pico/interruptConfigure.cpp b/examples_pico/interruptConfigure.cpp index a63518b88..a6159f615 100644 --- a/examples_pico/interruptConfigure.cpp +++ b/examples_pico/interruptConfigure.cpp @@ -98,17 +98,13 @@ bool setup() // Fot this example, we use the same address to send data back and forth // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 // additional setup specific to the node's role - if (role) { - // setup for TX mode - radio.stopListening(); // put radio in TX mode - } - else { + if (!role) { // setup for RX mode // disable IRQ pin in RX mode diff --git a/examples_pico/manualAcknowledgements.cpp b/examples_pico/manualAcknowledgements.cpp index ac4c4f28d..951878370 100644 --- a/examples_pico/manualAcknowledgements.cpp +++ b/examples_pico/manualAcknowledgements.cpp @@ -83,7 +83,7 @@ bool setup() radio.setPayloadSize(sizeof(payload)); // char[7] & uint8_t datatypes occupy 8 bytes // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 @@ -92,7 +92,6 @@ bool setup() // setup the TX node memcpy(payload.message, "Hello ", 6); // set the outgoing message - radio.stopListening(); // put radio in TX mode } else { // setup the RX node diff --git a/examples_pico/multiceiverDemo.cpp b/examples_pico/multiceiverDemo.cpp index b38732da3..634066545 100644 --- a/examples_pico/multiceiverDemo.cpp +++ b/examples_pico/multiceiverDemo.cpp @@ -191,8 +191,7 @@ void setRole() payload.payloadID = 0; // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[role], 5); - radio.stopListening(); // put radio in TX mode + radio.stopListening(address[role]); // put radio in TX mode // According to the datasheet, the auto-retry features's delay value should // be "skewed" to allow the RX node to receive 1 transmission at a time. diff --git a/examples_pico/streamingData.cpp b/examples_pico/streamingData.cpp index 916924e66..a3716a563 100644 --- a/examples_pico/streamingData.cpp +++ b/examples_pico/streamingData.cpp @@ -74,16 +74,13 @@ bool setup() radio.setPayloadSize(SIZE); // default value is the maximum 32 bytes // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(radio.txAddress, address[radioNumber], 5); + radio.stopListening(address[radioNumber]); // set the RX address of the TX node into a RX pipe radio.openReadingPipe(1, address[!radioNumber]); // using pipe 1 // additional setup specific to the node's role - if (role) { - radio.stopListening(); // put radio in TX mode - } - else { + if (!role) { radio.startListening(); // put radio in RX mode } From 5e52cdbb0a42aa9a3f925b2978e38d911c4530d7 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Wed, 30 Apr 2025 16:52:58 -0700 Subject: [PATCH 07/15] try initializing the cached addresses in declaration --- RF24.cpp | 2 -- RF24.h | 14 +++++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index 5e98ac245..fd0d3f7d7 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -603,8 +603,6 @@ void RF24::_init_obj() _spi = &SPI; #endif // defined (RF24_SPI_PTR) - memset(pipe0_reading_address, 0, 5); - memset(txAddress, 0xE7, 5); if (spi_speed <= 35000) { //Handle old BCM2835 speed constants, default to RF24_SPI_SPEED spi_speed = RF24_SPI_SPEED; } diff --git a/RF24.h b/RF24.h index 41114421e..22153975d 100644 --- a/RF24.h +++ b/RF24.h @@ -179,12 +179,12 @@ class RF24 uint8_t spi_rxbuff[32 + 1]; //SPI receive buffer (payload max 32 bytes) uint8_t spi_txbuff[32 + 1]; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command) #endif - uint8_t status; /* The status byte returned from every SPI transaction */ - uint8_t payload_size; /* Fixed size of payloads */ - uint8_t pipe0_reading_address[5]; /* Last address set on pipe 0 for reading. */ - uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */ - bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */ - bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */ + uint8_t status; /* The status byte returned from every SPI transaction */ + uint8_t payload_size; /* Fixed size of payloads */ + uint8_t pipe0_reading_address[5] = {0}; /* Last address set on pipe 0 for reading. */ + uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */ + bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */ + bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */ protected: /** @@ -382,7 +382,7 @@ class RF24 * * Previously, openWritingPipe() should be called after stopListening(). */ - uint8_t txAddress[5]; + uint8_t txAddress[5] = {0xE7}; /** * Stop listening for incoming messages, and switch to transmit mode. From e0fe4740bd716a730b8ab5a69f3ef8e3d8ee2e4e Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Wed, 30 Apr 2025 17:12:43 -0700 Subject: [PATCH 08/15] don't init cached addresses user code should ultimately specify address(es) regardless of initialization --- RF24.h | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/RF24.h b/RF24.h index 22153975d..41114421e 100644 --- a/RF24.h +++ b/RF24.h @@ -179,12 +179,12 @@ class RF24 uint8_t spi_rxbuff[32 + 1]; //SPI receive buffer (payload max 32 bytes) uint8_t spi_txbuff[32 + 1]; //SPI transmit buffer (payload max 32 bytes + 1 byte for the command) #endif - uint8_t status; /* The status byte returned from every SPI transaction */ - uint8_t payload_size; /* Fixed size of payloads */ - uint8_t pipe0_reading_address[5] = {0}; /* Last address set on pipe 0 for reading. */ - uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */ - bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */ - bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */ + uint8_t status; /* The status byte returned from every SPI transaction */ + uint8_t payload_size; /* Fixed size of payloads */ + uint8_t pipe0_reading_address[5]; /* Last address set on pipe 0 for reading. */ + uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */ + bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */ + bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */ protected: /** @@ -382,7 +382,7 @@ class RF24 * * Previously, openWritingPipe() should be called after stopListening(). */ - uint8_t txAddress[5] = {0xE7}; + uint8_t txAddress[5]; /** * Stop listening for incoming messages, and switch to transmit mode. From f9d6957d76708e3f01be6813e812c641ad7c0e23 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Wed, 30 Apr 2025 22:56:42 -0700 Subject: [PATCH 09/15] revert exposing cached TX address --- RF24.cpp | 10 +++++----- RF24.h | 26 +++++--------------------- pyRF24/pyRF24.cpp | 19 +------------------ 3 files changed, 11 insertions(+), 44 deletions(-) diff --git a/RF24.cpp b/RF24.cpp index fd0d3f7d7..9e7eb713b 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1185,17 +1185,17 @@ void RF24::stopListening(void) powerUp(); } #endif - write_register(RX_ADDR_P0, txAddress, addr_width); + write_register(RX_ADDR_P0, pipe0_writing_address, addr_width); write_register(EN_RXADDR, static_cast(read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0])))); // Enable RX on pipe0 } /****************************************************************************/ -void RF24::stopListening(const uint8_t* tx_address) +void RF24::stopListening(const uint8_t* txAddress) { - memcpy(txAddress, tx_address, addr_width); + memcpy(pipe0_writing_address, txAddress, addr_width); stopListening(); - write_register(TX_ADDR, txAddress, addr_width); + write_register(TX_ADDR, pipe0_writing_address, addr_width); } /****************************************************************************/ @@ -1603,7 +1603,7 @@ void RF24::openWritingPipe(uint64_t value) write_register(RX_ADDR_P0, reinterpret_cast(&value), addr_width); write_register(TX_ADDR, reinterpret_cast(&value), addr_width); - memcpy(txAddress, &value, addr_width); + memcpy(pipe0_writing_address, &value, addr_width); } /****************************************************************************/ diff --git a/RF24.h b/RF24.h index 41114421e..045d4d1fd 100644 --- a/RF24.h +++ b/RF24.h @@ -182,6 +182,7 @@ class RF24 uint8_t status; /* The status byte returned from every SPI transaction */ uint8_t payload_size; /* Fixed size of payloads */ uint8_t pipe0_reading_address[5]; /* Last address set on pipe 0 for reading. */ + uint8_t pipe0_writing_address[5]; /* Last address set on pipe 0 for writing. */ uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */ bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */ bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */ @@ -366,24 +367,6 @@ class RF24 */ void startListening(void); - /** - * The TX address to use on pipe 0 for writing. - * - * This is cached in the library to ensure proper auto-ack behavior on pipe 0, - * if pipe 0 is also used with a different RX address for receiving. - * - * Use this instead of calling openWritingPipe() - * - * ```cpp - * uint8_t rxNodeAddress[6] = "1Node"; - * memcpy(radio.txAddress, rxNodeAddress, 5); - * radio.stopListening(); - * ``` - * - * Previously, openWritingPipe() should be called after stopListening(). - */ - uint8_t txAddress[5]; - /** * Stop listening for incoming messages, and switch to transmit mode. * @@ -401,9 +384,10 @@ class RF24 /** * @brief Similar to startListening(void) but changes the TX address. - * @param tx_address The new TX address. This value will be cached to `txAddress` member. + * @param txAddress The new TX address. + * This value will be cached for auto-ack purposes. */ - void stopListening(const uint8_t* tx_address); + void stopListening(const uint8_t* txAddress); /** * Check whether there are bytes available to be read @@ -542,7 +526,7 @@ class RF24 * New: Open a pipe for writing via byte array. Old addressing format retained * for compatibility. * - * @deprecated Use `RF24::txAddress` or `RF24::stopListening(uint8_t*)` instead. + * @deprecated Use `RF24::stopListening(uint8_t*)` instead. * * Only one writing pipe can be opened at once, but this function changes * the address that is used to transmit (ACK payloads/packets do not apply diff --git a/pyRF24/pyRF24.cpp b/pyRF24/pyRF24.cpp index 0e2cbddf5..2bb4489d5 100644 --- a/pyRF24/pyRF24.cpp +++ b/pyRF24/pyRF24.cpp @@ -39,21 +39,6 @@ int get_bytes_or_bytearray_ln(bp::object buf) return 0; } -void set_tx_address(RF24& ref, bp::object buf) -{ - // set the TX address of the RX node for use on the TX pipe (pipe 0) - memcpy(ref.txAddress, get_bytes_or_bytearray_str(buf), get_bytes_or_bytearray_ln(buf)); -} - -bp::object get_tx_address(RF24& ref) -{ - char* buf = new char[6]; - memcpy(buf, ref.txAddress, 5); - bp::object py_ba(bp::handle<>(PyByteArray_FromStringAndSize(buf, 5))); - delete[] buf; - return py_ba; -} - bp::object read_wrap(RF24& ref, int maxlen) { char* buf = new char[maxlen + 1]; @@ -348,8 +333,6 @@ BOOST_PYTHON_MODULE(RF24) .def("openReadingPipe", (void(::RF24::*)(::uint8_t, ::uint64_t))(&::RF24::openReadingPipe), (bp::arg("number"), bp::arg("address"))) .def("openWritingPipe", &openWritingPipe_wrap, (bp::arg("address"))) .def("openWritingPipe", (void(::RF24::*)(::uint64_t))(&::RF24::openWritingPipe), (bp::arg("address"))) - .add_property("txAddress", &get_tx_address, &set_tx_address) - .add_property("tx_address", &get_tx_address, &set_tx_address) .def("powerDown", &RF24::powerDown) .def("powerUp", &RF24::powerUp) .def("printDetails", &RF24::printDetails) @@ -374,7 +357,7 @@ BOOST_PYTHON_MODULE(RF24) .def("startListening", &RF24::startListening) .def("startWrite", &startWrite_wrap, (bp::arg("buf"), bp::arg("len"), bp::arg("multicast"))) .def("stopListening", (void(::RF24::*)(void))(&RF24::stopListening)) - .def("stopListening", &stopListening_wrap, (bp::arg("tx_address"))) + .def("stopListening", &stopListening_wrap, (bp::arg("txAddress"))) .def("testCarrier", &RF24::testCarrier) .def("testRPD", &RF24::testRPD) .def("toggleAllPipes", &RF24::toggleAllPipes) From 79ea02d09ac912f876f9c47332282fcdc12a4621 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 3 May 2025 00:07:04 -0700 Subject: [PATCH 10/15] add to migration guide --- docs/migration.md | 64 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/docs/migration.md b/docs/migration.md index f3139a05c..906654222 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -46,6 +46,10 @@ There are overloaded functions that use a buffer instead: These eliminate the unnecessary 24 bits by only using the length of the buffer (`uint8_t*`) specified by `RF24::setAddressWidth()`. +@see The `RF24::openWritingPipe(const uint8_t*)` is now deprecated in favor of the +overloaded `RF24::stopListening(uint8_t*)` function. +See the section below for more detail. + > [!CAUTION] > The endianness (byte order) of a buffer is reversed compared to a 64-bit integer. > ```c @@ -211,3 +215,63 @@ radio.clearStatusFlags(RF24_RX_DR); ``` + +## openWritingPipe(const uint8_t*) + +> Deprecated since v1.5 + +Originally, `RF24::openWritingPipe(const uint8_t*)` was just a compliment to +`RF24::openReadingPipe()`. +It changes the address on pipe 0 because that is the only pipe that can be +used for transmitting. + +Unfortunately, there was a bug that prevented the given TX address from being +persistent on pipe 0 if the user code also set an RX address to pipe 0. +This bug would surface when switching between RX mode and TX mode (via +`RF24::startListening()` and `RF24::stopListening()` respectively) or after +`RF24::stopConstCarrier()`. +As a result the TX address has to be cached on the `RF24` instance. +Consequently, this solution does not fit well with the traditional order of +setting up the radio. + +By overloading `RF24::stopListening(const uint8_t*)`, we are able to ensure proper radio +setup without requiring certain functions are called in a certain order. + +- Use `RF24::stopListening(const uint8_t*)` to set the TX address and enter inactive TX mode. + `RF24::openReadingPipe()` can now (as of v1.5) be used in TX mode without consequence. +- Use `RF24::stopListening()` to enter inactive TX mode without changing the TX address. + +> [!warning] +> Avoid using pipe 0 for RX operations to improve performance and reliability. +> +> For implementation detail, see the source for `RF24::openReadingPipe()` and +> `RF24::stopListening()`. Ultimately, the datasheet's Appendix A has a detailed +> example outlining the order of a proper radio setup. + + + + +
OldNew (supported)
+ +```cpp +// set TX address (pipe 0) +radio.openWritingPipe(tx_address); + +// set RX address (pipe 1) +radio.openReadingPipe(1, rx_address); + +// idle radio using inactive TX mode +radio.stopListening(); +``` + + + +```cpp +// set TX address (pipe 0) +radio.stopListening(tx_address); // enters inactive TX mode + +// set RX address (pipe 1) +radio.openReadingPipe(1, rx_address); +``` + +
From 60617617d93391718cdbf6ed03e2853ab27a7b70 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 3 May 2025 00:27:02 -0700 Subject: [PATCH 11/15] `stopConstCarrier()` restore cached TX address for plus variants only --- RF24.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/RF24.cpp b/RF24.cpp index 9e7eb713b..ad1385cf9 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -2048,6 +2048,11 @@ void RF24::stopConstCarrier() powerDown(); // per datasheet recommendation (just to be safe) write_register(RF_SETUP, static_cast(read_register(RF_SETUP) & ~_BV(CONT_WAVE) & ~_BV(PLL_LOCK))); ce(LOW); + flush_tx(); + if (isPVariant()) { + // restore the cached TX address + write_register(TX_ADDR, pipe0_writing_address, addr_width); + } } /****************************************************************************/ From c9dbb87d316e4f188e67a7b7aaddc3dbb51ea62a Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 3 May 2025 03:41:03 -0700 Subject: [PATCH 12/15] revert `openWritingPipe(buf)` --- RF24.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/RF24.cpp b/RF24.cpp index ad1385cf9..af85e3950 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1614,6 +1614,7 @@ void RF24::openWritingPipe(const uint8_t* address) // expects it LSB first too, so we're good. write_register(RX_ADDR_P0, address, addr_width); write_register(TX_ADDR, address, addr_width); + memcpy(pipe0_writing_address, address, addr_width); } /****************************************************************************/ From 7beba48c94cb54d14a0a218da6da4870bbcb9dad Mon Sep 17 00:00:00 2001 From: TMRh20 Date: Sat, 3 May 2025 05:41:34 -0600 Subject: [PATCH 13/15] Add uint64_t versions of new stoplistening --- RF24.cpp | 9 +++++++++ RF24.h | 7 +++++++ 2 files changed, 16 insertions(+) diff --git a/RF24.cpp b/RF24.cpp index af85e3950..d8d14eb80 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -1191,6 +1191,15 @@ void RF24::stopListening(void) /****************************************************************************/ +void RF24::stopListening(const uint64_t txAddress) +{ + memcpy(pipe0_writing_address, &txAddress, addr_width); + stopListening(); + write_register(TX_ADDR, pipe0_writing_address, addr_width); +} + +/****************************************************************************/ + void RF24::stopListening(const uint8_t* txAddress) { memcpy(pipe0_writing_address, txAddress, addr_width); diff --git a/RF24.h b/RF24.h index 045d4d1fd..bf86db7b8 100644 --- a/RF24.h +++ b/RF24.h @@ -389,6 +389,13 @@ class RF24 */ void stopListening(const uint8_t* txAddress); + /** + * @brief Similar to startListening(void) but changes the TX address. + * @param txAddress The new TX address. + * This value will be cached for auto-ack purposes. + */ + void stopListening(const uint64_t txAddress); + /** * Check whether there are bytes available to be read * @code From 472d5f8977116eda7caee423fb9d237d6874b5d0 Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 3 May 2025 12:30:15 -0700 Subject: [PATCH 14/15] deprecate `stopListening(uint64_t)` review migration guide again --- RF24.h | 18 +++++++++++------- docs/migration.md | 28 +++++++++++++++++++--------- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/RF24.h b/RF24.h index bf86db7b8..1fd4d543e 100644 --- a/RF24.h +++ b/RF24.h @@ -389,13 +389,6 @@ class RF24 */ void stopListening(const uint8_t* txAddress); - /** - * @brief Similar to startListening(void) but changes the TX address. - * @param txAddress The new TX address. - * This value will be cached for auto-ack purposes. - */ - void stopListening(const uint64_t txAddress); - /** * Check whether there are bytes available to be read * @code @@ -2034,6 +2027,17 @@ class RF24 */ void whatHappened(bool& tx_ok, bool& tx_fail, bool& rx_ready); + /** + * Similar to startListening(void) but changes the TX address. + * + * @deprecated Use stopListening(const uint8_t*) instead. + * See our [migration guide](migration.md) to understand what you should update in your code. + * + * @param txAddress The new TX address. + * This value will be cached for auto-ack purposes. + */ + void stopListening(const uint64_t txAddress); + private: /**@}*/ /** diff --git a/docs/migration.md b/docs/migration.md index 906654222..b4d378266 100644 --- a/docs/migration.md +++ b/docs/migration.md @@ -30,24 +30,32 @@ if radio.available() { /* .. */ } -## openReadingPipe(uint8_t, uint64_t) and openWritingPipe(uint64_t) +## 64-bit integer addresses -> **Deprecated since v1.3.11** +Any function that accept an address in the form of `uint64_t` is discouraged. This includes -These functions' address parameter used a 64-bit unsigned integer (`uint64_t`). +- `RF24::openReadingPipe(uint8_t, uint64_t)` + > **Deprecated since v1.3.11** +- `RF24::openWritingPipe(uint64_t)` + > **Deprecated since v1.3.11** +- `RF24::stopListening(const uint64_t)` + > **Deprecated since v1.5** + +These functions' address parameter use a 64-bit unsigned integer (`uint64_t`). The nRF24L01 can only use up to 40 bit addresses. -Thus, there was an unused 24 bits being allocated for addresses using this function. +Thus, there is an unused 24 bits being allocated for addresses using these functions. There are overloaded functions that use a buffer instead: - `RF24::openReadingPipe(uint8_t, const uint8_t*)` - `RF24::openWritingPipe(const uint8_t*)` +- `RF24::stopListening(const uint8_t*)` These eliminate the unnecessary 24 bits by only using the length of the buffer (`uint8_t*`) specified by `RF24::setAddressWidth()`. @see The `RF24::openWritingPipe(const uint8_t*)` is now deprecated in favor of the -overloaded `RF24::stopListening(uint8_t*)` function. +overloaded `RF24::stopListening(const uint8_t*)` function. See the section below for more detail. > [!CAUTION] @@ -181,6 +189,7 @@ The aptly named `RF24::clearStatusFlags()` is designed to be a replacement for ` Like `RF24::clearStatusFlags()`, `RF24::setStatusFlags()` takes 1 parameter whose value is defined by the `rf24_irq_flags_e` enumerated constants. These constant values specify individual flags; they can also be OR'd together to specify multiple flags. + Additionally, `RF24::clearStatusFlags()` returns the STATUS byte containing the flags that caused the IRQ pin to go active LOW. This allows the user code to allocate less memory when diagnosing the IRQ pin's meaning. @@ -229,10 +238,11 @@ Unfortunately, there was a bug that prevented the given TX address from being persistent on pipe 0 if the user code also set an RX address to pipe 0. This bug would surface when switching between RX mode and TX mode (via `RF24::startListening()` and `RF24::stopListening()` respectively) or after -`RF24::stopConstCarrier()`. -As a result the TX address has to be cached on the `RF24` instance. -Consequently, this solution does not fit well with the traditional order of -setting up the radio. +`RF24::stopConstCarrier()` (if `RF24::isPVariant()` returns `true`). + +The solution is to cache the TX address on the `RF24` instance. +Consequently, this solution did not fit well with the traditional order of +functions used to set up the radio's TX or RX mode. By overloading `RF24::stopListening(const uint8_t*)`, we are able to ensure proper radio setup without requiring certain functions are called in a certain order. From a04c3244dbb0e1b6ea226d5859269a9add37957e Mon Sep 17 00:00:00 2001 From: Brendan <2bndy5@gmail.com> Date: Sat, 3 May 2025 12:34:42 -0700 Subject: [PATCH 15/15] upgrade doxygen version --- .github/workflows/doxygen.yml | 2 +- .readthedocs.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/doxygen.yml b/.github/workflows/doxygen.yml index 1f0457aee..fcc62a91c 100644 --- a/.github/workflows/doxygen.yml +++ b/.github/workflows/doxygen.yml @@ -50,5 +50,5 @@ jobs: uses: nRF24/.github/.github/workflows/build_docs.yaml@main with: deploy-gh-pages: ${{ github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.ref == 'refs/heads/master') }} - doxygen-version: '1.12.0' + doxygen-version: '1.13.2' secrets: inherit diff --git a/.readthedocs.yaml b/.readthedocs.yaml index e6f4edc3b..db2305248 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -15,7 +15,7 @@ build: commands: # Install doxygen from source distributions (conda forge does not keep up-to-date doxygen releases) - > - DOXYGEN_VERSION="1.12.0" && + DOXYGEN_VERSION="1.13.2" && mkdir .doxygen && cd .doxygen && echo $(pwd) && echo "https://sourceforge.net/projects/doxygen/files/rel-$DOXYGEN_VERSION/doxygen-$DOXYGEN_VERSION.linux.bin.tar.gz" &&