Skip to content

Commit

Permalink
listen won't flush RX FIFO; flush TX FIFO of ACKs
Browse files Browse the repository at this point in the history
  • Loading branch information
2bndy5 committed Oct 23, 2020
1 parent 8df70db commit 6e8eb83
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 15 deletions.
3 changes: 2 additions & 1 deletion circuitpython_nrf24l01/rf24.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions docs/basic_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ listen
- `True` enables RX mode. Additionally, per `Appendix B of the nRF24L01+ Specifications
Sheet <https://www.sparkfun.com/datasheets/Components/SMD/
nRF24L01Pluss_Preliminary_Product_Specification_v1_0.pdf#G1091756>`_, 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()
******************
Expand Down
9 changes: 3 additions & 6 deletions examples/nrf24l01_ack_payload_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Expand All @@ -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(
Expand Down
5 changes: 2 additions & 3 deletions examples/nrf24l01_interrupt_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 3 additions & 1 deletion examples/nrf24l01_multiceiver_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 6e8eb83

Please sign in to comment.