diff --git a/RF24.cpp b/RF24.cpp index a6775ba..3718874 100644 --- a/RF24.cpp +++ b/RF24.cpp @@ -313,6 +313,9 @@ void RF24::startListening(void) { write_register(CONFIG, _BV(EN_CRC) | _BV(PWR_UP) | _BV(PRIM_RX)); write_register(STATUS, _BV(RX_DR) | _BV(TX_DS) | _BV(MAX_RT) ); + + // Restore the pipe0 adddress + write_register(RX_ADDR_P0, reinterpret_cast(&pipe0_reading_address), 5); // Flush buffers flush_rx(); @@ -495,6 +498,12 @@ void RF24::openReadingPipe(uint8_t child, uint64_t value) const uint8_t child_pipe_enable[] = { ERX_P0, ERX_P1, ERX_P2, ERX_P3, ERX_P4, ERX_P5 }; + // If this is pipe 0, cache the address. This is needed because + // openWritingPipe() will overwrite the pipe 0 address, so + // startListening() will have to restore it. + if (child == 0) + pipe0_reading_address = value; + if (child < 5) { // For pipes 2-5, only write the LSB diff --git a/RF24.h b/RF24.h index c71f644..2939c30 100644 --- a/RF24.h +++ b/RF24.h @@ -23,6 +23,7 @@ private: uint8_t payload_size; /**< Fixed size of payloads */ boolean ack_payload_available; /**< Whether there is an ack payload waiting */ uint8_t ack_payload_length; /**< Dynamic size of pending ack payload. Note: not used. */ + uint64_t pipe0_reading_address; /**< Last address set on pipe 0 for reading. */ protected: /**