Ejemplo n.º 1
0
void SX1276LoRaInit( void )
{
   
    SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );	
	SX1276LoRaSetDefaults( );
		
	SX1276ReadBuffer( 0x1,&SX1276LR, 0x70 - 1 );
      
	SX1276Read( REG_LR_VERSION, &SX1276LR.RegVersion );
	 
    // set the RF settings 
    SX1276LoRaSetRFFrequency( LoRaSettings.RFFrequency,&SX1276LR );
    SX1276LoRaSetRFPower_2( LoRaSettings.Power,&SX1276LR );
    SX1276LoRaSetSpreadingFactor( LoRaSettings.SpreadingFactor,&SX1276LR ); // SF6 only operates in implicit header mode.
    SX1276LoRaSetErrorCoding( LoRaSettings.ErrorCoding,&SX1276LR );
    SX1276LoRaSetPacketCrcOn( LoRaSettings.CrcOn,&SX1276LR );
    SX1276LoRaSetSignalBandwidth( LoRaSettings.SignalBw,&SX1276LR );
    
    SX1276LoRaSetImplicitHeaderOn( LoRaSettings.ImplicitHeaderOn,&SX1276LR );
    SX1276LoRaSetSymbTimeout( 0x3FF,&SX1276LR );	//Maximum - casove okno pro hledani preamble v single rezimu
    SX1276LoRaSetPayloadLength( LoRaSettings.PayloadLength,&SX1276LR );	//
   // SX1276LoRaSetLowDatarateOptimize( true,&SX1276LR );	//dela problemy - u delsiho paketu je rozsypany caj
    
	/*AGC AUTO*/
 	SX1276Read( REG_LR_MODEMCONFIG3,&SX1276LR.RegModemConfig3 );
 	SX1276LR.RegModemConfig3|=0x4;
 	SX1276Write( REG_LR_MODEMCONFIG3,SX1276LR.RegModemConfig3 );
	SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );
}
Ejemplo n.º 2
0
void SX1276LoRaInit( void )
{
	  
    RFLRState = RFLR_STATE_IDLE;

    SX1276LoRaSetDefaults( );				// 读取XS1276的版本号到SX1276LR->RegVersion
    
    SX1276ReadBuffer( REG_LR_OPMODE, SX1276Regs + 1, 0x70 - 1 );		// 从REG_LR_OPMODE地址开始连续读出0x6F个寄存器的值到SX1276Regs[1...0x6F]
    
    SX1276LR->RegLna = RFLR_LNA_GAIN_G1;

    SX1276WriteBuffer( REG_LR_OPMODE, SX1276Regs + 1, 0x70 - 1 );

    // set the RF settings 
    SX1276LoRaSetRFFrequency( LoRaSettings.RFFrequency );
    SX1276LoRaSetSpreadingFactor( LoRaSettings.SpreadingFactor ); // SF6 only operates in implicit header mode.
    SX1276LoRaSetErrorCoding( LoRaSettings.ErrorCoding );
    SX1276LoRaSetPacketCrcOn( LoRaSettings.CrcOn );
    SX1276LoRaSetSignalBandwidth( LoRaSettings.SignalBw );

    SX1276LoRaSetImplicitHeaderOn( LoRaSettings.ImplicitHeaderOn );
    SX1276LoRaSetSymbTimeout( 0x3FF );
    SX1276LoRaSetPayloadLength( LoRaSettings.PayloadLength );
    SX1276LoRaSetLowDatarateOptimize( FALSE );

#if( ( MODULE_SX1276RF1IAS == 1 ) || ( MODULE_SX1276RF1KAS == 1 ) )
    if( LoRaSettings.RFFrequency > 860000000 )
    {
        SX1276LoRaSetPAOutput( RFLR_PACONFIG_PASELECT_RFO );
        SX1276LoRaSetPa20dBm( FALSE );
        LoRaSettings.Power = 14;
        SX1276LoRaSetRFPower( LoRaSettings.Power );
    }
    else
    {
        SX1276LoRaSetPAOutput( RFLR_PACONFIG_PASELECT_PABOOST );
        SX1276LoRaSetPa20dBm( TRUE );
        LoRaSettings.Power = 20;
        SX1276LoRaSetRFPower( LoRaSettings.Power );		
    } 
#elif( MODULE_SX1276RF1JAS == 1 )
    if( LoRaSettings.RFFrequency > 860000000 )
    {
        SX1276LoRaSetPAOutput( RFLR_PACONFIG_PASELECT_PABOOST );
        SX1276LoRaSetPa20dBm( TRUE );
        LoRaSettings.Power = 20;
        SX1276LoRaSetRFPower( LoRaSettings.Power );
    }
    else
    {
        SX1276LoRaSetPAOutput( RFLR_PACONFIG_PASELECT_RFO );
        SX1276LoRaSetPa20dBm( FALSE );
        LoRaSettings.Power = 14;
        SX1276LoRaSetRFPower( LoRaSettings.Power );
    } 
#endif
	
    SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );
}
Ejemplo n.º 3
0
void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
{
    //	tc45_disable(&TCD5);

    SX1276ReadBuffer( 0, buffer, size );
    //	tc45_enable(&TCD5);

}
Ejemplo n.º 4
0
/*****************************************************************************
 Prototype    : SX1276SetLoRaOn
 Description  : none
 Input        : bool enable  
 Output       : None
 Return Value : 
 Date         : 2014/3/15
 Author       : Barry
*****************************************************************************/
void SX1276SetLoRaOn( bool enable )
{
    /* if current state is the same of wanted state,return */
    if( LoRaOnState == enable )
    {
        return;
    }
    LoRaOnState = enable;
    LoRaOn = enable;

    if( LoRaOn == true )
    {
     #if defined(SX1276_LORA)
        SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );
        /* set to lora mode */
        SX1276LR->RegOpMode = ( SX1276LR->RegOpMode & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON;
        SX1276Write( REG_LR_OPMODE, SX1276LR->RegOpMode );
        
        SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );

        g_GDOx_map_conf.GDO0Config = DIO0_RxDone;
        g_GDOx_map_conf.GDO1Config = DIO1_RxTimeout;
        g_GDOx_map_conf.GDO2Config = DIO2_FhssCC;
        g_GDOx_map_conf.GDO3Config = DIO3_CadDone;
        g_GDOx_map_conf.GDO4Config = DIO4_CadDetected;
        g_GDOx_map_conf.GDO5Config = DIO5_ModeReady;
        config_GDOx_Map(g_GDOx_map_conf);
        
        SX1276ReadBuffer( REG_LR_OPMODE, SX1276Regs + 1, 0x70 - 1 );
#endif
    }
    else 
    {
   #if defined(SX1276_FSK)
        SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );
        
        SX1276LR->RegOpMode = ( SX1276LR->RegOpMode & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF;
        SX1276Write( REG_LR_OPMODE, SX1276LR->RegOpMode );
        
        SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );
        
        SX1276ReadBuffer( REG_OPMODE, SX1276Regs + 1, 0x70 - 1 );
   #endif
    }
}
Ejemplo n.º 5
0
void SX1276SetLoRaOn( bool enable )
{
    if( LoRaOnState == enable )
    {
        return;
    }
    LoRaOnState = enable;
    LoRaOn = enable;

    if( LoRaOn == true )
    {
        SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );
        
        SX1276LR->RegOpMode = ( SX1276LR->RegOpMode & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON;
        SX1276Write( REG_LR_OPMODE, SX1276LR->RegOpMode );
        
        SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );
                                        // RxDone               RxTimeout                   FhssChangeChannel           CadDone
        SX1276LR->RegDioMapping1 = RFLR_DIOMAPPING1_DIO0_00; //| RFLR_DIOMAPPING1_DIO1_00 | RFLR_DIOMAPPING1_DIO2_00 | RFLR_DIOMAPPING1_DIO3_00;
                                        // CadDetected          ModeReady
        SX1276LR->RegDioMapping2 = RFLR_DIOMAPPING2_DIO4_00 | RFLR_DIOMAPPING2_DIO5_00;
        SX1276WriteBuffer( REG_LR_DIOMAPPING1, &SX1276LR->RegDioMapping1, 2 );
        
        SX1276ReadBuffer( REG_LR_OPMODE, SX1276Regs + 1, 0x70 - 1 );
    }
    else
    {
        SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );
        
        SX1276LR->RegOpMode = ( SX1276LR->RegOpMode & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF;
        SX1276Write( REG_LR_OPMODE, SX1276LR->RegOpMode );
        
        SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );
        
        SX1276ReadBuffer( REG_OPMODE, SX1276Regs + 1, 0x70 - 1 );
    }
}
Ejemplo n.º 6
0
void SX1276_FSK_init(void)
{
    #if defined(SX1276_FSK)
    SX1276 = ( tSX1276* )SX1276Regs;

    SX1276Reset( );

    SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );

    SX1276LR->RegOpMode = ( SX1276LR->RegOpMode & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_OFF;
    SX1276Write( REG_LR_OPMODE, SX1276LR->RegOpMode );

    SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );

    SX1276ReadBuffer( REG_OPMODE, SX1276Regs + 1, 0x70 - 1 );
    #endif
}
Ejemplo n.º 7
0
void SX1276_lora_init(void)
{
    SX1276LR = ( tSX1276LR* )SX1276Regs;

    SX1276Reset( );

    SX1276LoRaSetOpMode( RFLR_OPMODE_SLEEP );
    /* set to lora mode */
    SX1276LR->RegOpMode = ( SX1276LR->RegOpMode & RFLR_OPMODE_LONGRANGEMODE_MASK ) | RFLR_OPMODE_LONGRANGEMODE_ON;
    SX1276Write( REG_LR_OPMODE, SX1276LR->RegOpMode );

    SX1276LoRaSetOpMode( RFLR_OPMODE_STANDBY );

    g_GDOx_map_conf.GDO0Config = DIO0_RxDone;
    g_GDOx_map_conf.GDO1Config = DIO1_RxTimeout;
    g_GDOx_map_conf.GDO2Config = DIO2_FhssCC;
    g_GDOx_map_conf.GDO3Config = DIO3_CadDone;
    g_GDOx_map_conf.GDO4Config = DIO4_CadDetected;
    g_GDOx_map_conf.GDO5Config = DIO5_ModeReady;
    config_GDOx_Map(g_GDOx_map_conf);

    SX1276ReadBuffer( REG_LR_OPMODE, SX1276Regs + 1, 0x70 - 1 );
}
Ejemplo n.º 8
0
int32_t SX1276FskReadAfc( void )
{
    SX1276ReadBuffer( REG_AFCMSB, &SX1276.RegAfcMsb, 2 );                            // Reads the AFC value
    return ( int32_t )( double )( ( ( uint16_t )SX1276.RegAfcMsb << 8 ) | ( uint16_t )SX1276.RegAfcLsb ) * ( double )FREQ_STEP;
}
Ejemplo n.º 9
0
int32_t SX1276FskReadFei( void )
{
    SX1276ReadBuffer( REG_FEIMSB, &SX1276.RegFeiMsb, 2 );                          // Reads the FEI value

    return ( int32_t )( double )( ( ( uint16_t )SX1276.RegFeiMsb << 8 ) | ( uint16_t )SX1276.RegFeiLsb ) * ( double )FREQ_STEP;
}
Ejemplo n.º 10
0
void SX1276FskInit( void )
{
    SX1276FskSetOpMode( RF_OPMODE_STANDBY );
   
    SX1276FskSetDefaults( );
    
    SX1276ReadBuffer( REG_OPMODE, SX1276Regs + 1, 0x70 - 1 );

    // Set the device in FSK mode and Sleep Mode
    SX1276.RegOpMode = RF_OPMODE_MODULATIONTYPE_FSK | RF_OPMODE_SLEEP;
    SX1276Write( REG_OPMODE, SX1276.RegOpMode );

    SX1276.RegPaRamp = RF_PARAMP_MODULATIONSHAPING_01;
    SX1276Write( REG_PARAMP, SX1276.RegPaRamp );

    SX1276.RegLna = RF_LNA_GAIN_G1;
    SX1276Write( REG_LNA, SX1276.RegLna );

    if( FskSettings.AfcOn == true )
    {
        SX1276.RegRxConfig = RF_RXCONFIG_RESTARTRXONCOLLISION_OFF | RF_RXCONFIG_AFCAUTO_ON |
                              RF_RXCONFIG_AGCAUTO_ON | RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT;
    }
    else
    {
        SX1276.RegRxConfig = RF_RXCONFIG_RESTARTRXONCOLLISION_OFF | RF_RXCONFIG_AFCAUTO_OFF |
                              RF_RXCONFIG_AGCAUTO_ON | RF_RXCONFIG_RXTRIGER_PREAMBLEDETECT;
    }

    SX1276.RegPreambleLsb = 8;
    
    SX1276.RegPreambleDetect = RF_PREAMBLEDETECT_DETECTOR_ON | RF_PREAMBLEDETECT_DETECTORSIZE_2 |
                                RF_PREAMBLEDETECT_DETECTORTOL_10;

    SX1276.RegRssiThresh = 0xFF;

    SX1276.RegSyncConfig = RF_SYNCCONFIG_AUTORESTARTRXMODE_WAITPLL_ON | RF_SYNCCONFIG_PREAMBLEPOLARITY_AA |
                            RF_SYNCCONFIG_SYNC_ON |
                            RF_SYNCCONFIG_SYNCSIZE_4;

    SX1276.RegSyncValue1 = 0x69;
    SX1276.RegSyncValue2 = 0x81;
    SX1276.RegSyncValue3 = 0x7E;
    SX1276.RegSyncValue4 = 0x96;

    SX1276.RegPacketConfig1 = RF_PACKETCONFIG1_PACKETFORMAT_VARIABLE | RF_PACKETCONFIG1_DCFREE_OFF |
                               ( FskSettings.CrcOn << 4 ) | RF_PACKETCONFIG1_CRCAUTOCLEAR_ON |
                               RF_PACKETCONFIG1_ADDRSFILTERING_OFF | RF_PACKETCONFIG1_CRCWHITENINGTYPE_CCITT;
    SX1276FskGetPacketCrcOn(&SX1276); // Update CrcOn on FskSettings

    SX1276.RegPayloadLength = FskSettings.PayloadLength;

    // we can now update the registers with our configuration
    SX1276WriteBuffer( REG_OPMODE, SX1276Regs + 1, 0x70 - 1 );

    // then we need to set the RF settings 
    SX1276FskSetRFFrequency( FskSettings.RFFrequency,&SX1276);
    SX1276FskSetBitrate( FskSettings.Bitrate,&SX1276 );
    SX1276FskSetFdev( FskSettings.Fdev,&SX1276 );

    SX1276FskSetDccBw( &SX1276.RegRxBw, 0, FskSettings.RxBw,&SX1276 );
    SX1276FskSetDccBw( &SX1276.RegAfcBw, 0, FskSettings.RxBwAfc,&SX1276 );
    SX1276FskSetRssiOffset( 0 ,&SX1276);


    if( FskSettings.RFFrequency > 860000000 )
    {
        SX1276FskSetPAOutput( RF_PACONFIG_PASELECT_RFO,&SX1276 );
        SX1276FskSetPa20dBm( false ,&SX1276);
        FskSettings.Power = 14;
        SX1276FskSetRFPower( FskSettings.Power ,&SX1276);
    }

    SX1276FskSetOpMode( RF_OPMODE_STANDBY );

    // Calibrate the HF
    SX1276FskRxCalibrate(&SX1276 );
}
Ejemplo n.º 11
0
void SX1276Read( uint8_t addr, uint8_t *data )
{
	SX1276ReadBuffer( addr, data, 1 );
}
Ejemplo n.º 12
0
void SX1276ReadFifo( uint8_t *buffer, uint8_t size )
{
	SX1276ReadBuffer( 0, buffer, size );
}