Simple SX1272 Test Application

Dependencies:   SX1272Lib mbed

Files at this revision

API Documentation at this revision

Comitter:
mick_ccc
Date:
Thu May 11 14:59:23 2017 +0000
Parent:
4:fac0fc95a644
Commit message:
Defined LoRaWAN EU channels

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Apr 28 15:24:27 2017 +0000
+++ b/main.cpp	Thu May 11 14:59:23 2017 +0000
@@ -5,20 +5,21 @@
 #include "main.h"
 
 #define TX_LOOP 1
-#define TX_FREQ 867100000
 #define PAYLOAD_SIZE_LONG 112 //97
 #define PAYLOAD_SIZE_SHORT 12
 
-#define CHANNEL_0_FREQ_HZ 867100000
-#define CHANNEL_1_FREQ_HZ 867300000
-#define CHANNEL_2_FREQ_HZ 867500000
-#define CHANNEL_3_FREQ_HZ 867700000
-#define CHANNEL_4_FREQ_HZ 867900000
-#define CHANNEL_5_FREQ_HZ 868100000
-#define CHANNEL_6_FREQ_HZ 868300000
-#define CHANNEL_7_FREQ_HZ 868500000
-#define CHANNEL_8_FREQ_HZ 868300000
-#define CHANNEL_9_FREQ_HZ 868800000
+uint32_t Channels[10] = {
+    867100000,
+    867300000,
+    867500000,
+    867700000,
+    867900000,
+    868100000,
+    868300000,
+    868500000,
+    868300000,
+    868800000
+};
 
 typedef enum Modulation
 {
@@ -93,11 +94,11 @@
     switch( modulation )
     {
         case MODEM_LORA:
-            Radio.SetTxConfig( MODEM_LORA, 2, 0, bw, CurrentDatarate, 1, 8, false, true, 0, 0, false, 10e3 );
+            Radio.SetTxConfig( MODEM_LORA, 0, 0, bw, CurrentDatarate, 1, 8, false, true, 0, 0, false, 10e3 );
             TimeOnAir = Radio.TimeOnAir( MODEM_LORA, pkt_size );
             break;
         case MODEM_FSK:
-            Radio.SetTxConfig( MODEM_FSK, 2, 25e3, 0, 50e3, 0, 5, false, true, 0, 0, false, 3e3 );
+            Radio.SetTxConfig( MODEM_FSK, 0, 25e3, 0, 50e3, 0, 5, false, true, 0, 0, false, 3e3 );
             TimeOnAir = Radio.TimeOnAir( MODEM_FSK, pkt_size );
             break;
         default:
@@ -157,7 +158,25 @@
             LoRaWANBuffer[7] = 0; // FCnt, filled later
             LoRaWANBuffer[8] = 1; // FPort
             LoRaWANBuffer[9] = 0x0; // FRMPayload
-            
+
+#if 1
+            FCnt = 0;
+            while( 1 )
+            {
+                LoRaWANBuffer[6] = FCnt;
+                LoRaWANBuffer[7] = FCnt >> 8;
+             
+                // Send LoRa packet
+                PktToA = SendPacket( Channels[FCnt % 8], MODEM_LORA, LORA_BW_125K, PAYLOAD_SIZE_SHORT );
+                //pc.printf( "(%d) Sending LoRa packet: Freq=%u, SF%u (%.1lfms), FCnt=%u...\n", i, TxFreq, CurrentDatarate, PktToA, FCnt );
+                wait_ms( PktToA );
+                Radio.Sleep( );
+                
+                FCnt += 1;   
+            }
+#endif
+
+#if 0            
             FCnt = 0;
             for( i = 0; i < (int)TX_LOOP; i++ )
             {
@@ -165,37 +184,34 @@
                 LoRaWANBuffer[7] = FCnt >> 8;
                 
                 // Send LoRa packet
-                PktToA = SendPacket( CHANNEL_0_FREQ_HZ, MODEM_LORA, LORA_BW_125K, PAYLOAD_SIZE_LONG );
+                PktToA = SendPacket( Channels[0], MODEM_LORA, LORA_BW_125K, PAYLOAD_SIZE_LONG );
                 //pc.printf( "(%d) Sending LoRa packet: Freq=%u, SF%u (%.1lfms), FCnt=%u...\n", i, TxFreq, CurrentDatarate, PktToA, FCnt );
                 wait_ms( PktToA );
                 Radio.Sleep( );
                 
-#if 1
                 FCnt += 1;
                 LoRaWANBuffer[6] = FCnt;
                 LoRaWANBuffer[7] = FCnt >> 8;
                 
                 // Send FSK packet
-                PktToA = SendPacket( CHANNEL_9_FREQ_HZ, MODEM_FSK, LORA_BW_NA, PAYLOAD_SIZE_SHORT );
+                PktToA = SendPacket( Channels[0], MODEM_FSK, LORA_BW_NA, PAYLOAD_SIZE_SHORT );
                 //pc.printf( "(%d) Sending FSK packet: Freq=%u, FCnt=%u...\n", i, TxFreq, PktToA, FCnt );
                 wait_ms( PktToA );
                 Radio.Sleep( );
-#endif
-                
-#if 1
+
                 FCnt += 1;
                 LoRaWANBuffer[6] = FCnt;
                 LoRaWANBuffer[7] = FCnt >> 8;
                 
                 // Send LoRa packet
-                PktToA = SendPacket( CHANNEL_8_FREQ_HZ, MODEM_LORA, LORA_BW_250K, PAYLOAD_SIZE_SHORT );
+                PktToA = SendPacket( Channels[8], MODEM_LORA, LORA_BW_500K, PAYLOAD_SIZE_SHORT );
                 //pc.printf( "(%d) Sending LoRa packet: Freq=%u, SF%u (%.1lfms), FCnt=%u...\n", i, TxFreq, CurrentDatarate, PktToA, FCnt );
                 wait_ms( PktToA );
                 Radio.Sleep( );
-#endif
                 
                 FCnt += 1;
             }
+#endif
 
             // Stop sending
             ButtonPressed = false;