MAX32625PICO LP1 mode
Dependencies: SX1276GenericLib USBDevice
Fork of PICO_LP1 by
Diff: SX1276GenericPingPong/GenericPingPong2.cpp
- Revision:
- 7:8875c4d513bb
- Parent:
- 6:51f492ca61a2
--- a/SX1276GenericPingPong/GenericPingPong2.cpp Wed Oct 14 00:19:02 2020 +0000 +++ b/SX1276GenericPingPong/GenericPingPong2.cpp Fri Oct 16 06:46:00 2020 +0000 @@ -19,13 +19,13 @@ #ifdef FEATURE_LORA // in main.cpp /* 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 RF_FREQUENCY RF_FREQUENCY_915_0 // Hz -#define TX_OUTPUT_POWER 14 // 14 dBm +#define TX_OUTPUT_POWER 1 // 14 dBm #if USE_MODEM_LORA == 1 @@ -33,8 +33,11 @@ #define LORA_SPREADING_FACTOR LORA_SF7 #define LORA_CODINGRATE LORA_ERROR_CODING_RATE_4_5 -#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx -#define LORA_SYMBOL_TIMEOUT 5 // Symbols +//#define LORA_PREAMBLE_LENGTH 8 // Same for Tx and Rx, default +#define LORA_PREAMBLE_LENGTH 5 +//#define LORA_SYMBOL_TIMEOUT 5 // Symbols +#define LORA_SYMBOL_TIMEOUT 4 // Symbols + #define LORA_FIX_LENGTH_PAYLOAD_ON false #define LORA_FHSS_ENABLED false #define LORA_NB_SYMB_HOP 4 @@ -56,9 +59,11 @@ #endif -//#define RX_TIMEOUT_VALUE 3500 // in ms, default -#define RX_TIMEOUT_VALUE 333 // testing -//#define RX_TIMEOUT_VALUE 333 // in ms +#if MASTER == 1 + #define RX_TIMEOUT_VALUE 3500 // in ms, default +#elif SLAVE == 1 + #define RX_TIMEOUT_VALUE 333 // in ms +#endif //#define BUFFER_SIZE 32 // Define the payload size here //#define BUFFER_SIZE 64 // Define the payload size here @@ -246,11 +251,67 @@ if (DEBUG_MESSAGE) ad->printf("Starting Ping-Pong loop\r\n"); - - Radio->Rx( RX_TIMEOUT_VALUE ); +#if MASTER == 1 + Radio->Rx( RX_TIMEOUT_VALUE ); // initate Rx State for Master +#endif + return 0; //added by Walter due to "Control reaches end of non-void function" } + +bool SX1276MasterCheckForNewData(void) +{ + bool new_data_available = false; + switch( State ) + { + case RX: + if( BufferSizeRx > 0 ) + { + new_data_available = true; + wait_ms( 10 ); //do we need this? + if (DEBUG_MESSAGE) + ad->printf( "State=RX\r\n" ); + } + Radio->Rx( RX_TIMEOUT_VALUE ); + State = LOWPOWER; + break; + case RX_TIMEOUT: + wait_ms( 10 ); + if (DEBUG_MESSAGE) + ad->printf( "State=RX_TIMEOUT\r\n" ); + Radio->Rx( RX_TIMEOUT_VALUE ); + State = LOWPOWER; + break; + case RX_ERROR: + // We have received a Packet with a CRC error, send reply as if packet was correct + wait_ms( 10 ); + if (DEBUG_MESSAGE) + ad->printf( "State=RX_ERROR\r\n" ); + Radio->Rx( RX_TIMEOUT_VALUE ); + State = LOWPOWER; + break; + case TX_TIMEOUT: + if (DEBUG_MESSAGE) + ad->printf( "State=TX_TIMEOUT\r\n" ); + State = LOWPOWER; + break; + case LOWPOWER: + sleep(); + break; + default: + sleep(); // TODO, should this be removed? + break; + } + return new_data_available; +} + +void SX1276SlaveSendData(void) +{ + //wait_ms( 10 ); + Radio->Send( BufferTx, BufferSizeTx ); + sleep(); +} + /**************************************************************************************************************************************** * ****************************************************************************************************************************************/ @@ -558,4 +619,6 @@ } + + #endif