diff --git a/inc/gpio.h b/inc/gpio.h --- a/inc/gpio.h +++ b/inc/gpio.h @@ -8,7 +8,7 @@ enum _blinkrate { BLINK_FAST = 50, BLINK_MED = 250, - BLINK_SLOW = 1000 + BLINK_SLOW = 2000 }; diff --git a/src/main.c b/src/main.c --- a/src/main.c +++ b/src/main.c @@ -40,6 +40,7 @@ uint32_t statled_ontime = 0; int main(void) { HAL_Init(); + HAL_Delay(2000); // startup delay before infinisleep sysclk_init(); rtc_init(); @@ -57,6 +58,7 @@ int main(void) uint32_t gps_polltimer = 0; uint32_t fix_acq_starttime = 0; uint32_t nextwspr_time = 0; + uint8_t nextwspr_time_valid = 0; uint32_t last_wspr_tx_time = 0; uint8_t fix_ok = 0; @@ -67,7 +69,7 @@ int main(void) { // Every 10 minutes, wake up and try to wspr - if(state == SYSTEM_IDLE && (HAL_GetTick() - last_wspr_tx_time > 60000 * 10)) + if(state == SYSTEM_IDLE && (HAL_GetTick() - last_wspr_tx_time > 60000))// * 10)) { state = SYSTEM_GPSACQ; } @@ -84,6 +86,7 @@ int main(void) { // Wait until even minute, coming soon nextwspr_time = HAL_GetTick() + (60000 - (gps_getdata()->second * 1000)); + nextwspr_time_valid = 1; } // If even minute @@ -91,6 +94,7 @@ int main(void) { // Wait until odd minute, one minute and some change away nextwspr_time = HAL_GetTick() + 60000 + (60000 - (gps_getdata()->second * 1000)); + nextwspr_time_valid = 1; } } gps_polltimer = HAL_GetTick(); @@ -107,7 +111,7 @@ int main(void) blink_rate = BLINK_SLOW; // Actually sleep for real: disable systick and sleep until RTC interrupt - HAL_SuspendTick(); +// HAL_SuspendTick(); // Enter sleep mode: wait for interrupt HAL_PWR_EnterSLEEPMode(0, PWR_SLEEPENTRY_WFI); @@ -115,9 +119,9 @@ int main(void) // We have woken up! // This is hopefully the only timer that needs to stay alive in idle mode - last_wspr_tx_time += 0; // move this timer forward based on sleep length + // last_wspr_tx_time += 0; // move this timer forward based on sleep length - HAL_ResumeTick(); + // HAL_ResumeTick(); // TODO: Eventually use GPS time to calibrate the RTC maybe @@ -141,7 +145,7 @@ int main(void) } // If 3d fix with a decent enough precision - if( ((gps_getdata()->fixtype == 2) || (gps_getdata()->fixtype == 3)) && gps_getdata()->pdop < 10) + if( ((gps_getdata()->fixtype == 2) || (gps_getdata()->fixtype == 3)) && gps_getdata()->pdop < 10 && nextwspr_time_valid == 1) { // Disable GPS module gps_poweroff(); @@ -186,8 +190,8 @@ int main(void) __calc_gridloc(grid_locator, latitude_flt, longitude_flt); + wspr_transmit(grid_locator); last_wspr_tx_time = HAL_GetTick(); - wspr_transmit(grid_locator); state = SYSTEM_IDLE; } else @@ -196,6 +200,7 @@ int main(void) last_wspr_tx_time = HAL_GetTick(); state = SYSTEM_IDLE; } + nextwspr_time_valid = 0; // invalidate wspr time } else { diff --git a/src/wspr.c b/src/wspr.c --- a/src/wspr.c +++ b/src/wspr.c @@ -81,7 +81,8 @@ void wspr_transmit(uint8_t* grid_locator //si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA); //si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA); si5351_set_freq(WSPR_DEFAULT_FREQ * 100, 0, SI5351_CLK0); - si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired (8ma max) +// si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_8MA); // Set for max power if desired (8ma max) + si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_6MA); // Set for max power if desired (8ma max) si5351_output_enable(SI5351_CLK0, 1); //si5351_pll_reset(SI5351_PLLA);