Simple example Ping Pong from Semtech, updated new lib

Dependencies:   SX1276Lib mbed

Fork of SX1276PingPong by Semtech

i'm using stm32 nucleo l46rg and stm32 nucleo l073 with sx1276mb1mas.

Files at this revision

API Documentation at this revision

Comitter:
NguyenNguyenQuocHuy1
Date:
Tue Aug 16 04:03:12 2016 +0000
Parent:
14:c7251480feb9
Commit message:
updated lib

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Wed Feb 17 09:28:29 2016 +0000
+++ b/main.cpp	Tue Aug 16 04:03:12 2016 +0000
@@ -4,11 +4,11 @@
 #include "debug.h"
 
 /* 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 USE_MODEM_FSK   !USE_MODEM_LORA
 
 #define RF_FREQUENCY                                    868000000 // Hz
 #define TX_OUTPUT_POWER                                 14        // 14 dBm
@@ -32,7 +32,7 @@
     #define LORA_IQ_INVERSION_ON                        false
     #define LORA_CRC_ENABLED                            true
     
-#elif USE_MODEM_FSK == 1
+/*#elif USE_MODEM_FSK == 1
 
     #define FSK_FDEV                                    25000     // Hz
     #define FSK_DATARATE                                19200     // bps
@@ -40,13 +40,13 @@
     #define FSK_AFC_BANDWIDTH                           83333     // Hz
     #define FSK_PREAMBLE_LENGTH                         5         // Same for Tx and Rx
     #define FSK_FIX_LENGTH_PAYLOAD_ON                   false
-    #define FSK_CRC_ENABLED                             true
+    #define FSK_CRC_ENABLED                             true*/
     
 #else
     #error "Please define a modem in the compiler options."
 #endif
 
-#define RX_TIMEOUT_VALUE                                3500000   // in us
+#define RX_TIMEOUT_VALUE                                35000000   //  DU 1 SO 0
 #define BUFFER_SIZE                                     32        // Define the payload size here
 
 #if( defined ( TARGET_KL25Z ) || defined ( TARGET_LPC11U6X ) )
@@ -100,6 +100,8 @@
     uint8_t i;
     bool isMaster = true;
     
+    debug ("\n\r HUY  \n\r");
+    
     debug( "\n\n\r     SX1276 Ping Pong Demo Application \n\n\r" );
 
     // Initialize Radio driver
@@ -109,6 +111,7 @@
     RadioEvents.TxTimeout = OnTxTimeout;
     RadioEvents.RxTimeout = OnRxTimeout;
     Radio.Init( &RadioEvents );
+    debug ("\n\r HUY HUY  \n\r");
     
     // verify the connection with the board
     while( Radio.Read( REG_VERSION ) == 0x00  )
@@ -117,15 +120,17 @@
         wait( 1 );
     }
             
-    debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ) , "\n\r > Board Type: SX1276MB1LAS < \n\r" );
+    //debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1LAS ) ) , "\n\r > Board Type: SX1276MB1LAS < \n\r" );
     debug_if( ( DEBUG_MESSAGE & ( Radio.DetectBoardType( ) == SX1276MB1MAS ) ) , "\n\r > Board Type: SX1276MB1MAS < \n\r" );
-    
+    debug ("\n\r HUY HUY HUY  \n\r");
     Radio.SetChannel( RF_FREQUENCY ); 
 
 #if USE_MODEM_LORA == 1
     
     debug_if( LORA_FHSS_ENABLED, "\n\n\r             > LORA FHSS Mode < \n\n\r");
     debug_if( !LORA_FHSS_ENABLED, "\n\n\r             > LORA Mode < \n\n\r");
+    
+    debug ("\n\r HUY HUY HUY HUY  \n\r");
 
     Radio.SetTxConfig( MODEM_LORA, TX_OUTPUT_POWER, 0, LORA_BANDWIDTH,
                          LORA_SPREADING_FACTOR, LORA_CODINGRATE,
@@ -139,7 +144,7 @@
                          LORA_CRC_ENABLED, LORA_FHSS_ENABLED, LORA_NB_SYMB_HOP, 
                          LORA_IQ_INVERSION_ON, true );
                          
-#elif USE_MODEM_FSK == 1
+/*#elif USE_MODEM_FSK == 1
 
     debug("\n\n\r              > FSK Mode < \n\n\r");
     Radio.SetTxConfig( MODEM_FSK, TX_OUTPUT_POWER, FSK_FDEV, 0,
@@ -150,7 +155,7 @@
     Radio.SetRxConfig( MODEM_FSK, FSK_BANDWIDTH, FSK_DATARATE,
                          0, FSK_AFC_BANDWIDTH, FSK_PREAMBLE_LENGTH,
                          0, FSK_FIX_LENGTH_PAYLOAD_ON, 0, FSK_CRC_ENABLED,
-                         0, 0, false, true );
+                         0, 0, false, true );*/
                          
 #else
 
@@ -158,7 +163,11 @@
 
 #endif
      
+     
+     
     debug_if( DEBUG_MESSAGE, "Starting Ping-Pong loop\r\n" ); 
+     
+     debug ("\n\r HUY PING PONG  \n\r");
         
     led = 0;
         
@@ -177,6 +186,7 @@
                     {
                         led = !led;
                         debug( "...Pong\r\n" );
+                        debug ("\n\r HUY PONG  \n\r");
                         // Send the next PING frame            
                         strcpy( ( char* )Buffer, ( char* )PingMsg );
                         // We fill the buffer with numbers for the payload 
@@ -190,6 +200,7 @@
                     else if( strncmp( ( const char* )Buffer, ( const char* )PingMsg, 4 ) == 0 )
                     { // A master already exists then become a slave
                         debug( "...Ping\r\n" );
+                        debug ("\n\r HUY PING  \n\r");
                         led = !led;
                         isMaster = false;
                         // Send the next PONG frame            
@@ -217,6 +228,7 @@
                     {
                         led = !led;
                         debug( "...Ping\r\n" );
+                        debug ("\n\r HUY PING 2  \n\r");
                         // Send the reply to the PING string
                         strcpy( ( char* )Buffer, ( char* )PongMsg );
                         // We fill the buffer with numbers for the payload 
@@ -241,10 +253,12 @@
             if( isMaster == true )  
             {
                 debug( "Ping...\r\n" );
+                debug ("\n\r HUY PING 3  \n\r");
             }
             else
             {
                 debug( "Pong...\r\n" );
+                debug ("\n\r HUY PONG 2 \n\r");
             }
             Radio.Rx( RX_TIMEOUT_VALUE );
             State = LOWPOWER;
@@ -311,6 +325,7 @@
     Radio.Sleep( );
     State = TX;
     debug_if( DEBUG_MESSAGE, "> OnTxDone\n\r" );
+    debug ("\n\r HUY ONTXDONE  \n\r");
 }
 
 void OnRxDone( uint8_t *payload, uint16_t size, int16_t rssi, int8_t snr)
@@ -322,6 +337,7 @@
     SnrValue = snr;
     State = RX;
     debug_if( DEBUG_MESSAGE, "> OnRxDone\n\r" );
+    debug ("\n\r HUY RXDONE  \n\r");
 }
 
 void OnTxTimeout( void )
@@ -329,6 +345,7 @@
     Radio.Sleep( );
     State = TX_TIMEOUT;
     debug_if( DEBUG_MESSAGE, "> OnTxTimeout\n\r" );
+    debug ("\n\r HUYTX_TIMEOUT  \n\r");
 }
 
 void OnRxTimeout( void )
@@ -337,6 +354,7 @@
     Buffer[ BufferSize ] = 0;
     State = RX_TIMEOUT;
     debug_if( DEBUG_MESSAGE, "> OnRxTimeout\n\r" );
+    debug ("\n\r HUY RX_TIMEOUT  \n\r");
 }
 
 void OnRxError( void )
--- a/mbed.bld	Wed Feb 17 09:28:29 2016 +0000
+++ b/mbed.bld	Tue Aug 16 04:03:12 2016 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/165afa46840b
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/b0220dba8be7
\ No newline at end of file