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

SX127xSetOpMode improvement #66

Closed
JiapengLi opened this issue Apr 15, 2016 · 2 comments
Closed

SX127xSetOpMode improvement #66

JiapengLi opened this issue Apr 15, 2016 · 2 comments

Comments

@JiapengLi
Copy link

Below is the implementation of SetOpMode, static variable opModePrev is used to keep previous mode, but this value is not always synced with the acctual mode, like situation user transmits one packet, when finished, SX127x will enter standby mode automatically, but opModePrev now is still in transmit mode, this will cause issue, if user doesn't call SetOpMode to set standby/sleep manually (actually not necessary for LoRa chip) before next transmitting, then the transmit will fail.

Related patch is submitted but should have not solved the issue completely. @djaeckle
008f8dd

Two possible solutions:

  1. Abandon static local variable, use global value instead. Update the value when LoRa chip mode is
    changed internally automactically (TXDONE, RXDONE, and reset operation need sync the value to standby mode)
  2. Abandon static local variable, read OpMode value from lora chip directly. This way costs some extra MCU resources but not much, should be more clean than previous one.
void SX1276SetOpMode( uint8_t opMode )
{
    static uint8_t opModePrev = RF_OPMODE_STANDBY;

    if( opMode != opModePrev )
    {
        opModePrev = opMode;
        if( opMode == RF_OPMODE_SLEEP )
        {
            SX1276SetAntSwLowPower( true );
        }
        else
        {
            SX1276SetAntSwLowPower( false );
            if( opMode == RF_OPMODE_TRANSMITTER )
            {
                 SX1276SetAntSw( 1 );
            }
            else
            {
                 SX1276SetAntSw( 0 );
            }
        }
        SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RF_OPMODE_MASK ) | opMode );
    }
}
@mluis1
Copy link
Contributor

mluis1 commented Apr 15, 2016

Thanks @JiapengLi .

I'll add the below change to the next develop branch commit. (The same applies to SX1272)

void SX1276SetOpMode( uint8_t opMode )
{
    if( opMode == RF_OPMODE_SLEEP )
    {
        SX1276SetAntSwLowPower( true );
    }
    else
    {
        SX1276SetAntSwLowPower( false );
        if( opMode == RF_OPMODE_TRANSMITTER )
        {
             SX1276SetAntSw( 1 );
        }
        else
        {
             SX1276SetAntSw( 0 );
        }
    }
    SX1276Write( REG_OPMODE, ( SX1276Read( REG_OPMODE ) & RF_OPMODE_MASK ) | opMode );
}

@JiapengLi
Copy link
Author

Thank you, Miguel.

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

No branches or pull requests

2 participants