Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Function to set DIO2 of SX126x chips to be used as RF antenna switch #17

Merged
merged 7 commits into from
Jun 4, 2019
Merged

Function to set DIO2 of SX126x chips to be used as RF antenna switch #17

merged 7 commits into from
Jun 4, 2019

Conversation

beegee-tokyo
Copy link
Contributor

Add function to set DIO2 of SX126x chips to be used as RF antenna switch.
Based on example design of Semtech and used in many modules.

This breaks the CAD function as DIO2 cannot be used as IRQ output.

Signed-off-by: Bernd Giesecke [email protected]

…tch (based on example design of Semtech and used in many modules).

This breaks the CAD function as DIO2 cannot be used as IRQ output.

Signed-off-by: Bernd Giesecke <[email protected]>
@beegee-tokyo
Copy link
Contributor Author

Tested on two modules

  • eByte E22-900M which does not use DIO2 as RF antenna switch
  • Insight ISP4520 which does use DIO2 as RF antenna switch

TODO
Get CAD function to work again (e.g. by using DIO3 if available).

src/Module.h Outdated Show resolved Hide resolved
src/Module.cpp Outdated Show resolved Hide resolved
src/Module.h Outdated Show resolved Hide resolved
src/modules/SX126x.cpp Outdated Show resolved Hide resolved
src/modules/SX126x.h Outdated Show resolved Hide resolved
@jgromes
Copy link
Owner

jgromes commented Jun 4, 2019

Also, I don't think it't a good idea to use DIO3 for CAD timeout. DIO3 must be used on some modules for TCXO control.

If RF control on DIO2 is enabled, CAD should be disabled entirely.

@beegee-tokyo
Copy link
Contributor Author

Testing the changes right now. Function moved to SX126x.cpp, memory leak removed, simplified, removed unnecessary functions.

Question before I push the changes.

Do you want a new error value for scanChannel() if DIO2 is used for RF antenna switch?

@jgromes
Copy link
Owner

jgromes commented Jun 4, 2019

Since that's quite a unique error, I think a new status code is a good idea. It should have the value -708.

@beegee-tokyo
Copy link
Contributor Author

/*!
  \brief SX126x scan channel not possible because DIO2 is used as RF antenna switch.
*/
#define ERR_DIO2_UNAVAIL_CAD_FAILED           -708

and

int16_t SX126x::scanChannel() {
  // check active modem
  if(getPacketType() != SX126X_PACKET_TYPE_LORA) {
    return(ERR_WRONG_MODEM);
  }

  if (_dio2RfSwitch) {
    // If DIO2 is used as RF switch this function does not work
    return(ERR_DIO2_UNAVAIL_CAD_FAILED);
  }
...

Added new error code
Removed memory leak

Signed-off-by: Bernd Giesecke <[email protected]>
@beegee-tokyo
Copy link
Contributor Author

Should be ok now.

Another thing, I get a compile error on ESP8266 module using PlatformIO. I am not compiling for ESP8266 or including ESP8266.h from the lib (but it is included in RadioLib.h)!

Compiling .pioenvs\LoraSender_4520\libeb3\RadioLib-DIO2\RadioLib.cpp.o
Compiling .pioenvs\LoraSender_4520\libeb3\RadioLib-DIO2\modules\CC1101.cpp.o
Compiling .pioenvs\LoraSender_4520\libeb3\RadioLib-DIO2\modules\ESP8266.cpp.o
Compiling .pioenvs\LoraSender_4520\libeb3\RadioLib-DIO2\modules\HC05.cpp.o
lib\RadioLib-DIO2\src\modules\ESP8266.cpp:183:10: error: prototype for 'uint16_t ESP8266::getNumBytes(uint32_t, size_t)' does not match any in class 'ESP8266'
uint16_t ESP8266::getNumBytes(uint32_t timeout, size_t minBytes) {
^~~~~~~
In file included from lib\RadioLib-DIO2\src\modules\ESP8266.cpp:1:0:
lib\RadioLib-DIO2\src\modules\ESP8266.h:55:12: error: candidate is: virtual size_t ESP8266::getNumBytes(uint32_t, size_t)
size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10);
^~~~~~~~~~~
*** [.pioenvs\LoraSender_4520\libeb3\RadioLib-DIO2\modules\ESP8266.cpp.o] Error 1

The cause is that in ESP8266.h the function is declared as

    size_t getNumBytes(uint32_t timeout = 10000, size_t minBytes = 10);

but in ESP8266.cpp the function is set as

uint16_t ESP8266::getNumBytes(uint32_t timeout, size_t minBytes) {

Will include it in this commit.

Copy link
Owner

@jgromes jgromes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're almost done here. Could you also add a new keyword to keywords.txt? Please use tab to separate the keyword and the type (i.e. actual tab, not spaces).

src/modules/SX126x.cpp Outdated Show resolved Hide resolved
src/modules/SX126x.cpp Outdated Show resolved Hide resolved
Signed-off-by: Bernd Giesecke <[email protected]>
Signed-off-by: Bernd Giesecke <[email protected]>
@jgromes jgromes merged commit ee86ff8 into jgromes:master Jun 4, 2019
@jgromes
Copy link
Owner

jgromes commented Jun 4, 2019

All looks good now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants