SX1276 Tx Continuous Wave Demo Application

Dependencies:   SX1276Lib mbed

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.

Revision:
0:d5e61ad8edd9
Child:
1:edbca7c3fbad
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Aug 19 08:50:29 2014 +0000
@@ -0,0 +1,192 @@
+/*
+ / _____)             _              | |
+( (____  _____ ____ _| |_ _____  ____| |__
+ \____ \| ___ |    (_   _) ___ |/ ___)  _ \
+ _____) ) ____| | | || |_| ____( (___| | | |
+(______/|_____)_|_|_| \__)_____)\____)_| |_|
+    ( C )2014 Semtech
+
+Description: Tx Continuous Wave implementation
+
+License: Revised BSD License, see LICENSE.TXT file include in the project
+
+Maintainers: Miguel Luis, Gregory Cristian and Nicolas Huguenin
+*/
+#include "mbed.h"
+#include "sx1276-hal.h"
+
+#define TEST_HF_OUTPUT                              1
+#define TEST_LF_OUTPUT = !TEST_HF_OUTPUT
+
+#define LORA_BANDWIDTH                              0         // [0: 125 kHz,
+                                                              //  1: 250 kHz,
+                                                              //  2: 500 kHz,
+                                                              //  3: Reserved]
+#define LORA_SPREADING_FACTOR                       9         // [SF7..SF12]
+#define LORA_CODINGRATE                             1         // [1: 4/5,
+                                                              //  2: 4/6,
+                                                              //  3: 4/7,
+                                                              //  4: 4/8]
+#define LORA_PREAMBLE_LENGTH                        8         // Same for Tx and Rx
+#define LORA_FIX_LENGTH_PAYLOAD_ON                  false
+#define LORA_IQ_INVERSION_ON                        false
+
+SX1276MB1xAS Radio( NULL, NULL, NULL, NULL, NULL );
+
+#if USE_LEDS
+    DigitalOut Led1( LED1 );
+    DigitalOut Led2( LED2 );
+    DigitalOut Led3( LED3 );
+#else
+    bool Led1 = 0;
+    bool Led2 = 0;
+    bool Led3 = 0;
+#endif
+
+static Timeout LedTimer;
+volatile bool Led1TimerEvent = false;
+volatile bool Led2TimerEvent = false;
+volatile bool Led3TimerEvent = false;
+
+/*!
+ * \brief Function executed on Led 1 Timeout event
+ */
+void OnLed1TimerEvent( void )
+{
+    Led1TimerEvent = true;
+}
+
+/*!
+ * \brief Function executed on Led 2 Timeout event
+ */
+void OnLed2TimerEvent( void )
+{
+    Led2TimerEvent = true;
+}
+
+/*!
+ * \brief Function executed on Led 3 Timeout event
+ */
+void OnLed3TimerEvent( void )
+{
+    Led3TimerEvent = true;
+}
+
+void PrintLeds( )
+{
+    #if !USE_LEDS
+        char charLed1 = ( Led1 == true ) ? '0' : 'x';
+        char charLed2 = ( Led2 == true ) ? '0' : 'x';
+        char charLed3 = ( Led3 == true ) ? '0' : 'x';
+        debug( "%c%c%c\r\n", charLed1, charLed2, charLed3 );
+    #endif
+}
+
+/**
+ * Main application entry point.
+ */
+int main( void )
+{
+    uint8_t TxOuputPower = 0;
+
+    /**********************************************/
+    /*                  WARNING                   */
+    /* The below settings can damage the chipset  */
+    /* if wrongly used. DO NOT CHANGE THE VALUES! */
+    /*                                            */
+    /**********************************************/
+    
+#if TEST_HF_OUTPUT == 1
+
+    if( Radio.DetectBoardType( ) == SX1276MB1LAS ) // 
+    {
+        Radio.SetChannel( 915000000 );
+        TxOuputPower = 14;
+        Radio.Write( 0x01, 0x88 );
+        Radio.Write( 0x3D, 0xA1 );
+        Radio.Write( 0x36, 0x01 );
+        Radio.Write( 0x1e, 0x08 );
+    }
+    else
+    {   // SX1276MB1MAS
+        Radio.SetChannel( 868000000 );
+        TxOuputPower = 20;
+        Radio.Write( 0x01, 0x80 );
+        Radio.Write( 0x44, 0x7B );
+        Radio.Write( 0x3D, 0xA1 );
+        Radio.Write( 0x36, 0x01 );
+        Radio.Write( 0x1e, 0x08 );
+        Radio.Write( 0x45, 0xDF );
+        Radio.Write( 0x46, 0x03 );
+        Radio.Write( 0x4D, 0x87 );
+        Radio.Write( 0x52, 0x60 );
+    }
+    
+#elif TEST_LF_OUTPUT == 1
+
+    Radio.SetChannel( 433000000 );
+    TxOuputPower = 14;
+    Radio.Write( 0x01, 0x88 );
+    Radio.Write( 0x3D, 0xA1 );
+    Radio.Write( 0x36, 0x01 );
+    Radio.Write( 0x1e, 0x08 );
+
+#endif
+
+    Radio.SetTxConfig( MODEM_LORA, TxOuputPower, 0, LORA_BANDWIDTH,
+                                   LORA_SPREADING_FACTOR, LORA_CODINGRATE,
+                                   LORA_PREAMBLE_LENGTH, LORA_FIX_LENGTH_PAYLOAD_ON,
+                                   true, LORA_IQ_INVERSION_ON, 3000000 );
+
+    // Switch LED 1 ON
+    Led1 = 1;
+    LedTimer.attach_us( OnLed1TimerEvent, 90000 );
+    
+    // Sets the radio in Tx mode
+    Radio.Send( NULL, 0 );
+
+    debug( "Start main loop: \r\n" );
+    // Blink LEDs just to show some activity
+    while( 1 )
+    {
+        if( Led1TimerEvent == true )
+        {
+            Led1TimerEvent = false;
+            
+            // Switch LED 1 OFF
+            Led1 = 0;
+            // Switch LED 2 ON
+            Led2 = 1;
+            
+            LedTimer.attach_us( OnLed2TimerEvent, 90000 );
+            PrintLeds( );
+        }
+
+        if( Led2TimerEvent == true )
+        {
+            Led2TimerEvent = false;
+            
+            // Switch LED 2 OFF
+            Led2 = 0;
+            // Switch LED 3 ON
+            Led3 = 1;
+            
+            LedTimer.attach_us( OnLed3TimerEvent, 90000 );
+            PrintLeds( );
+        }
+    
+        if( Led3TimerEvent == true )
+        {
+            Led3TimerEvent = false;
+            
+            // Switch LED 3 OFF
+            Led3 = 0;
+            // Switch LED 1 ON
+            Led1 = 1;
+            
+            LedTimer.attach_us( OnLed1TimerEvent, 90000 );
+            PrintLeds( );
+        }    
+    }
+}
+