I-O DATA DEV2 / Mbed 2 deprecated Nucleo_Private_LoRa

Dependencies:   mbed Private_lora_SX1276

Revision:
2:0da0a3008102
Parent:
1:b8126d119fda
--- a/main.cpp	Wed Nov 25 08:17:35 2020 +0000
+++ b/main.cpp	Fri Dec 18 00:26:49 2020 +0000
@@ -3,30 +3,49 @@
 #include "sx1276-hal.h"
 #include "debug.h"
 
+/***********************************************
+ Semtech SX1276 Loraの実験 
+  Priva Lora
+
+  SX1278       NUCLEO 接続
+   3.3V        AVDD
+   GND         GND
+   SPI SCK      D13  
+   SPI MISO     D12
+   SPI MOSI     D11
+   SPI CS       D10
+   RESET        D9
+   DIO0         D8
+  
+  通常は送信
+  ボタン押し リセットで受信モード
+   
+***********************************************/
+
 /* Set this flag to '1' to display debug messages on the console */
-#define DEBUG_MESSAGE   0
+#define DEBUG_MESSAGE   1
 
 /* Set this flag to '1' to use the LoRa modulation or to '0' to use FSK modulation */
 #define USE_MODEM_LORA  1
 #define USE_MODEM_FSK   !USE_MODEM_LORA
 
-#define RF868  1
+#define RF868  1 //920Mhz 429MHzはコメントにする
 
 #ifdef RF868
 
     #define RF_FREQUENCY                                    921000000 // Hz
-    #define TX_OUTPUT_POWER                                 20        // 14 dBm
+    #define TX_OUTPUT_POWER                                 13       // 13 dBm 20mW  20dB 100mWまで可能
 
 #else
 
-    #define RF_FREQUENCY                                    433000000 // Hz
-    #define TX_OUTPUT_POWER                                 14        // 26 dBm
+    #define RF_FREQUENCY                                    426375000 // Hz
+    #define TX_OUTPUT_POWER                                 13        // 20 dBm 20mW  20dB 100mWまで可能
 
 #endif
 
 #if USE_MODEM_LORA == 1
     #define LORA_BANDWIDTH  0
-    #define LORA_SPREADING_FACTOR   7 /*6-12*/
+    #define LORA_SPREADING_FACTOR   12 /*6-12   12が一番遅いが感度*/
     #define LORA_CODINGRATE     2
 
     //#define LORA_BANDWIDTH                              2         // [0: 125 kHz,
@@ -158,7 +177,7 @@
 const uint8_t PongMsg[] = "PONG";
 const uint8_t TestMsg[] = "LoRa Test";
 
-uint16_t BufferSize = 56;//BUFFER_SIZE;
+uint16_t BufferSize = 56;//up to 56 BUFFER_SIZE;
 uint8_t Buffer[BUFFER_SIZE];
 
 //int16_t RssiValue = 0.0;
@@ -226,7 +245,7 @@
 
     #ifdef UART_ENABLE
     regval = Radio.Read(REG_VERSION);
-    pc.printf("%s", TestMsg);
+    pc.printf("%s freq=%d", TestMsg, RF_FREQUENCY );
     pc.printf("IC Version: %02X\r\n", regval);
     regval = Radio.Read(REG_OPMODE);
     pc.printf("OPMODE: %02X\r\n", regval);
@@ -291,7 +310,7 @@
     
 #ifdef PINGPONG
     Radio.Rx( RX_TIMEOUT_VALUE );
-    
+    int j=0;
    
     while( 1 )
     {
@@ -464,7 +483,7 @@
     }
 
 #else
-    
+    int j=0;
     if(isMaster == true){
         tx_tmr.start();
         begin = tx_tmr.read_ms();
@@ -480,8 +499,10 @@
             State = ST_LOWPOWER;
 #ifdef UART_ENABLE
             //pc.printf("\r\nRX OK\tRSSI:%f  SNR:%f \r\n",float(RssiValue),float(SnrValue));
-            pc.printf("RX OK\tRSSI:%d  SNR:%d ",RssiValue,SnrValue);
-            pc.printf("\tRSSI: %02X SNR: %01X %s\r\n", (uint8_t)RssiValue, (uint8_t)SnrValue,Buffer);
+            if (RssiValue>=64) RssiValue -= 256; 
+            pc.printf("RX OK\tRSSI:%d SNR:%d ",RssiValue,SnrValue);
+            for(i=0;i<BufferSize;i++) if (Buffer[i] & 0x80) Buffer[i]=0; 
+            pc.printf("\tSZ=%d %s\r\n", BufferSize,Buffer);
             Buffer[0]=0;
 #endif      
             break;
@@ -508,10 +529,13 @@
             if (isMaster){
                 end = tx_tmr.read_ms();
                 if ((end-begin) >= 2000){
+                   
                     Sender();
                     tx_tmr.stop();
                     tx_tmr.start();
                     begin = tx_tmr.read_ms();
+                     if (j++ > 500) NVIC_SystemReset();
+
                 }
             }
             break;