Skip to content

Commit

Permalink
drivers/radio/nrf24l01: Properly handle timeout.
Browse files Browse the repository at this point in the history
The timeout condition was not handled before. Upon timeout, this
caused the chip to stay active until another send command changed
it's state.

Sometimes when it was unable to transmit the data, it got stuck
in the tx fifo causing it to fill up over time, which set the
TX_FULL flag in the STATUS register.

Since there was no exceptions raised, the user code could not
differentiate a successful send or a timeout condition.

Signed-off-by: Marcell Pünkösd <[email protected]>
  • Loading branch information
marcsello committed Dec 30, 2024
1 parent e4cf095 commit 9f143e9
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions micropython/drivers/radio/nrf24l01/nrf24l01.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,13 @@ def send(self, buf, timeout=500):
result = None
while result is None and utime.ticks_diff(utime.ticks_ms(), start) < timeout:
result = self.send_done() # 1 == success, 2 == fail

if result is None:
# timed out, cancel sending and power down the module
self.flush_tx()
self.reg_write(CONFIG, self.reg_read(CONFIG) & ~PWR_UP)
raise OSError("timed out")

if result == 2:
raise OSError("send failed")

Expand Down

0 comments on commit 9f143e9

Please sign in to comment.