From 9f143e9dc62baf3fffd64c547601d2ab4a333ba5 Mon Sep 17 00:00:00 2001 From: marcsello Date: Mon, 30 Dec 2024 15:47:09 +0100 Subject: [PATCH] drivers/radio/nrf24l01: Properly handle timeout. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- micropython/drivers/radio/nrf24l01/nrf24l01.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/micropython/drivers/radio/nrf24l01/nrf24l01.py b/micropython/drivers/radio/nrf24l01/nrf24l01.py index 76d55312f..055773ffa 100644 --- a/micropython/drivers/radio/nrf24l01/nrf24l01.py +++ b/micropython/drivers/radio/nrf24l01/nrf24l01.py @@ -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")