Skip to content

Commit 0c34c0f

Browse files
TMRh202bndy5
andauthored
Pipe0 fix (#1029)
* Pipe0 Fix #1028 * Caches & restores RX_ADDR_P0 address when calling stopListening(). Ensures ACK functionality works on pipe 0. * add docs bout cached TX address --------- Co-authored-by: Brendan <[email protected]>
1 parent 81b51b3 commit 0c34c0f

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

RF24.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,6 +1188,7 @@ void RF24::stopListening(void)
11881188
powerUp();
11891189
}
11901190
#endif
1191+
write_register(RX_ADDR_P0, pipe0_writing_address, addr_width);
11911192
write_register(EN_RXADDR, static_cast<uint8_t>(read_register(EN_RXADDR) | _BV(pgm_read_byte(&child_pipe_enable[0])))); // Enable RX on pipe0
11921193
}
11931194

@@ -1565,6 +1566,7 @@ void RF24::openWritingPipe(uint64_t value)
15651566

15661567
write_register(RX_ADDR_P0, reinterpret_cast<uint8_t*>(&value), addr_width);
15671568
write_register(TX_ADDR, reinterpret_cast<uint8_t*>(&value), addr_width);
1569+
memcpy(pipe0_writing_address, &value, addr_width);
15681570
}
15691571

15701572
/****************************************************************************/
@@ -1575,6 +1577,7 @@ void RF24::openWritingPipe(const uint8_t* address)
15751577
// expects it LSB first too, so we're good.
15761578
write_register(RX_ADDR_P0, address, addr_width);
15771579
write_register(TX_ADDR, address, addr_width);
1580+
memcpy(pipe0_writing_address, address, addr_width);
15781581
}
15791582

15801583
/****************************************************************************/

RF24.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ class RF24
158158
uint8_t status; /* The status byte returned from every SPI transaction */
159159
uint8_t payload_size; /* Fixed size of payloads */
160160
uint8_t pipe0_reading_address[5]; /* Last address set on pipe 0 for reading. */
161+
uint8_t pipe0_writing_address[5]; /* Last address set on pipe 0 for writing. */
161162
uint8_t config_reg; /* For storing the value of the NRF_CONFIG register */
162163
bool _is_p_variant; /* For storing the result of testing the toggleFeatures() affect */
163164
bool _is_p0_rx; /* For keeping track of pipe 0's usage in user-triggered RX mode. */
@@ -351,9 +352,13 @@ class RF24
351352
* radio.write(&data, sizeof(data));
352353
* @endcode
353354
*
354-
* @note When the ACK payloads feature is enabled, the TX FIFO buffers are
355+
* @warning When the ACK payloads feature is enabled, the TX FIFO buffers are
355356
* flushed when calling this function. This is meant to discard any ACK
356357
* payloads that were not appended to acknowledgment packets.
358+
*
359+
* @note For auto-ack purposes, the TX address passed to openWritingPipe() will be restored to
360+
* RX pipe 0. This still means that `stopListening()` shall be called before
361+
* calling openWritingPipe() because the TX address is cached in openWritingPipe().
357362
*/
358363
void stopListening(void);
359364

@@ -522,10 +527,13 @@ class RF24
522527
* @see
523528
* - setAddressWidth()
524529
* - startListening()
530+
* - stopListening()
525531
*
526532
* @param address The address to be used for outgoing transmissions (uses
527533
* pipe 0). Coordinate this address amongst other receiving nodes (the
528-
* pipe numbers don't need to match).
534+
* pipe numbers don't need to match). This address is cached to ensure proper
535+
* auto-ack behavior; stopListening() will always restore the latest cached TX
536+
* address.
529537
*
530538
* @remark There is no address length parameter because this function will
531539
* always write the number of bytes that the radio addresses are configured

0 commit comments

Comments
 (0)