kopia lustrzana https://github.com/micropython/micropython-lib
lora-sx126x: Fix invalid default configuration after reset.
According to the docs, only freq_khz was needed for working output. However: - Without output_power setting, no output from SX1262 antenna (theory: output routed to the SX1261 antenna). - SF,BW,etc. settings were different from the SX127x power on defaults, so modems with an identical configuration were unable to communicate. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>pull/804/head
rodzic
4cc67065dd
commit
b712103519
|
@ -163,6 +163,9 @@ class _SX126x(BaseModem):
|
||||||
# 0x02 is 40us, default value appears undocumented but this is the SX1276 default
|
# 0x02 is 40us, default value appears undocumented but this is the SX1276 default
|
||||||
self._ramp_val = 0x02
|
self._ramp_val = 0x02
|
||||||
|
|
||||||
|
# Configure the SX126x at least once after reset
|
||||||
|
self._configured = False
|
||||||
|
|
||||||
if reset:
|
if reset:
|
||||||
# If the caller supplies a reset pin argument, reset the radio
|
# If the caller supplies a reset pin argument, reset the radio
|
||||||
reset.init(Pin.OUT, value=0)
|
reset.init(Pin.OUT, value=0)
|
||||||
|
@ -385,22 +388,22 @@ class _SX126x(BaseModem):
|
||||||
syncword = 0x0404 + ((syncword & 0x0F) << 4) + ((syncword & 0xF0) << 8)
|
syncword = 0x0404 + ((syncword & 0x0F) << 4) + ((syncword & 0xF0) << 8)
|
||||||
self._cmd(">BBH", _CMD_WRITE_REGISTER, _REG_LSYNCRH, syncword)
|
self._cmd(">BBH", _CMD_WRITE_REGISTER, _REG_LSYNCRH, syncword)
|
||||||
|
|
||||||
if "output_power" in lora_cfg:
|
if not self._configured or any(
|
||||||
|
key in lora_cfg for key in ("output_power", "pa_ramp_us", "tx_ant")
|
||||||
|
):
|
||||||
pa_config_args, self._output_power = self._get_pa_tx_params(
|
pa_config_args, self._output_power = self._get_pa_tx_params(
|
||||||
lora_cfg["output_power"], lora_cfg.get("tx_ant", None)
|
lora_cfg.get("output_power", self._output_power), lora_cfg.get("tx_ant", None)
|
||||||
)
|
)
|
||||||
self._cmd("BBBBB", _CMD_SET_PA_CONFIG, *pa_config_args)
|
self._cmd("BBBBB", _CMD_SET_PA_CONFIG, *pa_config_args)
|
||||||
|
|
||||||
if "pa_ramp_us" in lora_cfg:
|
if "pa_ramp_us" in lora_cfg:
|
||||||
self._ramp_val = self._get_pa_ramp_val(
|
self._ramp_val = self._get_pa_ramp_val(
|
||||||
lora_cfg, [10, 20, 40, 80, 200, 800, 1700, 3400]
|
lora_cfg, [10, 20, 40, 80, 200, 800, 1700, 3400]
|
||||||
)
|
)
|
||||||
|
|
||||||
if "output_power" in lora_cfg or "pa_ramp_us" in lora_cfg:
|
|
||||||
# Only send the SetTxParams command if power level or PA ramp time have changed
|
|
||||||
self._cmd("BBB", _CMD_SET_TX_PARAMS, self._output_power, self._ramp_val)
|
self._cmd("BBB", _CMD_SET_TX_PARAMS, self._output_power, self._ramp_val)
|
||||||
|
|
||||||
if any(key in lora_cfg for key in ("sf", "bw", "coding_rate")):
|
if not self._configured or any(key in lora_cfg for key in ("sf", "bw", "coding_rate")):
|
||||||
if "sf" in lora_cfg:
|
if "sf" in lora_cfg:
|
||||||
self._sf = lora_cfg["sf"]
|
self._sf = lora_cfg["sf"]
|
||||||
if self._sf < _CFG_SF_MIN or self._sf > _CFG_SF_MAX:
|
if self._sf < _CFG_SF_MIN or self._sf > _CFG_SF_MAX:
|
||||||
|
@ -441,6 +444,7 @@ class _SX126x(BaseModem):
|
||||||
self._reg_write(_REG_RX_GAIN, 0x96 if lora_cfg["rx_boost"] else 0x94)
|
self._reg_write(_REG_RX_GAIN, 0x96 if lora_cfg["rx_boost"] else 0x94)
|
||||||
|
|
||||||
self._check_error()
|
self._check_error()
|
||||||
|
self._configured = True
|
||||||
|
|
||||||
def _invert_workaround(self, enable):
|
def _invert_workaround(self, enable):
|
||||||
# Apply workaround for DS 15.4 Optimizing the Inverted IQ Operation
|
# Apply workaround for DS 15.4 Optimizing the Inverted IQ Operation
|
||||||
|
|
|
@ -37,10 +37,11 @@ class BaseModem:
|
||||||
self._ant_sw = ant_sw
|
self._ant_sw = ant_sw
|
||||||
self._irq_callback = None
|
self._irq_callback = None
|
||||||
|
|
||||||
# Common configuration settings that need to be tracked by all modem drivers
|
# Common configuration settings that need to be tracked by all modem drivers.
|
||||||
# (Note that subclasses may set these to other values in their constructors, to match
|
|
||||||
# the power-on-reset configuration of a particular modem.)
|
|
||||||
#
|
#
|
||||||
|
# Where modem hardware sets different values after reset, the driver should
|
||||||
|
# set them back to these defaults (if not provided by the user), so that
|
||||||
|
# behaviour remains consistent between different modems using the same driver.
|
||||||
self._rf_freq_hz = 0 # Needs to be set via configure()
|
self._rf_freq_hz = 0 # Needs to be set via configure()
|
||||||
self._sf = 7 # Spreading factor
|
self._sf = 7 # Spreading factor
|
||||||
self._bw_hz = 125000 # Reset value
|
self._bw_hz = 125000 # Reset value
|
||||||
|
|
Ładowanie…
Reference in New Issue