SX126xDevKit
Dependencies: mbed DmTftLibrary SX126xLib
Diff: Demo/DemoApplication.cpp
- Revision:
- 1:b96176a4ccb8
- Parent:
- 0:e5420f1a8a1a
- Child:
- 2:8e1b4210df6b
diff -r e5420f1a8a1a -r b96176a4ccb8 Demo/DemoApplication.cpp --- a/Demo/DemoApplication.cpp Tue Sep 05 08:15:37 2017 +0000 +++ b/Demo/DemoApplication.cpp Fri Mar 09 13:28:34 2018 +0000 @@ -98,8 +98,8 @@ }; // SPI -// mosi, miso, sclk, nss, dio0, dio1, dio2, dio3, rst, deviceSel, antSwPower, callbacks... -SX126xHal Radio( D11, D12, D13, D7, D3, D5, NC, NC, A0, A2, D8, &RadioEvents ); +// mosi, miso, sclk, nss, dio0, dio1, dio2, dio3, rst, freqSel, deviceSel, antSwPower, callbacks... +SX126xHal Radio( D11, D12, D13, D7, D3, D5, NC, NC, A0, A1, A2, D8, &RadioEvents ); /*! * \brief Tx LED toggling on transmition success @@ -162,6 +162,61 @@ // * * // * * // ***************************************************************************** +uint8_t RunDemoTestRssi( void ) +{ + uint8_t refreshDisplay = 0; + static uint16_t i; + + if( Eeprom.EepromData.DemoSettings.HoldDemo == true ) + { + return 0; + } + + if( DemoRunning == false ) + { + DemoRunning = true; + + printf( "Start RunDemoTestRssi\n\r" ); + + TX_LED = 0; + RX_LED = 0; + + Eeprom.EepromData.DemoSettings.CntPacketTx = 0; + Eeprom.EepromData.DemoSettings.CntPacketRxOK = 0; + Eeprom.EepromData.DemoSettings.CntPacketRxKO = 0; + + InitializeDemoParameters( Eeprom.EepromData.DemoSettings.ModulationType ); + + IrqMask = IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; + Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE ); + // Rx Continuous + if( Eeprom.EepromData.DemoSettings.BoostedRx == false ) + { + Radio.SetRx( 0xFFFFFF ); + } + else + { + Radio.SetRxBoosted( 0xFFFFFF ); + } + DemoInternalState = APP_IDLE; + i = 0; + } + + Radio.ProcessIrqs( ); + + if( i < 5000 ) + { + i++; + } + else + { + i = 0; + Eeprom.EepromData.DemoSettings.RssiValue = Radio.GetRssiInst( ); + refreshDisplay = 1; + } + + return refreshDisplay; +} uint8_t RunDemoSleepMode( void ) { @@ -254,7 +309,7 @@ Radio.SetStandby( STDBY_RC ); Radio.SetRegulatorMode( ( RadioRegulatorMode_t )Eeprom.EepromData.DemoSettings.RadioPowerMode ); Radio.SetRfFrequency( Eeprom.EepromData.DemoSettings.Frequency ); - Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_40_US ); + Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_200_US ); Radio.SetTxContinuousWave( ); DemoRunning = true; } @@ -439,7 +494,7 @@ case APP_RX_ERROR: case APP_RX_TIMEOUT: Eeprom.EepromData.DemoSettings.CntPacketRxKO ++; - DemoInternalState = PER_RX_START; + DemoInternalState = APP_IDLE; refreshDisplay = 1; break; @@ -495,7 +550,7 @@ } else { - IrqMask = /*0xFFFF; IRQ_HEADER_VALID |*/ IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; + IrqMask = /*0xFFFF; */IRQ_HEADER_VALID | IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE ); // Rx Single without timeout for the start if( Eeprom.EepromData.DemoSettings.BoostedRx == false ) @@ -554,7 +609,7 @@ break; case PER_RX_START: - IrqMask = /*0xFFFF;*/ IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; + IrqMask = /*0xFFFF;*/ IRQ_HEADER_VALID | IRQ_RX_DONE | IRQ_CRC_ERROR | IRQ_RX_TX_TIMEOUT; Radio.SetDioIrqParams( IrqMask, IrqMask, IRQ_RADIO_NONE, IRQ_RADIO_NONE ); if( Eeprom.EepromData.DemoSettings.BoostedRx == false ) { @@ -729,7 +784,7 @@ { DemoInternalState = SEND_PING_MSG; uint32_t temp = ( Eeprom.EepromData.DemoSettings.InterPacketDelay << 1 ) + RX_TIMEOUT_MARGIN; - float val = ( float )temp / ( float )( 1000.0 ); + float val = ( float )temp / 1000.0; SendNextPacket.attach( &SendNextPacketEvent, val ); } else @@ -1078,6 +1133,11 @@ return( Radio.GetDeviceType( ) ); } +uint8_t GetMatchingFrequency( void ) +{ + return( Radio.GetFreqSelect( ) ); +} + void InitDemoApplication( void ) { RX_LED = 1; @@ -1303,6 +1363,14 @@ PacketParams.Params.LoRa.InvertIQ = ( RadioLoRaIQModes_t ) Eeprom.EepromData.DemoSettings.PacketParam5; Eeprom.EepromData.DemoSettings.PayloadLength = PacketParams.Params.LoRa.PayloadLength; + + if( ( ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF6 ) || ( ModulationParams.Params.LoRa.SpreadingFactor == LORA_SF5 ) ) + { + if( PacketParams.Params.LoRa.PreambleLength < 12 ) + { + PacketParams.Params.LoRa.PreambleLength = 12; + } + } } else// if( modulation == PACKET_TYPE_GFSK ) { @@ -1337,7 +1405,7 @@ Radio.SetBufferBaseAddresses( 0x00, 0x00 ); - Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_40_US ); + Radio.SetTxParams( Eeprom.EepromData.DemoSettings.TxPower, RADIO_RAMP_200_US ); // only used in GFSK Radio.SetSyncWord( ( uint8_t[] ){ 0x12, 0x34, 0x56, 0x78, 0x9A, 0xBC, 0xDE, 0xF0 } );