@@ -74,7 +74,6 @@ int16_t SX126x::beginFSK(float br, float freqDev, float rxBw, uint16_t preambleL
7474 this ->pulseShape = RADIOLIB_SX126X_GFSK_FILTER_GAUSS_0_5;
7575 this ->crcTypeFSK = RADIOLIB_SX126X_GFSK_CRC_2_BYTE_INV; // CCITT CRC configuration
7676 this ->preambleLengthFSK = preambleLength;
77- this ->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF;
7877
7978 // set module properties and perform initial setup
8079 int16_t state = this ->modSetup (tcxoVoltage, useRegulatorLDO, RADIOLIB_SX126X_PACKET_TYPE_GFSK);
@@ -468,8 +467,10 @@ int16_t SX126x::standby(uint8_t mode, bool wakeup) {
468467 this ->mod ->setRfSwitchState (Module::MODE_IDLE);
469468
470469 if (wakeup) {
471- // pull NSS low to wake up
472- this ->mod ->hal ->digitalWrite (this ->mod ->getCs (), this ->mod ->hal ->GpioLevelLow );
470+ // send a NOP command - this pulls the NSS low to exit the sleep mode,
471+ // while preventing interference with possible other SPI transactions
472+ // see https://github.com/jgromes/RadioLib/discussions/1364
473+ (void )this ->mod ->SPIwriteStream (RADIOLIB_SX126X_CMD_NOP, NULL , 0 , false , false );
473474 }
474475
475476 uint8_t data[] = { mode };
@@ -515,13 +516,15 @@ void SX126x::clearChannelScanAction() {
515516static unsigned long MAX_BUSY_TIME = 5000 ;
516517
517518int16_t SX126x::startTransmit (const uint8_t * data, size_t len, uint8_t addr) {
519+ (void )addr;
520+
518521 // check packet length
519522 if (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH) {
520523 return (RADIOLIB_ERR_PACKET_TOO_LONG);
521524 }
522525
523526 // maximum packet length is decreased by 1 when address filtering is active
524- if ((this -> addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) && (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH - 1 )) {
527+ if ((RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) && (len > RADIOLIB_SX126X_MAX_PACKET_LENGTH - 1 )) {
525528 return (RADIOLIB_ERR_PACKET_TOO_LONG);
526529 }
527530
@@ -532,13 +535,7 @@ int16_t SX126x::startTransmit(const uint8_t* data, size_t len, uint8_t addr) {
532535 state = setPacketParams (this ->preambleLengthLoRa , this ->crcTypeLoRa , len, this ->headerType , this ->invertIQEnabled );
533536
534537 } else if (modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
535- state = setPacketParamsFSK (this ->preambleLengthFSK , this ->crcTypeFSK , this ->syncWordLength , this ->addrComp , this ->whitening , this ->packetType , len);
536-
537- // address is taken from the register
538- if (this ->addrComp != RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF) {
539- RADIOLIB_ASSERT (state);
540- state = writeRegister (RADIOLIB_SX126X_REG_NODE_ADDRESS, &addr, 1 );
541- }
538+ state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this ->whitening , this ->packetType , len);
542539
543540 } else if (modem != RADIOLIB_SX126X_PACKET_TYPE_LR_FHSS) {
544541 return (RADIOLIB_ERR_UNKNOWN);
@@ -642,12 +639,6 @@ int16_t SX126x::finishTransmit() {
642639 int16_t state = clearIrqStatus ();
643640 RADIOLIB_ASSERT (state);
644641
645- // restore the original node address
646- if (getPacketType () == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
647- state = writeRegister (RADIOLIB_SX126X_REG_NODE_ADDRESS, &this ->nodeAddr , 1 );
648- RADIOLIB_ASSERT (state);
649- }
650-
651642 // set mode to standby to disable transmitter/RF switch
652643 return (standby ());
653644}
@@ -657,7 +648,12 @@ int16_t SX126x::startReceive() {
657648}
658649
659650int16_t SX126x::startReceive (uint32_t timeout, RadioLibIrqFlags_t irqFlags, RadioLibIrqFlags_t irqMask, size_t len) {
660- (void )len;
651+ // in implicit header mode, use the provided length if it is nonzero
652+ // otherwise we trust the user has previously set the payload length manually
653+ if ((this ->headerType == RADIOLIB_SX126X_LORA_HEADER_IMPLICIT) && (len != 0 )) {
654+ this ->implicitLen = len;
655+ }
656+
661657 int16_t state = startReceiveCommon (timeout, irqFlags, irqMask);
662658 RADIOLIB_ASSERT (state);
663659
@@ -759,7 +755,7 @@ int16_t SX126x::startReceiveCommon(uint32_t timeout, RadioLibIrqFlags_t irqFlags
759755 if (modem == RADIOLIB_SX126X_PACKET_TYPE_LORA) {
760756 state = setPacketParams (this ->preambleLengthLoRa , this ->crcTypeLoRa , this ->implicitLen , this ->headerType , this ->invertIQEnabled );
761757 } else if (modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
762- state = setPacketParamsFSK (this ->preambleLengthFSK , this ->crcTypeFSK , this ->syncWordLength , this ->addrComp , this ->whitening , this ->packetType );
758+ state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF , this ->whitening , this ->packetType );
763759 } else {
764760 return (RADIOLIB_ERR_UNKNOWN);
765761 }
@@ -984,12 +980,15 @@ int16_t SX126x::setPreambleLength(size_t preambleLength) {
984980 return (setPacketParams (this ->preambleLengthLoRa , this ->crcTypeLoRa , this ->implicitLen , this ->headerType , this ->invertIQEnabled ));
985981 } else if (modem == RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
986982 this ->preambleLengthFSK = preambleLength;
987- this ->preambleDetLength = preambleLength >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
988- preambleLength >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
989- preambleLength >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
990- preambleLength > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
983+ // maximum preamble detector length is limited by sync word length
984+ // for details, see the note in SX1261 datasheet, Rev 2.1, section 6.2.2.1, page 45
985+ uint8_t maxDetLen = RADIOLIB_MIN (this ->syncWordLength , this ->preambleLengthFSK );
986+ this ->preambleDetLength = maxDetLen >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
987+ maxDetLen >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
988+ maxDetLen >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
989+ maxDetLen > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
991990 RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF;
992- return (setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this -> addrComp , this ->whitening , this ->packetType ));
991+ return (setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF , this ->whitening , this ->packetType ));
993992 }
994993
995994 return (RADIOLIB_ERR_UNKNOWN);
@@ -1225,7 +1224,16 @@ int16_t SX126x::setSyncWord(uint8_t* syncWord, size_t len) {
12251224
12261225 // update packet parameters
12271226 this ->syncWordLength = len * 8 ;
1228- state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this ->addrComp , this ->whitening , this ->packetType );
1227+
1228+ // maximum preamble detector length is limited by sync word length
1229+ // for details, see the note in SX1261 datasheet, Rev 2.1, section 6.2.2.1, page 45
1230+ uint8_t maxDetLen = RADIOLIB_MIN (this ->syncWordLength , this ->preambleLengthFSK );
1231+ this ->preambleDetLength = maxDetLen >= 32 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_32 :
1232+ maxDetLen >= 24 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_24 :
1233+ maxDetLen >= 16 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_16 :
1234+ maxDetLen > 0 ? RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_8 :
1235+ RADIOLIB_SX126X_GFSK_PREAMBLE_DETECT_OFF;
1236+ state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF, this ->whitening , this ->packetType );
12291237
12301238 return (state);
12311239
@@ -1267,52 +1275,6 @@ int16_t SX126x::setSyncBits(uint8_t *syncWord, uint8_t bitsLen) {
12671275 return (setSyncWord (syncWord, bytesLen));
12681276}
12691277
1270- int16_t SX126x::setNodeAddress (uint8_t addr) {
1271- // check active modem
1272- if (getPacketType () != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
1273- return (RADIOLIB_ERR_WRONG_MODEM);
1274- }
1275-
1276- // enable address filtering (node only)
1277- this ->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE;
1278- int16_t state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this ->addrComp , this ->whitening , this ->packetType );
1279- RADIOLIB_ASSERT (state);
1280-
1281- // set node address
1282- this ->nodeAddr = addr;
1283- state = writeRegister (RADIOLIB_SX126X_REG_NODE_ADDRESS, &addr, 1 );
1284-
1285- return (state);
1286- }
1287-
1288- int16_t SX126x::setBroadcastAddress (uint8_t broadAddr) {
1289- // check active modem
1290- if (getPacketType () != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
1291- return (RADIOLIB_ERR_WRONG_MODEM);
1292- }
1293-
1294- // enable address filtering (node and broadcast)
1295- this ->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_NODE_BROADCAST;
1296- int16_t state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this ->addrComp , this ->whitening , this ->packetType );
1297- RADIOLIB_ASSERT (state);
1298-
1299- // set broadcast address
1300- state = writeRegister (RADIOLIB_SX126X_REG_BROADCAST_ADDRESS, &broadAddr, 1 );
1301-
1302- return (state);
1303- }
1304-
1305- int16_t SX126x::disableAddressFiltering () {
1306- // check active modem
1307- if (getPacketType () != RADIOLIB_SX126X_PACKET_TYPE_GFSK) {
1308- return (RADIOLIB_ERR_WRONG_MODEM);
1309- }
1310-
1311- // disable address filtering
1312- this ->addrComp = RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF;
1313- return (setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this ->addrComp , this ->whitening ));
1314- }
1315-
13161278int16_t SX126x::setCRC (uint8_t len, uint16_t initial, uint16_t polynomial, bool inverted) {
13171279 // check active modem
13181280 uint8_t modem = getPacketType ();
@@ -1341,7 +1303,7 @@ int16_t SX126x::setCRC(uint8_t len, uint16_t initial, uint16_t polynomial, bool
13411303 return (RADIOLIB_ERR_INVALID_CRC_CONFIGURATION);
13421304 }
13431305
1344- int16_t state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this -> addrComp , this ->whitening , this ->packetType );
1306+ int16_t state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF , this ->whitening , this ->packetType );
13451307 RADIOLIB_ASSERT (state);
13461308
13471309 // write initial CRC value
@@ -1383,7 +1345,7 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) {
13831345 // disable whitening
13841346 this ->whitening = RADIOLIB_SX126X_GFSK_WHITENING_OFF;
13851347
1386- state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this -> addrComp , this ->whitening , this ->packetType );
1348+ state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF , this ->whitening , this ->packetType );
13871349 RADIOLIB_ASSERT (state);
13881350
13891351 } else {
@@ -1403,7 +1365,7 @@ int16_t SX126x::setWhitening(bool enabled, uint16_t initial) {
14031365 state = writeRegister (RADIOLIB_SX126X_REG_WHITENING_INITIAL_MSB, data, 2 );
14041366 RADIOLIB_ASSERT (state);
14051367
1406- state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this -> addrComp , this ->whitening , this ->packetType );
1368+ state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF , this ->whitening , this ->packetType );
14071369 RADIOLIB_ASSERT (state);
14081370 }
14091371 return (state);
@@ -2065,7 +2027,7 @@ int16_t SX126x::setPacketMode(uint8_t mode, uint8_t len) {
20652027 }
20662028
20672029 // set requested packet mode
2068- int16_t state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , this -> addrComp , this ->whitening , mode, len);
2030+ int16_t state = setPacketParamsFSK (this ->preambleLengthFSK , this ->preambleDetLength , this ->crcTypeFSK , this ->syncWordLength , RADIOLIB_SX126X_GFSK_ADDRESS_FILT_OFF , this ->whitening , mode, len);
20692031 RADIOLIB_ASSERT (state);
20702032
20712033 // update cached value
0 commit comments