Skip to content

Commit

Permalink
Add radio function to read the radio syncword uint16_t syncword = Rad…
Browse files Browse the repository at this point in the history
…io.GetSyncWord(void);
  • Loading branch information
beegee-tokyo committed Jan 5, 2025
1 parent 847b224 commit 8aa1f44
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "SX126x-Arduino",
"version": "2.0.28",
"version": "2.0.29",
"keywords": [
"lora",
"Semtech",
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SX126x-Arduino
version=2.0.28
version=2.0.29
author=Bernd Giesecke <[email protected]>
maintainer=Bernd Giesecke <[email protected]>
sentence=Arduino library to use Semtech SX126x LoRa chips and modules to communicate
Expand Down
24 changes: 18 additions & 6 deletions src/boards/mcu/board.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand Down
8 changes: 7 additions & 1 deletion src/radio/radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*
Expand Down
20 changes: 19 additions & 1 deletion src/radio/sx126x/radio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]
*
Expand Down Expand Up @@ -406,6 +413,7 @@ const struct Radio_s Radio =
RadioSetMaxPayloadLength,
RadioSetPublicNetwork,
RadioSetCustomSyncWord,
RadioGetSyncWord,
RadioGetWakeupTime,
RadioBgIrqProcess,
RadioIrqProcess,
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/radio/sx126x/sx126x.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
7 changes: 7 additions & 0 deletions src/radio/sx126x/sx126x.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit 8aa1f44

Please sign in to comment.