Skip to content

Commit c7103bb

Browse files
marcsellodpgeorge
authored andcommitted
nrf24l01: Optimize 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 bd1ab77 commit c7103bb

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)
@@ -250,7 +257,8 @@ def send_start(self, buf):
250257

251258
# returns None if send still in progress, 1 for success, 2 for fail
252259
def send_done(self):
253-
if not (self.reg_read(STATUS) & (TX_DS | MAX_RT)):
260+
status = self.read_status()
261+
if not (status & (TX_DS | MAX_RT)):
254262
return None # tx not finished
255263

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

0 commit comments

Comments
 (0)