Skip to content

Commit 9f143e9

Browse files
committed
drivers/radio/nrf24l01: Properly handle timeout.
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]>
1 parent e4cf095 commit 9f143e9

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

micropython/drivers/radio/nrf24l01/nrf24l01.py

+7
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,13 @@ def send(self, buf, timeout=500):
220220
result = None
221221
while result is None and utime.ticks_diff(utime.ticks_ms(), start) < timeout:
222222
result = self.send_done() # 1 == success, 2 == fail
223+
224+
if result is None:
225+
# timed out, cancel sending and power down the module
226+
self.flush_tx()
227+
self.reg_write(CONFIG, self.reg_read(CONFIG) & ~PWR_UP)
228+
raise OSError("timed out")
229+
223230
if result == 2:
224231
raise OSError("send failed")
225232

0 commit comments

Comments
 (0)