diff --git a/CHANGELOG.md b/CHANGELOG.md index ff93227..c5e141c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ Arduino library for LoRa communication with Semtech SX126x chips. It is based on # Release Notes +# V2.0.29 Add read the Syncword function + - Add radio function to read the radio syncword uint16_t syncword = Radio.GetSyncWord(void); + # V2.0.28 Add custom Syncword and Low DataRate optimization - Add radio function to set a custom Syncword Radio.SetCustomSyncWord(uint16_t syncword); - Add radio function to enforce Low DataRate optimization Radio.EnforceLowDRopt(bool enforce); diff --git a/README.md b/README.md index 044d643..9e21575 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ---- ## Changelog [Code releases](CHANGELOG.md) +- 2025-01-05 Add function to read the Syncword + - Add radio function to read the radio syncword uint16_t syncword = Radio.GetSyncWord(void); - 2025-01-01 Add custom Syncword and Low DataRate optimization - Add radio function to set a custom Syncword Radio.SetCustomSyncWord(uint16_t syncword); - Add radio function to enforce Low DataRate optimization Radio.EnforceLowDRopt(bool enforce); diff --git a/library.json b/library.json index b306331..15800f5 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "SX126x-Arduino", - "version": "2.0.28", + "version": "2.0.29", "keywords": [ "lora", "Semtech", diff --git a/library.properties b/library.properties index f198cdc..7a1e6da 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SX126x-Arduino -version=2.0.28 +version=2.0.29 author=Bernd Giesecke maintainer=Bernd Giesecke sentence=Arduino library to use Semtech SX126x LoRa chips and modules to communicate diff --git a/src/boards/mcu/board.cpp b/src/boards/mcu/board.cpp index c5ade04..fccc933 100644 --- a/src/boards/mcu/board.cpp +++ b/src/boards/mcu/board.cpp @@ -92,7 +92,9 @@ uint32_t lora_hardware_init(hw_config hwConfig) LOG_LIB("BRD", "SyncWord = %04X", readSyncWord); - if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + // There could be a custom syncword, better test for 0xFFFF + // if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + if (readSyncWord != 0xFFFF) { #if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 if (start_lora_task()) @@ -138,7 +140,9 @@ uint32_t lora_hardware_re_init(hw_config hwConfig) LOG_LIB("BRD", "SyncWord = %04X", readSyncWord); - if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + // There could be a custom syncword, better test for 0xFFFF + // if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + if (readSyncWord != 0xFFFF) { #if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 if (start_lora_task()) @@ -183,7 +187,9 @@ uint32_t lora_isp4520_init(int chipType) LOG_LIB("BRD", "SyncWord = %04X", readSyncWord); - if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + // There could be a custom syncword, better test for 0xFFFF + // if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + if (readSyncWord != 0xFFFF) { #if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 if (start_lora_task()) @@ -230,7 +236,9 @@ uint32_t lora_rak4630_init(void) LOG_LIB("BRD", "SyncWord = %04X", readSyncWord); - if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + // There could be a custom syncword, better test for 0xFFFF + // if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + if (readSyncWord != 0xFFFF) { #if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 if (start_lora_task()) @@ -283,7 +291,9 @@ uint32_t lora_rak11300_init(void) LOG_LIB("BRD", "SyncWord = %04X", readSyncWord); - if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + // There could be a custom syncword, better test for 0xFFFF + // if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + if (readSyncWord != 0xFFFF) { // If we are compiling for ESP32, nRF52 or RP2040 we start background task #if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 @@ -344,7 +354,9 @@ uint32_t lora_rak13300_init(void) LOG_LIB("BRD", "SyncWord = %04X", readSyncWord); - if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + // There could be a custom syncword, better test for 0xFFFF + // if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434)) + if (readSyncWord != 0xFFFF) { #if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 || defined ARDUINO_RAKWIRELESS_RAK11300 if (start_lora_task()) diff --git a/src/radio/radio.h b/src/radio/radio.h index f786994..08ff988 100644 --- a/src/radio/radio.h +++ b/src/radio/radio.h @@ -354,11 +354,17 @@ struct Radio_s /*! * \brief Sets a custom Sync-Word. Updates the sync byte. * - * \remark Applies to LoRa modem only + * \remark ATTENTION, changes the LoRaWAN sync word as well. Use with care. * * \param syncword 2 byte custom Sync-Word to be used */ void (*SetCustomSyncWord)(uint16_t syncword); + /*! + * \brief Get Sync-Word. + * + * \retval syncword current 2 byte custom Sync-Word + */ + uint16_t (*GetSyncWord)(void); /*! * \brief Gets the time required for the board plus radio to get out of sleep.[ms] * diff --git a/src/radio/sx126x/radio.cpp b/src/radio/sx126x/radio.cpp index b1d0843..74b3be9 100644 --- a/src/radio/sx126x/radio.cpp +++ b/src/radio/sx126x/radio.cpp @@ -325,12 +325,19 @@ void RadioSetPublicNetwork(bool enable); /*! * \brief Sets a custom Sync-Word. Updates the sync byte. * - * \remark Applies to LoRa modem only + * \remark ATTENTION, changes the LoRaWAN sync word as well. Use with care. * * \param syncword 2 byte custom Sync-Word to be used */ void RadioSetCustomSyncWord(uint16_t syncword); +/*! + * \brief Get current Sync-Word. + * + * \param syncword 2 byte custom Sync-Word in use + */ +uint16_t RadioGetSyncWord(void); + /*! * @brief Gets the time required for the board plus radio to get out of sleep.[ms] * @@ -406,6 +413,7 @@ const struct Radio_s Radio = RadioSetMaxPayloadLength, RadioSetPublicNetwork, RadioSetCustomSyncWord, + RadioGetSyncWord, RadioGetWakeupTime, RadioBgIrqProcess, RadioIrqProcess, @@ -1250,6 +1258,16 @@ void RadioSetCustomSyncWord(uint16_t syncword) SX126xWriteRegister(REG_LR_SYNCWORD + 1, syncword & 0xFF); } +uint16_t RadioGetSyncWord(void) +{ + uint8_t syncWord[8]; + RadioSetModem(MODEM_LORA); + syncWord[0] = SX126xReadRegister(REG_LR_SYNCWORD); + syncWord[1] = SX126xReadRegister(REG_LR_SYNCWORD + 1); + + return (uint16_t)(syncWord[0] << 8) + (uint16_t)(syncWord[1]); +} + uint32_t RadioGetWakeupTime(void) { if (_hwConfig.USE_DIO3_TCXO) diff --git a/src/radio/sx126x/sx126x.cpp b/src/radio/sx126x/sx126x.cpp index 541cbce..f1ef063 100644 --- a/src/radio/sx126x/sx126x.cpp +++ b/src/radio/sx126x/sx126x.cpp @@ -160,6 +160,12 @@ uint8_t SX126xSetSyncWord(uint8_t *syncWord) return 0; } +uint8_t SX126xGetSyncWord(uint8_t *syncWord) +{ + SX126xReadRegisters(REG_LR_SYNCWORDBASEADDRESS, syncWord, 8); + return 0; +} + void SX126xSetCrcSeed(uint16_t seed) { uint8_t buf[2]; diff --git a/src/radio/sx126x/sx126x.h b/src/radio/sx126x/sx126x.h index 7a550c3..d702c14 100644 --- a/src/radio/sx126x/sx126x.h +++ b/src/radio/sx126x/sx126x.h @@ -784,6 +784,13 @@ void SX126xSendPayload(uint8_t *payload, uint8_t size, uint32_t timeout); */ uint8_t SX126xSetSyncWord(uint8_t *syncWord); +/*! + * \brief Gets the current Sync Word given by index used in GFSK + * + * \retval 2 byte syncword + */ +uint16_t SX126xGetSyncWord(void); + /*! * \brief Sets the seed value for the LFSR used for the CRC calculation *