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 <punkosdmarcell@rocketmail.com>
pull/954/head
marcsello 2024-12-30 15:47:09 +01:00 zatwierdzone przez Damien George
rodzic 3e859d2118
commit bd1ab77324
1 zmienionych plików z 7 dodań i 0 usunięć

Wyświetl plik

@ -220,6 +220,13 @@ class NRF24L01:
result = None result = None
while result is None and utime.ticks_diff(utime.ticks_ms(), start) < timeout: while result is None and utime.ticks_diff(utime.ticks_ms(), start) < timeout:
result = self.send_done() # 1 == success, 2 == fail 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: if result == 2:
raise OSError("send failed") raise OSError("send failed")