diff --git a/circuitpython_nrf24l01/rf24.py b/circuitpython_nrf24l01/rf24.py index cfc945c..13d0b84 100644 --- a/circuitpython_nrf24l01/rf24.py +++ b/circuitpython_nrf24l01/rf24.py @@ -245,11 +245,12 @@ def listen(self, is_rx): self._config = (self._config & 0xFC) | 3 self._reg_write(CONFIGURE, self._config) time.sleep(0.00015) # mandatory wait to power up radio - self.flush_rx() self.clear_status_flags() self.ce_pin.value = 1 # mandatory pulse is > 130 µs time.sleep(0.00013) else: + if self.ack: + self.flush_tx() self._config = self._config & 0xFE self._reg_write(CONFIGURE, self._config) time.sleep(0.00016) diff --git a/docs/basic_api.rst b/docs/basic_api.rst index c294ab6..4fe058c 100644 --- a/docs/basic_api.rst +++ b/docs/basic_api.rst @@ -84,13 +84,13 @@ listen - `True` enables RX mode. Additionally, per `Appendix B of the nRF24L01+ Specifications Sheet `_, this attribute - flushes the RX FIFO, clears the `irq_dr` status flag, and puts nRF24L01 in power up + clears the `irq_dr` status flag and puts nRF24L01 in power up mode. Notice the CE pin is be held HIGH during RX mode. - `False` disables RX mode. As mentioned in above link, this puts nRF24L01's power in Standby-I (CE pin is LOW meaning low current & no transmissions) mode which is ideal - for post-reception work. Disabing RX mode doesn't flush the RX/TX FIFO buffers, so - remember to flush your 3-level FIFO buffers when appropriate using `flush_tx()` or - `flush_rx()` (see also the `recv()` function). + for post-reception work. Disabing RX mode will only flush the TX FIFO buffers if the + `ack` attribute is enabled. Remember to manage your 3-level RX FIFO buffers using the + `flush_rx()` or `recv()` functions. any() ****************** diff --git a/examples/nrf24l01_ack_payload_test.py b/examples/nrf24l01_ack_payload_test.py index a7428e1..6d523a1 100644 --- a/examples/nrf24l01_ack_payload_test.py +++ b/examples/nrf24l01_ack_payload_test.py @@ -48,8 +48,7 @@ def master(count=5): # count = 5 will only transmit 5 packets """Transmits a payload every second and prints the ACK payload""" nrf.listen = False # put radio in TX mode - # set address of RX node into a TX pipe - nrf.open_tx_pipe(address) + nrf.open_tx_pipe(address) # set address of RX node into a TX pipe while count: buffer = b"Hello " + bytes([count + 48]) # output buffer @@ -74,8 +73,7 @@ def slave(count=5): # set address of TX node into an RX pipe. NOTE you MUST specify # which pipe number to use for RX; we'll be using pipe 0 nrf.open_rx_pipe(0, address) - # put radio into RX mode, power it up - nrf.listen = True + nrf.listen = True # put radio into RX mode, power it up # setup the first transmission's ACK payload buffer = ACK + bytes([count + 48]) @@ -96,8 +94,7 @@ def slave(count=5): nrf.load_ack(buffer, 0) # load ACK for next response # recommended behavior is to keep in TX mode while idle - nrf.listen = False # put radio in TX mode - nrf.flush_tx() # flush any ACK payloads that remain + nrf.listen = False # put radio in TX mode & flush unused ACK payloads print( diff --git a/examples/nrf24l01_interrupt_test.py b/examples/nrf24l01_interrupt_test.py index d3136e7..90679ed 100644 --- a/examples/nrf24l01_interrupt_test.py +++ b/examples/nrf24l01_interrupt_test.py @@ -125,12 +125,11 @@ def slave(timeout=6): # will listen for 6 seconds before timing out while not nrf.fifo(0, 0) and time.monotonic() - start_timer < timeout: # if RX FIFO is not full and timeout is not reached, then keep going pass - nrf.listen = False # put nRF24L01 in Standby-I mode when idling - if not nrf.fifo(False, True): # if RX FIFO is not empty + nrf.listen = False # put nRF24L01 in TX mode & discard any ACK payloads + if self.pipe is not None: # if RX FIFO is not empty # all 3 payloads received were 5 bytes each, and RX FIFO is full # so, fetching 15 bytes from the RX FIFO also flushes RX FIFO print("Complete RX FIFO:", nrf.recv(15)) - nrf.flush_tx() # discard any pending ACK payloads print( diff --git a/examples/nrf24l01_multiceiver_test.py b/examples/nrf24l01_multiceiver_test.py index d067c0e..5a7e3ba 100644 --- a/examples/nrf24l01_multiceiver_test.py +++ b/examples/nrf24l01_multiceiver_test.py @@ -60,7 +60,9 @@ def base(timeout=10): start_timer = time.monotonic() # reset timer with every payload if nrf.load_ack(ACK, 1): # keep TX FIFO full with ACK payloads print("\t ACK re-loaded") - nrf.listen = False + # recommended behavior is to keep in TX mode while idle + nrf.listen = False # put radio in TX mode & flush unused ACK payloads + def node(node_number, count=6):