Files
@ 21759af9d2ad
Branch filter:
Location: FeatherHAB/wsprhab/src/wspr.c - annotation
21759af9d2ad
2.9 KiB
text/plain
Various changes
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 | c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 c1b1dfc6c2f4 | #include "stm32f0xx_hal.h"
#include "si5351.h"
#include "jtencode.h"
#include "gpio.h"
#include "wspr.h"
#include "config.h"
#define WSPR_DEFAULT_FREQ 10140100UL
#define WSPR_TONE_SPACING 146 // ~1.46 Hz
#define WSPR_CTC 10672 // CTC value for WSPR
// 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;
TIM_HandleTypeDef htim1;
void wspr_init(void)
{
// 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);
}
// Do anything needed to prepare for sleep
void wspr_sleep(void)
{
HAL_TIM_Base_Stop_IT(&htim1);
}
void wspr_wakeup(void)
{
HAL_TIM_Base_Start_IT(&htim1);
}
// Bring up TCXO and oscillator IC
void wspr_transmit(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);
}
|