SX1276 Tx Continuous Wave Demo Application
SX1276 Tx Continuous Wave Demo Application
This application is used for test purposes by outputting a continuous wave, at maximum power, at a given frequency.
main.cpp@8:8a6702a74031, 2017-04-24 (annotated)
- Committer:
- mluis
- Date:
- Mon Apr 24 13:24:19 2017 +0000
- Revision:
- 8:8a6702a74031
- Parent:
- 6:86aff5a7af07
WARNING: Radio API timings changed from micro-seconds to milliseconds; ; Updated SX1276Lib and mbed libraries to the latest versions
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
GregCr | 0:d5e61ad8edd9 | 1 | /* |
GregCr | 0:d5e61ad8edd9 | 2 | / _____) _ | | |
GregCr | 0:d5e61ad8edd9 | 3 | ( (____ _____ ____ _| |_ _____ ____| |__ |
GregCr | 0:d5e61ad8edd9 | 4 | \____ \| ___ | (_ _) ___ |/ ___) _ \ |
GregCr | 0:d5e61ad8edd9 | 5 | _____) ) ____| | | || |_| ____( (___| | | | |
GregCr | 0:d5e61ad8edd9 | 6 | (______/|_____)_|_|_| \__)_____)\____)_| |_| |
GregCr | 0:d5e61ad8edd9 | 7 | ( C )2014 Semtech |
GregCr | 0:d5e61ad8edd9 | 8 | |
GregCr | 0:d5e61ad8edd9 | 9 | Description: Tx Continuous Wave implementation |
GregCr | 0:d5e61ad8edd9 | 10 | |
GregCr | 0:d5e61ad8edd9 | 11 | License: Revised BSD License, see LICENSE.TXT file include in the project |
GregCr | 0:d5e61ad8edd9 | 12 | |
GregCr | 0:d5e61ad8edd9 | 13 | Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin |
GregCr | 0:d5e61ad8edd9 | 14 | */ |
GregCr | 0:d5e61ad8edd9 | 15 | #include "mbed.h" |
GregCr | 0:d5e61ad8edd9 | 16 | #include "sx1276-hal.h" |
GregCr | 4:e143703ffc4e | 17 | #include "debug.h" |
GregCr | 0:d5e61ad8edd9 | 18 | |
GregCr | 2:c6e6da9fc5e1 | 19 | /* Set this flag to '1' to test the HF max output power or '0' to the the LF max output power */ |
GregCr | 0:d5e61ad8edd9 | 20 | #define TEST_HF_OUTPUT 1 |
GregCr | 0:d5e61ad8edd9 | 21 | #define TEST_LF_OUTPUT = !TEST_HF_OUTPUT |
GregCr | 0:d5e61ad8edd9 | 22 | |
GregCr | 0:d5e61ad8edd9 | 23 | #define LORA_BANDWIDTH 0 // [0: 125 kHz, |
GregCr | 0:d5e61ad8edd9 | 24 | // 1: 250 kHz, |
GregCr | 0:d5e61ad8edd9 | 25 | // 2: 500 kHz, |
GregCr | 0:d5e61ad8edd9 | 26 | // 3: Reserved] |
GregCr | 0:d5e61ad8edd9 | 27 | #define LORA_SPREADING_FACTOR 9 // [SF7..SF12] |
GregCr | 0:d5e61ad8edd9 | 28 | #define LORA_CODINGRATE 1 // [1: 4/5, |
GregCr | 0:d5e61ad8edd9 | 29 | // 2: 4/6, |
GregCr | 0:d5e61ad8edd9 | 30 | // 3: 4/7, |
GregCr | 0:d5e61ad8edd9 | 31 | // 4: 4/8] |
GregCr | 0:d5e61ad8edd9 | 32 | #define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx |
GregCr | 2:c6e6da9fc5e1 | 33 | #define LORA_SYMBOL_TIMEOUT 5 // Symbols |
GregCr | 0:d5e61ad8edd9 | 34 | #define LORA_FIX_LENGTH_PAYLOAD_ON false |
GregCr | 2:c6e6da9fc5e1 | 35 | #define LORA_FHSS_ENABLED false |
mluis | 8:8a6702a74031 | 36 | #define LORA_NB_SYMB_HOP 4 // Symbols |
GregCr | 0:d5e61ad8edd9 | 37 | #define LORA_IQ_INVERSION_ON false |
GregCr | 2:c6e6da9fc5e1 | 38 | #define LORA_CRC_ENABLED true |
GregCr | 0:d5e61ad8edd9 | 39 | |
mluis | 8:8a6702a74031 | 40 | /*! |
mluis | 8:8a6702a74031 | 41 | * Radio events function pointer |
mluis | 8:8a6702a74031 | 42 | */ |
mluis | 8:8a6702a74031 | 43 | static RadioEvents_t RadioEvents; |
GregCr | 0:d5e61ad8edd9 | 44 | |
mluis | 8:8a6702a74031 | 45 | /*! |
mluis | 8:8a6702a74031 | 46 | * Tx continuous wave parameters |
mluis | 8:8a6702a74031 | 47 | */ |
mluis | 8:8a6702a74031 | 48 | struct |
mluis | 8:8a6702a74031 | 49 | { |
mluis | 8:8a6702a74031 | 50 | uint32_t RfFrequency; |
mluis | 8:8a6702a74031 | 51 | uint32_t TxOutputPower; |
mluis | 8:8a6702a74031 | 52 | }TxCwParams; |
mluis | 8:8a6702a74031 | 53 | |
mluis | 8:8a6702a74031 | 54 | /*! |
mluis | 8:8a6702a74031 | 55 | * Radio object |
mluis | 8:8a6702a74031 | 56 | */ |
mluis | 5:2021b1237e6d | 57 | SX1276MB1xAS Radio( NULL ); |
GregCr | 0:d5e61ad8edd9 | 58 | |
mluis | 8:8a6702a74031 | 59 | /*! |
mluis | 8:8a6702a74031 | 60 | * \brief Function executed on Radio Tx Timeout event |
mluis | 8:8a6702a74031 | 61 | */ |
mluis | 8:8a6702a74031 | 62 | void OnRadioTxTimeout( void ) |
mluis | 8:8a6702a74031 | 63 | { |
mluis | 8:8a6702a74031 | 64 | // Restarts continuous wave transmission when timeout expires after 65535 seconds |
mluis | 8:8a6702a74031 | 65 | Radio.SetTxContinuousWave( TxCwParams.RfFrequency, TxCwParams.TxOutputPower, 65535 ); |
mluis | 8:8a6702a74031 | 66 | } |
mluis | 8:8a6702a74031 | 67 | |
GregCr | 0:d5e61ad8edd9 | 68 | /** |
GregCr | 0:d5e61ad8edd9 | 69 | * Main application entry point. |
GregCr | 0:d5e61ad8edd9 | 70 | */ |
GregCr | 0:d5e61ad8edd9 | 71 | int main( void ) |
GregCr | 0:d5e61ad8edd9 | 72 | { |
mluis | 8:8a6702a74031 | 73 | debug( "\n\r\n\r SX1276 Continuous Wave at full power Demo Application \n\r" ); |
GregCr | 1:edbca7c3fbad | 74 | |
GregCr | 1:edbca7c3fbad | 75 | #if defined TARGET_NUCLEO_L152RE |
mluis | 8:8a6702a74031 | 76 | debug( " > Nucleo-L152RE Platform <\r\n" ); |
GregCr | 1:edbca7c3fbad | 77 | #elif defined TARGET_KL25Z |
mluis | 8:8a6702a74031 | 78 | debug( " > KL25Z Platform <\r\n" ); |
GregCr | 1:edbca7c3fbad | 79 | #elif defined TARGET_LPC11U6X |
mluis | 8:8a6702a74031 | 80 | debug( " > LPC11U6X Platform <\r\n" ); |
GregCr | 1:edbca7c3fbad | 81 | #else |
mluis | 8:8a6702a74031 | 82 | debug( " > Untested Platform <\r\n" ); |
GregCr | 1:edbca7c3fbad | 83 | #endif |
GregCr | 1:edbca7c3fbad | 84 | |
GregCr | 2:c6e6da9fc5e1 | 85 | #if( TEST_HF_OUTPUT == 1 ) |
GregCr | 0:d5e61ad8edd9 | 86 | |
GregCr | 0:d5e61ad8edd9 | 87 | if( Radio.DetectBoardType( ) == SX1276MB1LAS ) // |
GregCr | 0:d5e61ad8edd9 | 88 | { |
GregCr | 1:edbca7c3fbad | 89 | debug("\r\n TEST_HF_OUTPUT on SX1276MB1LAS: 20 dBm at 915 MHz \r\n" ); |
mluis | 8:8a6702a74031 | 90 | |
mluis | 8:8a6702a74031 | 91 | TxCwParams.RfFrequency = 915e6; |
mluis | 8:8a6702a74031 | 92 | TxCwParams.TxOutputPower = 20; |
GregCr | 1:edbca7c3fbad | 93 | } |
GregCr | 1:edbca7c3fbad | 94 | else |
GregCr | 1:edbca7c3fbad | 95 | { // SX1276MB1MAS |
GregCr | 1:edbca7c3fbad | 96 | debug("\r\n TEST_HF_OUTPUT on SX1276MB1MAS: 14 dBm at 868 MHz \r\n" ); |
mluis | 8:8a6702a74031 | 97 | |
mluis | 8:8a6702a74031 | 98 | TxCwParams.RfFrequency = 868e6; |
mluis | 8:8a6702a74031 | 99 | TxCwParams.TxOutputPower = 14; |
GregCr | 0:d5e61ad8edd9 | 100 | } |
GregCr | 0:d5e61ad8edd9 | 101 | |
GregCr | 2:c6e6da9fc5e1 | 102 | #else //if( TEST_LF_OUTPUT == 1 ) |
GregCr | 0:d5e61ad8edd9 | 103 | |
GregCr | 1:edbca7c3fbad | 104 | debug("\r\n TEST_LF_OUTPUT on SX1276MB1xAS: 14 dBm at 434 MHz \r\n" ); |
mluis | 8:8a6702a74031 | 105 | TxCwParams.RfFrequency = 433e6; |
mluis | 8:8a6702a74031 | 106 | TxCwParams.TxOutputPower = 14; |
GregCr | 0:d5e61ad8edd9 | 107 | |
GregCr | 0:d5e61ad8edd9 | 108 | #endif |
GregCr | 0:d5e61ad8edd9 | 109 | |
mluis | 8:8a6702a74031 | 110 | // Radio initialization |
mluis | 8:8a6702a74031 | 111 | RadioEvents.TxTimeout = OnRadioTxTimeout; |
mluis | 8:8a6702a74031 | 112 | Radio.Init( &RadioEvents ); |
mluis | 8:8a6702a74031 | 113 | |
mluis | 8:8a6702a74031 | 114 | // Start continuous wave transmission fucntion expires after 65535 seconds |
mluis | 8:8a6702a74031 | 115 | Radio.SetTxContinuousWave( TxCwParams.RfFrequency, TxCwParams.TxOutputPower, 65535 ); |
GregCr | 0:d5e61ad8edd9 | 116 | |
GregCr | 0:d5e61ad8edd9 | 117 | debug( "Start main loop: \r\n" ); |
GregCr | 0:d5e61ad8edd9 | 118 | // Blink LEDs just to show some activity |
GregCr | 0:d5e61ad8edd9 | 119 | while( 1 ) |
GregCr | 0:d5e61ad8edd9 | 120 | { |
GregCr | 2:c6e6da9fc5e1 | 121 | debug( "Continuous Wave activated... \r\n" ); |
GregCr | 2:c6e6da9fc5e1 | 122 | wait_ms( 200 ); |
GregCr | 0:d5e61ad8edd9 | 123 | } |
GregCr | 0:d5e61ad8edd9 | 124 | } |