From 66fa552cfbe655e9df021316240b1f8f9cce3b47 Mon Sep 17 00:00:00 2001 From: brendan <2bndy5@gmail.com> Date: Thu, 22 Oct 2020 21:11:21 -0700 Subject: [PATCH] Revert "listen won't flush RX FIFO; flush TX FIFO of ACKs" This reverts commit 6e8eb8313bde160a949476b57767102b684fedc3. --- circuitpython_nrf24l01/rf24.py | 3 +-- docs/basic_api.rst | 8 ++++---- examples/nrf24l01_ack_payload_test.py | 9 ++++++--- examples/nrf24l01_interrupt_test.py | 5 +++-- examples/nrf24l01_multiceiver_test.py | 4 +--- 5 files changed, 15 insertions(+), 14 deletions(-) diff --git a/circuitpython_nrf24l01/rf24.py b/circuitpython_nrf24l01/rf24.py index 13d0b84..cfc945c 100644 --- a/circuitpython_nrf24l01/rf24.py +++ b/circuitpython_nrf24l01/rf24.py @@ -245,12 +245,11 @@ 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 4fe058c..c294ab6 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 - clears the `irq_dr` status flag and puts nRF24L01 in power up + flushes the RX FIFO, 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 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. + 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). any() ****************** diff --git a/examples/nrf24l01_ack_payload_test.py b/examples/nrf24l01_ack_payload_test.py index 6d523a1..a7428e1 100644 --- a/examples/nrf24l01_ack_payload_test.py +++ b/examples/nrf24l01_ack_payload_test.py @@ -48,7 +48,8 @@ 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 - nrf.open_tx_pipe(address) # set address of RX node into a TX pipe + # set address of RX node into a TX pipe + nrf.open_tx_pipe(address) while count: buffer = b"Hello " + bytes([count + 48]) # output buffer @@ -73,7 +74,8 @@ 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) - nrf.listen = True # put radio into RX mode, power it up + # put radio into RX mode, power it up + nrf.listen = True # setup the first transmission's ACK payload buffer = ACK + bytes([count + 48]) @@ -94,7 +96,8 @@ 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 & flush unused ACK payloads + nrf.listen = False # put radio in TX mode + nrf.flush_tx() # flush any ACK payloads that remain print( diff --git a/examples/nrf24l01_interrupt_test.py b/examples/nrf24l01_interrupt_test.py index 90679ed..d3136e7 100644 --- a/examples/nrf24l01_interrupt_test.py +++ b/examples/nrf24l01_interrupt_test.py @@ -125,11 +125,12 @@ 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 TX mode & discard any ACK payloads - if self.pipe is not None: # if RX FIFO is not empty + nrf.listen = False # put nRF24L01 in Standby-I mode when idling + if not nrf.fifo(False, True): # 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 5a7e3ba..d067c0e 100644 --- a/examples/nrf24l01_multiceiver_test.py +++ b/examples/nrf24l01_multiceiver_test.py @@ -60,9 +60,7 @@ 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") - # recommended behavior is to keep in TX mode while idle - nrf.listen = False # put radio in TX mode & flush unused ACK payloads - + nrf.listen = False def node(node_number, count=6):