Changeset - 1ecaddb549ab
[Not reviewed]
default
0 3 0
Ethan Zonca - 9 years ago 2016-10-13 21:00:18
ez@ethanzonca.com
Disable timer clocks, fix transmission issues
3 files changed with 37 insertions and 17 deletions:
0 comments (0 inline, 0 general)
src/i2c.c
Show inline comments
 
@@ -36,6 +36,13 @@ void i2c_init(void)
 
}
 
 
 
void i2c_deinit(void)
 
{
 
    HAL_I2C_DeInit(&hi2c1);
 
    __I2C1_CLK_DISABLE();
 
}
 
 
 
// Get pointer to I2C port
 
I2C_HandleTypeDef* i2c_get(void)
 
{
src/main.c
Show inline comments
 
@@ -38,7 +38,6 @@ int main(void)
 
    rtc_init();
 
    gpio_init();
 
    adc_init();
 
    i2c_init();
 
    wspr_init();
 
 
    uint32_t led_timer = HAL_GetTick();
 
@@ -61,7 +60,7 @@ int main(void)
 
    {
 
 
    	// Every 10 minutes, wake up and try to wspr
 
    	if(HAL_GetTick() - last_wspr_tx_time > 60000 * 10)
 
    	if(state == SYSTEM_IDLE && (HAL_GetTick() - last_wspr_tx_time > 60000 * 10))
 
    	{
 
    		state = SYSTEM_GPSACQ;
 
    	}
 
@@ -150,7 +149,7 @@ int main(void)
 
            // Wait for wspr timeslot and start transmitting
 
            case SYSTEM_WSPRTX:
 
            {
 
            	blink_rate = BLINK_SLOW;
 
            	blink_rate = BLINK_MED;
 
                // Wait for wspr countdown timer to expire and go to tx
 
//                if(timeout_expired)
 
//                {
 
@@ -166,8 +165,8 @@ int main(void)
 
 
            			__calc_gridloc(grid_locator, latitude_flt, longitude_flt);
 
 
						last_wspr_tx_time = HAL_GetTick();
 
						wspr_transmit(grid_locator);
 
						last_wspr_tx_time = HAL_GetTick();
 
						state = SYSTEM_IDLE;
 
            		}
 
            		else
src/wspr.c
Show inline comments
 
@@ -30,19 +30,6 @@ 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);
 

	
 
    // Turn off ICs
 
    HAL_GPIO_WritePin(OSC_NOTEN, 1);
 
    HAL_GPIO_WritePin(TCXO_EN, 0);
 
@@ -68,11 +55,27 @@ void wspr_transmit(uint8_t* grid_locator
 
		loc[i] = grid_locator[i];
 
	loc[4] = '\0';
 

	
 

	
 
    // 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);
 

	
 

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

	
 
    // Bring up the chip
 
    i2c_init();
 
    si5351_init(i2c_get(), SI5351_CRYSTAL_LOAD_8PF, 0);
 
    si5351_set_correction(0);
 
    //si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
@@ -114,5 +117,16 @@ void wspr_transmit(uint8_t* grid_locator
 

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

	
 
    i2c_deinit();
 

	
 
    // Disable timer
 
    HAL_NVIC_DisableIRQ(TIM1_BRK_UP_TRG_COM_IRQn);
 
    HAL_TIM_Base_Stop_IT(&htim1);
 
    HAL_TIM_Base_DeInit(&htim1);
 

	
 
    __TIM1_CLK_DISABLE();
 

	
 

	
 
}
 

	
0 comments (0 inline, 0 general)