Files
@ dd3b59fcb7a7
Branch filter:
Location: FeatherHAB/wsprhab/src/main.c - annotation
dd3b59fcb7a7
7.1 KiB
text/plain
Added code to handle GPS fix acquisition. Hot reaq time is around 3-4s. WSPR currently disabled.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | 4202475a7575 4202475a7575 4202475a7575 4202475a7575 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 23ecc15c694d f76c13fc8299 f76c13fc8299 0d9900312165 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff af87b55ed4c6 af87b55ed4c6 af87b55ed4c6 0d9900312165 0d9900312165 4ffdc5eab0ff f76c13fc8299 f76c13fc8299 f76c13fc8299 f76c13fc8299 f76c13fc8299 f76c13fc8299 4ffdc5eab0ff f76c13fc8299 f76c13fc8299 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 e3feb70c71e6 28c7e1414fd9 f76c13fc8299 f76c13fc8299 28c7e1414fd9 28c7e1414fd9 f76c13fc8299 28c7e1414fd9 28c7e1414fd9 f76c13fc8299 f76c13fc8299 f76c13fc8299 f76c13fc8299 23ecc15c694d f76c13fc8299 28c7e1414fd9 28c7e1414fd9 f76c13fc8299 28c7e1414fd9 28c7e1414fd9 28c7e1414fd9 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff f76c13fc8299 f76c13fc8299 4ffdc5eab0ff dd3b59fcb7a7 dd3b59fcb7a7 28c7e1414fd9 23ecc15c694d 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0dd5c923fdea 4202475a7575 0d9900312165 aa624684a65e aa624684a65e c5bc128e44a6 aa624684a65e aa624684a65e aa624684a65e dd3b59fcb7a7 0d9900312165 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 23ecc15c694d aa624684a65e 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 23ecc15c694d 0d9900312165 0d9900312165 0d9900312165 c5bc128e44a6 0d9900312165 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff b295af18d965 e1db5d4a8be4 4ffdc5eab0ff dd3b59fcb7a7 0d9900312165 0d9900312165 dd3b59fcb7a7 b295af18d965 f76c13fc8299 dd3b59fcb7a7 e1db5d4a8be4 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 e1db5d4a8be4 b295af18d965 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 dd3b59fcb7a7 f76c13fc8299 f76c13fc8299 aa624684a65e e1db5d4a8be4 0d9900312165 aa624684a65e 0d9900312165 0d9900312165 2dcb56fc814b 0d9900312165 dd3b59fcb7a7 0d9900312165 0d9900312165 4ffdc5eab0ff aa624684a65e 0d9900312165 0d9900312165 0d9900312165 0d9900312165 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff ddd34459834e 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 4ffdc5eab0ff 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 aa624684a65e aa624684a65e 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 aa624684a65e 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 0d9900312165 4202475a7575 0d9900312165 0d9900312165 0d9900312165 0d9900312165 | //
// WSPRHAB: Minimal high-altitude balloon tracker with WSPR telemetry
//
#include "stm32f0xx_hal.h"
#include "si5351.h"
#include "jtencode.h"
#include "adc.h"
#include "i2c.h"
#include "usart.h"
#include "gpio.h"
#include "gps.h"
#define WSPR_DEFAULT_FREQ 10140100UL
#define WSPR_TONE_SPACING 146 // ~1.46 Hz
#define WSPR_CTC 10672 // CTC value for WSPR
// Private functions
void sysclk_init(void);
void enter_sleep(void);
void enter_deepsleep(void);
// Test stuff
char call[7] = "KD8TDF";
char loc[5] = "EN72";
uint8_t dbm = 10;
uint8_t tx_buffer[255];
// Frequencies and channel info
uint32_t freq = WSPR_DEFAULT_FREQ;
uint8_t symbol_count = WSPR_SYMBOL_COUNT;
uint16_t ctc = WSPR_CTC;
uint16_t tone_spacing = WSPR_TONE_SPACING;
volatile uint8_t proceed = 0;
// Bring up TCXO and oscillator IC
void encode_wspr(void)
{
HAL_GPIO_WritePin(OSC_NOTEN, 0);
HAL_GPIO_WritePin(TCXO_EN, 1);
HAL_Delay(100);
// Bring up the chip
si5351_init(i2c_get(), SI5351_CRYSTAL_LOAD_8PF, 0);
si5351_set_correction(0);
//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_output_enable(SI5351_CLK0, 1);
//si5351_pll_reset(SI5351_PLLA);
// Make sure the other outputs of the SI5351 are disabled
si5351_output_enable(SI5351_CLK1, 0); // Disable the clock initially
si5351_output_enable(SI5351_CLK2, 0); // Disable the clock initially
// disable clock powers
si5351_set_clock_pwr(SI5351_CLK1, 0);
si5351_set_clock_pwr(SI5351_CLK2, 0);
// Encode message to transmit
wspr_encode(call, loc, dbm, tx_buffer);
// Key transmitter
si5351_output_enable(SI5351_CLK0, 1);
// Loop through and transmit symbols TODO: Do this from an ISR or ISR-triggered main loop function call (optimal)
uint8_t i;
for(i=0; i<symbol_count; i++)
{
uint32_t freq2 = (freq * 100) + (tx_buffer[i] * tone_spacing);
si5351_set_freq(freq2, 0, SI5351_CLK0);
HAL_GPIO_TogglePin(LED_BLUE);
proceed = 0;
while(!proceed);
}
// Disable transmitter
si5351_output_enable(SI5351_CLK0, 0);
HAL_GPIO_WritePin(OSC_NOTEN, 1);
HAL_GPIO_WritePin(TCXO_EN, 0);
}
TIM_HandleTypeDef htim1;
int main(void)
{
HAL_Init();
sysclk_init();
gpio_init();
adc_init();
i2c_init();
gps_init();
//jtencode_init();
HAL_Delay(300);
//gps_poweroff();
// Disable ICs
HAL_GPIO_WritePin(OSC_NOTEN, 1);
HAL_GPIO_WritePin(TCXO_EN, 0);
HAL_GPIO_TogglePin(LED_BLUE);
// Start timer for WSPR
__TIM1_CLK_ENABLE();
htim1.Instance = TIM1;
htim1.Init.Prescaler = 512; // gives 64uS ticks from 8MHz ahbclk
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = ctc; // Count up to this value (how many 64uS ticks per symbol)
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
HAL_TIM_Base_Init(&htim1);
HAL_TIM_Base_Start_IT(&htim1);
HAL_NVIC_SetPriority(TIM1_BRK_UP_TRG_COM_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
uint32_t led_timer = HAL_GetTick();
uint32_t last_gps = HAL_GetTick();
uint32_t last_wspr = HAL_GetTick(); //0xfffff; // start immediately.
HAL_GPIO_TogglePin(LED_BLUE);
HAL_Delay(100);
HAL_GPIO_TogglePin(LED_BLUE);
HAL_Delay(100);
HAL_GPIO_TogglePin(LED_BLUE);
HAL_Delay(100);
HAL_GPIO_TogglePin(LED_BLUE);
HAL_Delay(100);
uint8_t lastMinute = 0;
uint16_t blink_rate = 250;
while (1)
{
// TODO: Trigger this when RTC thinks its time to go
if(HAL_GetTick() - last_wspr > 500)
{
switch(gps_getstate())
{
case GPS_STATE_ACQUIRING:
blink_rate = 250;
break;
case GPS_STATE_FRESHFIX:
blink_rate = 50;
break;
case GPS_STATE_STALEFIX:
case GPS_STATE_NOFIX:
gps_acquirefix();
blink_rate = 500;
break;
}
// EMZ TODO: this needs to trigger off of RTC minute, not GPS minute
// volatile uint8_t minute = get_timestamp()[3] - 0x30;
//
// // If last minute was odd and this minute is even (transition)
// if(lastMinute%2 == 1 && minute%2 == 0)
// {
// // Wait until the first second of the minute
// HAL_Delay(1000);
// encode_wspr();
// }
// lastMinute = minute;
last_wspr = HAL_GetTick();
}
if(HAL_GetTick() - led_timer > blink_rate)
{
HAL_GPIO_TogglePin(LED_BLUE);
led_timer = HAL_GetTick();
}
if(HAL_GetTick() - last_gps > 10)
{
gps_process();
last_gps = HAL_GetTick();
}
//enter_sleep();
}
}
void enter_sleep(void)
{
//HAL_SuspendTick();
HAL_TIM_Base_Stop_IT(&htim1);
HAL_PWR_EnterSLEEPMode(PWR_MAINREGULATOR_ON, PWR_SLEEPENTRY_WFI);
HAL_TIM_Base_Start_IT(&htim1);
//HAL_ResumeTick();
}
void enter_deepsleep(void)
{
// Request to enter STOP mode with regulator in low power mode
HAL_PWR_EnterSTOPMode(PWR_LOWPOWERREGULATOR_ON, PWR_STOPENTRY_WFI);
// After wake-up from STOP reconfigure the PLL
sysclk_init();
}
// Initialize system clocks
void sysclk_init(void)
{
RCC_OscInitTypeDef RCC_OscInitStruct;
RCC_ClkInitTypeDef RCC_ClkInitStruct;
RCC_PeriphCLKInitTypeDef PeriphClkInit;
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI|RCC_OSCILLATORTYPE_HSI14;
RCC_OscInitStruct.HSIState = RCC_HSI_ON;
RCC_OscInitStruct.HSI14State = RCC_HSI14_ON;
RCC_OscInitStruct.HSICalibrationValue = 16;
RCC_OscInitStruct.HSI14CalibrationValue = 16;
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;
HAL_RCC_OscConfig(&RCC_OscInitStruct);
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|RCC_CLOCKTYPE_PCLK1;
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0);
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART1|RCC_PERIPHCLK_I2C1;
PeriphClkInit.Usart1ClockSelection = RCC_USART1CLKSOURCE_SYSCLK; //RCC_USART1CLKSOURCE_PCLK1;
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);
__SYSCFG_CLK_ENABLE();
// SysTick_IRQn interrupt configuration
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}
|