From 83c25ee8a283cbb71720677fe21876c0bb43d32a Mon Sep 17 00:00:00 2001 From: Linar Yusupov Date: Mon, 5 Feb 2024 07:11:57 +0300 Subject: [PATCH] SX12xx and CC13x2 radios: align legacy protocol carrier frequency setting with Nordic nRF905 100 kHz (LF) or 200 kHz (HF) resolution (step) --- .../firmware/source/SoftRF/src/driver/RF.cpp | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/software/firmware/source/SoftRF/src/driver/RF.cpp b/software/firmware/source/SoftRF/src/driver/RF.cpp index 7a55e0b09..e44598683 100644 --- a/software/firmware/source/SoftRF/src/driver/RF.cpp +++ b/software/firmware/source/SoftRF/src/driver/RF.cpp @@ -872,6 +872,15 @@ static void sx12xx_channel(int8_t channel) uint32_t frequency = RF_FreqPlan.getChanFrequency((uint8_t) channel); int8_t fc = settings->freq_corr; + if (LMIC.protocol->type == RF_PROTOCOL_LEGACY) { + nRF905_band_t nrf_band; + uint32_t nrf_freq_resolution; + + nrf_band = (frequency >= 844800000UL ? NRF905_BAND_868 : NRF905_BAND_433); + nrf_freq_resolution = (nrf_band == NRF905_BAND_433 ? 100000UL : 200000UL); + frequency -= (frequency % nrf_freq_resolution); + } + //Serial.print("frequency: "); Serial.println(frequency); if (sx12xx_receive_active) { @@ -892,7 +901,7 @@ static void sx12xx_channel(int8_t channel) } #if defined(ENABLE_PROL) - if (settings->rf_protocol == RF_PROTOCOL_APRS) { + if (LMIC.protocol->type == RF_PROTOCOL_APRS) { frequency = 433775000UL; } #endif /* ENABLE_PROL */ @@ -1847,6 +1856,15 @@ static void cc13xx_channel(int8_t channel) channel != cc13xx_channel_prev) { uint32_t frequency = RF_FreqPlan.getChanFrequency((uint8_t) channel); + if (settings->rf_protocol == RF_PROTOCOL_LEGACY) { + nRF905_band_t nrf_band; + uint32_t nrf_freq_resolution; + + nrf_band = (frequency >= 844800000UL ? NRF905_BAND_868 : NRF905_BAND_433); + nrf_freq_resolution = (nrf_band == NRF905_BAND_433 ? 100000UL : 200000UL); + frequency -= (frequency % nrf_freq_resolution); + } + if (cc13xx_receive_active) { /* restart Rx upon a channel switch */ EasyLink_abort();