SX1276 library for modtronix inair9. Edited for use with NRF51DK board.

Dependents:   InAir9_PingPong

Fork of SX1276Lib_modtronix by modtronix H

Revision:
20:7cf7c08f0088
Parent:
19:ef26bd64cb67
Child:
22:20db480143c9
--- a/sx1276/sx1276.cpp	Wed Mar 04 04:57:57 2015 +0000
+++ b/sx1276/sx1276.cpp	Thu Apr 02 01:02:35 2015 +0000
@@ -37,7 +37,7 @@
     { 166700, 0x11 },
     { 200000, 0x09 },
     { 250000, 0x01 },
-    {      0, 0x00 }, // Invalid Badwidth
+    { 300000, 0x00 }, // Invalid Badwidth
 };
 
 
@@ -282,9 +282,19 @@
                 datarate = 6;
             }
         
-            //bandwidth 7=125, 8=250, 9=500, datarate=SF
-            if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
-                ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
+            //bandwidth 6=62.5, 7=125, 8=250, 9=500, datarate=SF. LowDatarateOptimize is mandatory when symbol length > 16ms
+            //LowDatarateOptimize = 0 when (BW=500) or (BW=250 and SF=12),  else it is ON (Tsym > 16ms)
+            if( ( ( bandwidth == 8 ) && ( datarate == 12 ) ) ||
+                ( ( bandwidth == 7 ) && ( datarate > 10 ) )  ||
+                ( ( bandwidth == 6 ) && ( datarate > 9 ) )   ||
+                ( ( bandwidth == 5 ) && ( datarate > 9 ) )   ||
+                ( ( bandwidth == 4 ) && ( datarate > 8 ) )   ||  ( bandwidth < 4 )
+                //The below is actually correct method, but assume BW = 20.8 and lower will always have SF > 8
+//                ( ( bandwidth == 3 ) && ( datarate > 8 ) )   ||
+//                ( ( bandwidth == 2 ) && ( datarate > 7 ) )   ||
+//                ( ( bandwidth == 1 ) && ( datarate > 7 ) )   ||
+//                ( ( bandwidth == 0 ) && ( datarate > 6 ) )
+                )
             {
                 this->settings.LoRa.LowDatarateOptimize = 0x01;
             }
@@ -481,9 +491,19 @@
             {
                 datarate = 6;
             }
-            //bandwidth 7=125, 8=250, 9=500, datarate=SF
-            if( ( ( bandwidth == 7 ) && ( ( datarate == 11 ) || ( datarate == 12 ) ) ) ||
-                ( ( bandwidth == 8 ) && ( datarate == 12 ) ) )
+            //bandwidth 6=62.5, 7=125, 8=250, 9=500, datarate=SF. LowDatarateOptimize is mandatory when symbol length > 16ms
+            //LowDatarateOptimize = 0 when (BW=500) or (BW=250 and SF=12),  else it is ON (Tsym > 16ms)
+            if( ( ( bandwidth == 8 ) && ( datarate == 12 ) ) ||
+                ( ( bandwidth == 7 ) && ( datarate > 10 ) )  ||
+                ( ( bandwidth == 6 ) && ( datarate > 9 ) )   ||
+                ( ( bandwidth == 5 ) && ( datarate > 9 ) )   ||
+                ( ( bandwidth == 4 ) && ( datarate > 8 ) )   ||  ( bandwidth < 4 )
+                //The below is actually correct method, but assume BW = 20.8 and lower will always have SF > 8
+//                ( ( bandwidth == 3 ) && ( datarate > 8 ) )   ||
+//                ( ( bandwidth == 2 ) && ( datarate > 7 ) )   ||
+//                ( ( bandwidth == 1 ) && ( datarate > 7 ) )   ||
+//                ( ( bandwidth == 0 ) && ( datarate > 6 ) )
+                )
             {
                 this->settings.LoRa.LowDatarateOptimize = 0x01;
             }
@@ -1047,7 +1067,7 @@
 void SX1276::OnDio0Irq( void )
 {
     __IO uint8_t irqFlags = 0;
-
+  
     switch( this->settings.State )
     {                
         case RX: