Skip to content

Commit 7e10dc4

Browse files
committed
drivers/radio/nrf24l01: Optimized status reading.
The value of the STATUS register is always transmitted by the chip when reading any command. So a R_REGISTER command and the turnaround time can be spared by issuing a NOP command instead. This implementation suggested by the datasheet. This operation is compatible with both nRF24L01 and nRF24L01+. Signed-off-by: Marcell Pünkösd <[email protected]>
1 parent e4cf095 commit 7e10dc4

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: micropython/drivers/radio/nrf24l01/nrf24l01.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,13 @@ def reg_write(self, reg, value):
130130
self.cs(1)
131131
return ret
132132

133+
def read_status(self):
134+
self.cs(0)
135+
# STATUS register is always shifted during command transmit
136+
self.spi.readinto(self.buf, NOP)
137+
self.cs(1)
138+
return self.buf[0]
139+
133140
def flush_rx(self):
134141
self.cs(0)
135142
self.spi.readinto(self.buf, FLUSH_RX)
@@ -243,7 +250,8 @@ def send_start(self, buf):
243250

244251
# returns None if send still in progress, 1 for success, 2 for fail
245252
def send_done(self):
246-
if not (self.reg_read(STATUS) & (TX_DS | MAX_RT)):
253+
status = self.read_status()
254+
if not (status & (TX_DS | MAX_RT)):
247255
return None # tx not finished
248256

249257
# either finished or failed: get and clear status flags, power down

0 commit comments

Comments
 (0)