Skip to content

Commit 330b1f6

Browse files
committed
Merge branch 'support_SX1268' into dev
2 parents 72edddc + 63af8e1 commit 330b1f6

File tree

1 file changed

+67
-24
lines changed

1 file changed

+67
-24
lines changed

src/Fossa_GroundStation/Fossa_GroundStation.ino

Lines changed: 67 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@
3939
#include <ESPAsyncWiFiManager.h> // https://github.com/alanswx/ESPAsyncWiFiManager
4040
#include "BoardConfig.h"
4141

42+
43+
#define RADIO_TYPE SX1278 // type of radio module to be used
44+
//#define RADIO_SX126X // also uncomment this line when using SX126x!!!
45+
46+
4247
constexpr auto LOG_TAG = "FOSSAGS";
4348

4449
Esp32_mqtt_clientClass mqtt;
@@ -136,19 +141,36 @@ void printLocalTime()
136141
// GPIO14 — SX1278’s RESET
137142
// GPIO26 — SX1278’s IRQ(Interrupt Request)
138143

139-
// SX1278 has the following connections:
140-
SX1278 lora = new Module(18, 26, 12);
141-
// NSS pin: 18
142-
// DIO0 pin: 26
143-
// DIO1 pin: 12 (not used as isn't connected in the TTGo)
144+
// SX1278 - SX1268 has the following connections:
145+
146+
// pin definitions
147+
#define CS 18
148+
#define DIO0 26
149+
#define DIO1 12 // not connected on the ESP32 - TTGO
150+
#define BUSY 12
151+
152+
153+
154+
155+
#ifdef RADIO_SX126X
156+
RADIO_TYPE lora = new Module(CS, DIO0, BUSY);
157+
#else
158+
RADIO_TYPE lora = new Module(CS, DIO0, DIO1);
159+
#endif
144160

161+
// modem configuration
145162
#define LORA_CARRIER_FREQUENCY 436.7f // MHz
146163
#define LORA_BANDWIDTH 125.0f // kHz dual sideband
147164
#define LORA_SPREADING_FACTOR 11
148165
#define LORA_SPREADING_FACTOR_ALT 10
149166
#define LORA_CODING_RATE 8 // 4/8, Extended Hamming
150167
#define LORA_OUTPUT_POWER 21 // dBm
151168
#define LORA_CURRENT_LIMIT 120 // mA
169+
#define SYNC_WORD_7X 0xFF // sync word when using SX127x
170+
#define SYNC_WORD_6X 0x0F0F // SX126x
171+
172+
173+
152174

153175
// satellite callsign
154176
char callsign[] = "FOSSASAT-1";
@@ -504,28 +526,43 @@ void setup() {
504526
printLocalTime();
505527

506528
// initialize SX1278 with default settings
507-
Serial.print(F("[SX1278] Initializing ... "));
529+
Serial.print(F("[SX12x8] Initializing ... "));
508530
// carrier frequency: 436.7 MHz
509531
// bandwidth: 125.0 kHz
510532
// spreading factor: 11
511533
// coding rate: 8
512-
// sync word: 0xff
534+
// sync word: 0xff for SX1278 and 0x0F0F for SX1268
513535
// output power: 17 dBm
514536
// current limit: 100 mA
515537
// preamble length: 8 symbols
516538
// amplifier gain: 0 (automatic gain control)
517539
// int state = lora.begin();
518540

519-
int state = lora.begin(LORA_CARRIER_FREQUENCY,
520-
LORA_BANDWIDTH,
521-
LORA_SPREADING_FACTOR,
522-
LORA_CODING_RATE,
523-
0xff,
524-
17,
525-
(uint8_t)LORA_CURRENT_LIMIT);
541+
#ifdef RADIO_SX126X
542+
int state = lora.begin(LORA_CARRIER_FREQUENCY,
543+
LORA_BANDWIDTH,
544+
LORA_SPREADING_FACTOR,
545+
LORA_CODING_RATE,
546+
SYNC_WORD_6X,
547+
17,
548+
(uint8_t)LORA_CURRENT_LIMIT);
549+
#else
550+
int state = lora.begin(LORA_CARRIER_FREQUENCY,
551+
LORA_BANDWIDTH,
552+
LORA_SPREADING_FACTOR,
553+
LORA_CODING_RATE,
554+
SYNC_WORD_7X,
555+
17,
556+
(uint8_t)LORA_CURRENT_LIMIT);
557+
#endif
558+
526559
Serial.println(LORA_CARRIER_FREQUENCY);
527560
Serial.println(LORA_SPREADING_FACTOR);
528561
Serial.println(LORA_CODING_RATE);
562+
563+
564+
565+
529566
if (state == ERR_NONE) {
530567
Serial.println(F("success!"));
531568
} else {
@@ -536,10 +573,15 @@ void setup() {
536573

537574
// set the function that will be called
538575
// when new packet is received
576+
// attach the ISR to radio interrupt
577+
#ifdef RADIO_SX126X
578+
lora.setDio1Action(setFlag);
579+
#else
539580
lora.setDio0Action(setFlag);
581+
#endif
540582

541583
// start listening for LoRa packets
542-
Serial.print(F("[SX1278] Starting to listen ... "));
584+
Serial.print(F("[SX12x8] Starting to listen ... "));
543585
state = lora.startReceive();
544586
if (state == ERR_NONE) {
545587
Serial.println(F("success!"));
@@ -691,10 +733,11 @@ void loop() {
691733

692734
// set radio mode to reception
693735
#ifdef RADIO_SX126X
694-
// lora.setDio1Action(onInterrupt);
736+
lora.setDio1Action(setFlag);
695737
#else
696-
// lora.setDio0Action(onInterrupt);
738+
lora.setDio0Action(setFlag);
697739
#endif
740+
698741
lora.startReceive();
699742
enableInterrupt = true;
700743
}
@@ -755,17 +798,17 @@ void loop() {
755798
last_packet_received_frequencyerror=lora.getFrequencyError();
756799

757800
// print RSSI (Received Signal Strength Indicator)
758-
Serial.print(F("[SX1278] RSSI:\t\t"));
801+
Serial.print(F("[SX12x8] RSSI:\t\t"));
759802
Serial.print(lora.getRSSI());
760803
Serial.println(F(" dBm"));
761804

762805
// print SNR (Signal-to-Noise Ratio)
763-
Serial.print(F("[SX1278] SNR:\t\t"));
806+
Serial.print(F("[SX12x8] SNR:\t\t"));
764807
Serial.print(lora.getSNR());
765808
Serial.println(F(" dB"));
766809

767810
// print frequency error
768-
Serial.print(F("[SX1278] Frequency error:\t"));
811+
Serial.print(F("[SX12x8] Frequency error:\t"));
769812
Serial.print(lora.getFrequencyError());
770813
Serial.println(F(" Hz"));
771814

@@ -851,17 +894,17 @@ void loop() {
851894

852895
if (state == ERR_NONE) {
853896
// packet was successfully received
854-
// Serial.println(F("[SX1278] Received packet!"));
897+
// Serial.println(F("[SX12x8] Received packet!"));
855898

856899
// print data of the packet
857-
// Serial.print(F("[SX1278] Data:\t\t"));
900+
// Serial.print(F("[SX12x8] Data:\t\t"));
858901
// Serial.println(str);
859902
} else if (state == ERR_CRC_MISMATCH) {
860903
// packet was received, but is malformed
861-
Serial.println(F("[SX1278] CRC error!"));
904+
Serial.println(F("[SX12x8] CRC error!"));
862905
} else {
863906
// some other error occurred
864-
Serial.print(F("[SX1278] Failed, code "));
907+
Serial.print(F("[SX12x8] Failed, code "));
865908
Serial.println(state);
866909
}
867910

0 commit comments

Comments
 (0)