Files @ f76c13fc8299
Branch filter:

Location: FeatherHAB/wsprhab/src/main.c - annotation

Ethan Zonca
Cycle through different tones son the si5351
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
9becfc2d0fd1
f76c13fc8299
f76c13fc8299
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0dd5c923fdea
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
9becfc2d0fd1
0d9900312165
0d9900312165
0d9900312165
9becfc2d0fd1
9becfc2d0fd1
9becfc2d0fd1
9becfc2d0fd1
9becfc2d0fd1
9becfc2d0fd1
0d9900312165
f76c13fc8299
f76c13fc8299
f76c13fc8299
0d9900312165
b5b9635e3cd8
b5b9635e3cd8
0d9900312165
0d9900312165
f76c13fc8299
0d9900312165
0d9900312165
0d9900312165
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
f76c13fc8299
0d9900312165
0d9900312165
f76c13fc8299
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
0d9900312165
#include "stm32f0xx_hal.h"
#include "si5351.h"
#include "jtencode.h"
#include "adc.h"
#include "dma.h"
#include "i2c.h"
#include "usart.h"
#include "gpio.h"
#include "gps.h"


void sysclk_init(void);
#define WSPR_DEFAULT_FREQ 14097100UL
#define WSPR_TONE_SPACING 146 // ~1.46 Hz
#define WSPR_CTC 10672 // CTC value for WSPR

char call[7] = "N0CALL";
char loc[5] = "AA00";
uint8_t dbm = 27;
uint8_t tx_buffer[255];


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;

void encode_wspr(void)
{
    uint8_t i;
    //for(i=0; i<255; i++)
    //    tx_buffer[i] = 0;

    wspr_encode(call, loc, dbm, tx_buffer);


    //si5351_output_enable(SI5351_CLK0, 1);

    for(i=0; i<symbol_count; i++)
    {

        uint32_t freq2 = (freq * 100) + (tx_buffer[i] * tone_spacing);
        si5351_set_freq(freq2, 0, SI5351_CLK0);

          //si5351_set_freq((freq * 100) + (tx_buffer[i] * tone_spacing), 0, SI5351_CLK0);
          HAL_Delay(300);
          //proceed = 0;
          //while(!proceed);
    }
}

int main(void)
{
    HAL_Init();

    sysclk_init();
    gpio_init();
    MX_DMA_Init();
    MX_ADC_Init();
    i2c_init();

    HAL_GPIO_WritePin(OSC_NOTEN, 0);
    HAL_GPIO_WritePin(TCXO_EN, 1);
    HAL_Delay(100);

//    MX_USART1_UART_Init();

    jtencode_init();
    //gps_init();
    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_2MA); // Set for max power if desired (8ma max)
    si5351_output_enable(SI5351_CLK0, 1);
    //si5351_pll_reset(SI5351_PLLA);

    //wspr_encode(call, loc, dbm, tx_buffer);

    encode_wspr();

    HAL_Delay(1000);

    uint32_t led_timer = HAL_GetTick();
    uint32_t last_gps  = HAL_GetTick();
    uint32_t last_wspr  = HAL_GetTick();

    while (1)
    {
        if(HAL_GetTick() - last_wspr > 6000)
        {
            last_wspr = HAL_GetTick();
        }
        
        if(HAL_GetTick() - led_timer > 100)
        {
            //HAL_GPIO_TogglePin(LED_BLUE);
            led_timer = HAL_GetTick();
        }
        if(HAL_GetTick() - last_gps > 100)
        {
//            gps_process();
            last_gps = HAL_GetTick();
        }
    }
}


// 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_SYSCLK;
    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_PCLK1;
    PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_SYSCLK;
    HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit);

    HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

    HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

    // SysTick_IRQn interrupt configuration 
    HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
}