Skip to content

Commit 1a6196a

Browse files
authored
Merge pull request #450 from sparkfun/addLoRa
Add LoRa Radio control
2 parents b15fca0 + 3952d7b commit 1a6196a

File tree

11 files changed

+918
-106
lines changed

11 files changed

+918
-106
lines changed

Firmware/RTK_Everywhere/Base.ino

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ void processRTCM(uint8_t *rtcmData, uint16_t dataLength)
1212
for (int x = 0; x < dataLength; x++)
1313
espnowProcessRTCM(rtcmData[x]);
1414

15+
loraProcessRTCM(rtcmData, dataLength);
16+
1517
rtcmLastPacketSent = millis();
1618
rtcmPacketsSent++;
1719

Firmware/RTK_Everywhere/Begin.ino

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,8 @@ void beginBoard()
219219

220220
pin_GNSS_TimePulse = 39; // PPS on UM980
221221

222-
pin_muxA = 18; // Controls U12 switch between ESP UART1 to UM980 or LoRa
222+
pin_muxA = 18; // Controls U12 switch between ESP UART1 to UM980 UART3 or LoRa UART0
223+
pin_muxB = 12; // Controls U18 switch between ESP UART0 to LoRa UART2 or UM980 UART1
223224
pin_usbSelect = 21;
224225
pin_powerAdapterDetect = 36; // Goes low when USB cable is plugged in
225226

@@ -270,18 +271,21 @@ void beginBoard()
270271
digitalWrite(pin_usbSelect, HIGH); // Keep CH340 connected to USB bus
271272

272273
pinMode(pin_muxA, OUTPUT);
273-
digitalWrite(pin_muxA, LOW); // Keep ESP UART1 connected to UM980
274+
muxSelectUm980(); // Connect ESP UART1 to UM980
275+
276+
pinMode(pin_muxB, OUTPUT);
277+
muxSelectUsb(); // Connect ESP UART0 to CH340 Serial
274278

275279
settings.dataPortBaud = 115200; // Override settings. Use UM980 at 115200bps.
276280

277281
pinMode(pin_loraRadio_power, OUTPUT);
278-
digitalWrite(pin_loraRadio_power, LOW); // Keep LoRa powered down
282+
loraPowerOff(); // Keep LoRa powered down for now
279283

280284
pinMode(pin_loraRadio_boot, OUTPUT);
281-
digitalWrite(pin_loraRadio_boot, LOW);
285+
digitalWrite(pin_loraRadio_boot, LOW); //Exit bootloader, run program
282286

283287
pinMode(pin_loraRadio_reset, OUTPUT);
284-
digitalWrite(pin_loraRadio_reset, LOW); // Keep LoRa in reset
288+
digitalWrite(pin_loraRadio_reset, LOW); // Reset STM32/radio
285289
}
286290

287291
else if (productVariant == RTK_EVK)
@@ -1389,15 +1393,6 @@ bool i2cBusInitialization(TwoWire *i2cBus, int sda, int scl, int clockKHz)
13891393
return true;
13901394
}
13911395

1392-
// Depending on radio settings, begin hardware
1393-
void radioStart()
1394-
{
1395-
if (settings.enableEspNow == true)
1396-
espnowStart();
1397-
else
1398-
espnowStop();
1399-
}
1400-
14011396
// Start task to determine SD card size
14021397
void beginSDSizeCheckTask()
14031398
{

Firmware/RTK_Everywhere/ESPNOW.ino

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,47 @@
1313
few seconds so a single dropped frame is not critical.
1414
*/
1515

16+
// Called from main loop
17+
// Control incoming/outgoing RTCM data from internal ESP NOW radio
18+
// Use the ESP32 to directly transmit/receive RTCM over 2.4GHz (no WiFi needed)
19+
void updateEspnow()
20+
{
21+
#ifdef COMPILE_ESPNOW
22+
if (settings.enableEspNow == true)
23+
{
24+
if (espnowState == ESPNOW_PAIRED)
25+
{
26+
// If it's been longer than a few ms since we last added a byte to the buffer
27+
// then we've reached the end of the RTCM stream. Send partial buffer.
28+
if (espnowOutgoingSpot > 0 && (millis() - espnowLastAdd) > 50)
29+
{
30+
if (settings.espnowBroadcast == false)
31+
esp_now_send(0, (uint8_t *)&espnowOutgoing, espnowOutgoingSpot); // Send partial packet to all peers
32+
else
33+
{
34+
uint8_t broadcastMac[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
35+
esp_now_send(broadcastMac, (uint8_t *)&espnowOutgoing,
36+
espnowOutgoingSpot); // Send packet via broadcast
37+
}
38+
39+
if (!inMainMenu)
40+
{
41+
if (settings.debugEspNow == true)
42+
systemPrintf("ESPNOW transmitted %d RTCM bytes\r\n", espnowBytesSent + espnowOutgoingSpot);
43+
}
44+
espnowBytesSent = 0;
45+
espnowOutgoingSpot = 0; // Reset
46+
}
47+
48+
// If we don't receive an ESP NOW packet after some time, set RSSI to very negative
49+
// This removes the ESPNOW icon from the display when the link goes down
50+
if (millis() - lastEspnowRssiUpdate > 5000 && espnowRSSI > -255)
51+
espnowRSSI = -255;
52+
}
53+
}
54+
#endif // COMPILE_ESPNOW
55+
}
56+
1657
// Create a struct for ESP NOW pairing
1758
typedef struct PairMessage
1859
{
@@ -115,6 +156,12 @@ void promiscuous_rx_cb(void *buf, wifi_promiscuous_pkt_type_t type)
115156
// If the radio is off entirely, start the radio, turn on only the LR protocol
116157
void espnowStart()
117158
{
159+
if (settings.enableEspNow == false)
160+
{
161+
espnowStop();
162+
return;
163+
}
164+
118165
#ifdef COMPILE_ESPNOW
119166

120167
// Before we can issue esp_wifi_() commands WiFi must be started

0 commit comments

Comments
 (0)