Skip to content

Commit 8aa1f44

Browse files
committed
Add radio function to read the radio syncword uint16_t syncword = Radio.GetSyncWord(void);
1 parent 847b224 commit 8aa1f44

File tree

9 files changed

+64
-10
lines changed

9 files changed

+64
-10
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ Arduino library for LoRa communication with Semtech SX126x chips. It is based on
44

55
# Release Notes
66

7+
# V2.0.29 Add read the Syncword function
8+
- Add radio function to read the radio syncword uint16_t syncword = Radio.GetSyncWord(void);
9+
710
# V2.0.28 Add custom Syncword and Low DataRate optimization
811
- Add radio function to set a custom Syncword Radio.SetCustomSyncWord(uint16_t syncword);
912
- Add radio function to enforce Low DataRate optimization Radio.EnforceLowDRopt(bool enforce);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8888
----
8989
## Changelog
9090
[Code releases](CHANGELOG.md)
91+
- 2025-01-05 Add function to read the Syncword
92+
- Add radio function to read the radio syncword uint16_t syncword = Radio.GetSyncWord(void);
9193
- 2025-01-01 Add custom Syncword and Low DataRate optimization
9294
- Add radio function to set a custom Syncword Radio.SetCustomSyncWord(uint16_t syncword);
9395
- Add radio function to enforce Low DataRate optimization Radio.EnforceLowDRopt(bool enforce);

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "SX126x-Arduino",
3-
"version": "2.0.28",
3+
"version": "2.0.29",
44
"keywords": [
55
"lora",
66
"Semtech",

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=SX126x-Arduino
2-
version=2.0.28
2+
version=2.0.29
33
author=Bernd Giesecke <beegee@giesecke.tk>
44
maintainer=Bernd Giesecke <beegee@giesecke.tk>
55
sentence=Arduino library to use Semtech SX126x LoRa chips and modules to communicate

src/boards/mcu/board.cpp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ uint32_t lora_hardware_init(hw_config hwConfig)
9292

9393
LOG_LIB("BRD", "SyncWord = %04X", readSyncWord);
9494

95-
if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
95+
// There could be a custom syncword, better test for 0xFFFF
96+
// if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
97+
if (readSyncWord != 0xFFFF)
9698
{
9799
#if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040
98100
if (start_lora_task())
@@ -138,7 +140,9 @@ uint32_t lora_hardware_re_init(hw_config hwConfig)
138140

139141
LOG_LIB("BRD", "SyncWord = %04X", readSyncWord);
140142

141-
if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
143+
// There could be a custom syncword, better test for 0xFFFF
144+
// if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
145+
if (readSyncWord != 0xFFFF)
142146
{
143147
#if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040
144148
if (start_lora_task())
@@ -183,7 +187,9 @@ uint32_t lora_isp4520_init(int chipType)
183187

184188
LOG_LIB("BRD", "SyncWord = %04X", readSyncWord);
185189

186-
if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
190+
// There could be a custom syncword, better test for 0xFFFF
191+
// if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
192+
if (readSyncWord != 0xFFFF)
187193
{
188194
#if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040
189195
if (start_lora_task())
@@ -230,7 +236,9 @@ uint32_t lora_rak4630_init(void)
230236

231237
LOG_LIB("BRD", "SyncWord = %04X", readSyncWord);
232238

233-
if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
239+
// There could be a custom syncword, better test for 0xFFFF
240+
// if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
241+
if (readSyncWord != 0xFFFF)
234242
{
235243
#if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040
236244
if (start_lora_task())
@@ -283,7 +291,9 @@ uint32_t lora_rak11300_init(void)
283291

284292
LOG_LIB("BRD", "SyncWord = %04X", readSyncWord);
285293

286-
if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
294+
// There could be a custom syncword, better test for 0xFFFF
295+
// if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
296+
if (readSyncWord != 0xFFFF)
287297
{
288298
// If we are compiling for ESP32, nRF52 or RP2040 we start background task
289299
#if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040
@@ -344,7 +354,9 @@ uint32_t lora_rak13300_init(void)
344354

345355
LOG_LIB("BRD", "SyncWord = %04X", readSyncWord);
346356

347-
if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
357+
// There could be a custom syncword, better test for 0xFFFF
358+
// if ((readSyncWord == 0x2414) || (readSyncWord == 0x4434))
359+
if (readSyncWord != 0xFFFF)
348360
{
349361
#if defined NRF52_SERIES || defined ESP32 || defined ARDUINO_ARCH_RP2040 || defined ARDUINO_RAKWIRELESS_RAK11300
350362
if (start_lora_task())

src/radio/radio.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,11 +354,17 @@ struct Radio_s
354354
/*!
355355
* \brief Sets a custom Sync-Word. Updates the sync byte.
356356
*
357-
* \remark Applies to LoRa modem only
357+
* \remark ATTENTION, changes the LoRaWAN sync word as well. Use with care.
358358
*
359359
* \param syncword 2 byte custom Sync-Word to be used
360360
*/
361361
void (*SetCustomSyncWord)(uint16_t syncword);
362+
/*!
363+
* \brief Get Sync-Word.
364+
*
365+
* \retval syncword current 2 byte custom Sync-Word
366+
*/
367+
uint16_t (*GetSyncWord)(void);
362368
/*!
363369
* \brief Gets the time required for the board plus radio to get out of sleep.[ms]
364370
*

src/radio/sx126x/radio.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,19 @@ void RadioSetPublicNetwork(bool enable);
325325
/*!
326326
* \brief Sets a custom Sync-Word. Updates the sync byte.
327327
*
328-
* \remark Applies to LoRa modem only
328+
* \remark ATTENTION, changes the LoRaWAN sync word as well. Use with care.
329329
*
330330
* \param syncword 2 byte custom Sync-Word to be used
331331
*/
332332
void RadioSetCustomSyncWord(uint16_t syncword);
333333

334+
/*!
335+
* \brief Get current Sync-Word.
336+
*
337+
* \param syncword 2 byte custom Sync-Word in use
338+
*/
339+
uint16_t RadioGetSyncWord(void);
340+
334341
/*!
335342
* @brief Gets the time required for the board plus radio to get out of sleep.[ms]
336343
*
@@ -406,6 +413,7 @@ const struct Radio_s Radio =
406413
RadioSetMaxPayloadLength,
407414
RadioSetPublicNetwork,
408415
RadioSetCustomSyncWord,
416+
RadioGetSyncWord,
409417
RadioGetWakeupTime,
410418
RadioBgIrqProcess,
411419
RadioIrqProcess,
@@ -1250,6 +1258,16 @@ void RadioSetCustomSyncWord(uint16_t syncword)
12501258
SX126xWriteRegister(REG_LR_SYNCWORD + 1, syncword & 0xFF);
12511259
}
12521260

1261+
uint16_t RadioGetSyncWord(void)
1262+
{
1263+
uint8_t syncWord[8];
1264+
RadioSetModem(MODEM_LORA);
1265+
syncWord[0] = SX126xReadRegister(REG_LR_SYNCWORD);
1266+
syncWord[1] = SX126xReadRegister(REG_LR_SYNCWORD + 1);
1267+
1268+
return (uint16_t)(syncWord[0] << 8) + (uint16_t)(syncWord[1]);
1269+
}
1270+
12531271
uint32_t RadioGetWakeupTime(void)
12541272
{
12551273
if (_hwConfig.USE_DIO3_TCXO)

src/radio/sx126x/sx126x.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ uint8_t SX126xSetSyncWord(uint8_t *syncWord)
160160
return 0;
161161
}
162162

163+
uint8_t SX126xGetSyncWord(uint8_t *syncWord)
164+
{
165+
SX126xReadRegisters(REG_LR_SYNCWORDBASEADDRESS, syncWord, 8);
166+
return 0;
167+
}
168+
163169
void SX126xSetCrcSeed(uint16_t seed)
164170
{
165171
uint8_t buf[2];

src/radio/sx126x/sx126x.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,13 @@ void SX126xSendPayload(uint8_t *payload, uint8_t size, uint32_t timeout);
784784
*/
785785
uint8_t SX126xSetSyncWord(uint8_t *syncWord);
786786

787+
/*!
788+
* \brief Gets the current Sync Word given by index used in GFSK
789+
*
790+
* \retval 2 byte syncword
791+
*/
792+
uint16_t SX126xGetSyncWord(void);
793+
787794
/*!
788795
* \brief Sets the seed value for the LFSR used for the CRC calculation
789796
*

0 commit comments

Comments
 (0)