Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/helpers/sensors/EnvironmentSensorManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,11 @@ void EnvironmentSensorManager::initBasicGPS() {
MESH_DEBUG_PRINTLN("No GPS detected");
}
_location->stop();
// Pull up MCU's RX pin before ending UART. When GPS powers down, its TX
// line drops LOW (break condition) which prevents nRF52 UARTE's RXTO event
// from firing, causing Serial1.end() to hang indefinitely.
pinMode(PIN_GPS_TX, INPUT_PULLUP); // PIN_GPS_TX = toward CPU = MCU's RX
Serial1.end(); // Disable UART peripheral to save power (significant on nRF52)
gps_active = false; //Set GPS visibility off until setting is changed
}

Expand Down Expand Up @@ -680,6 +685,14 @@ void EnvironmentSensorManager::start_gps() {
return;
#endif

// Re-initialize UART (was closed by stop_gps() to save power)
Serial1.setPins(PIN_GPS_TX, PIN_GPS_RX);
#ifdef GPS_BAUD_RATE
Serial1.begin(GPS_BAUD_RATE);
#else
Serial1.begin(9600);
#endif

_location->begin();
_location->reset();

Expand All @@ -697,6 +710,9 @@ void EnvironmentSensorManager::stop_gps() {
#endif

_location->stop();
// Pull up MCU's RX pin before ending UART - see comment in initBasicGPS()
pinMode(PIN_GPS_TX, INPUT_PULLUP);
Serial1.end(); // Disable UART peripheral to save power (significant on nRF52)

#ifndef PIN_GPS_EN
MESH_DEBUG_PRINTLN("Stop GPS is N/A on this board. Actual GPS state unchanged");
Expand All @@ -707,7 +723,9 @@ void EnvironmentSensorManager::loop() {
static long next_gps_update = 0;

#if ENV_INCLUDE_GPS
_location->loop();
if (gps_active) {
_location->loop();
}
if (millis() > next_gps_update) {

if(gps_active){
Expand Down