Skip to content

Commit 2fba6b8

Browse files
projectgusdpgeorge
authored andcommitted
lora: Workaround SX1262 bug with GetStatus.
This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 1957f24 commit 2fba6b8

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

micropython/lora/lora-sx126x/lora/sx126x.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
_CMD_GET_ERROR = const(0x17)
2525
_CMD_GET_IRQ_STATUS = const(0x12) # args: (r) Status, IrqStatus
2626
_CMD_GET_RX_BUFFER_STATUS = const(0x13) # args: (r) Status, RxPayloadLength, RxBufferPointer
27+
# NOTE: _CMD_GET_STATUS seems to have an issue, see _get_status() function below.
2728
_CMD_GET_STATUS = const(0xC0) # args: (r) Status
2829
_CMD_GET_PACKET_STATUS = const(0x14)
2930
_CMD_READ_REGISTER = const(0x1D) # args: addr (2b), status, (r) Data0 ... DataN
@@ -296,8 +297,21 @@ def _decode_status(self, raw_status, check_errors=True):
296297
return (mode, cmd)
297298

298299
def _get_status(self):
299-
# Issue the GetStatus command and return the decoded status of (mode value, command status)
300-
res = self._cmd("B", _CMD_GET_STATUS, n_read=1)[0]
300+
# Issue the GetStatus command and return the decoded status of (mode
301+
# value, command status)
302+
#
303+
# Due to what appears to be a silicon bug, we send GetIrqStatus here
304+
# instead of GetStatus. It seems that there is some specific sequence
305+
# where sending command GetStatus to the chip immediately after SetRX
306+
# (mode 5) will trip it it into an endless TX (mode 6) for no apparent
307+
# reason!
308+
#
309+
# It doesn't seem to be timing dependent, all that's needed is that
310+
# ordering (and the modem works fine otherwise).
311+
#
312+
# As a workaround we send the GetIrqStatus command and read an extra two
313+
# bytes that are then ignored...
314+
res = self._cmd("B", _CMD_GET_IRQ_STATUS, n_read=3)[0]
301315
return self._decode_status(res)
302316

303317
def _check_error(self):

0 commit comments

Comments
 (0)