Changeset - b5b9635e3cd8
[Not reviewed]
default
0 3 0
Ethan Zonca - 10 years ago 2016-03-06 21:56:52
ez@ethanzonca.com
Fix comms issues with the SI5351 which actually works now
3 files changed with 18 insertions and 17 deletions:
0 comments (0 inline, 0 general)
.settings/language.settings.xml
Show inline comments
 
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
 
<project>
 
	<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.1179702141" name="Default">
 
		<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
 
			<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
 
			<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
 
			<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1398045149230176998" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
			<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1398560194249728998" id="ilg.gnuarmeclipse.managedbuild.cross.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT GCC Built-in Compiler Settings Cross ARM" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
 
				<language-scope id="org.eclipse.cdt.core.gcc"/>
 
				<language-scope id="org.eclipse.cdt.core.g++"/>
 
			</provider>
 
			<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
 
		</extension>
 
	</configuration>
 
</project>
lib/si5351/si5351.c
Show inline comments
 
@@ -313,49 +313,50 @@ uint8_t si5351_set_freq(uint64_t freq, u
 
	
 
	// Set PLL if necessary
 
	if(write_pll == 1)
 
	{
 
		si5351_set_pll(pll_freq, target_pll);
 
	}
 

	
 
	return 0;
 
}
 

	
 
/*
 
 * set_pll(uint64_t pll_freq, enum si5351_pll target_pll)
 
 *
 
 * Set the specified PLL to a specific oscillation frequency
 
 *
 
 * pll_freq - Desired PLL frequency
 
 * target_pll - Which PLL to set
 
 *     (use the si5351_pll enum)
 
 */
 

	
 

	
 
uint8_t params[20];
 

	
 
void si5351_set_pll(uint64_t pll_freq, enum si5351_pll target_pll)
 
{ struct Si5351RegSet pll_reg;
 
{
 
  struct Si5351RegSet pll_reg;
 

	
 
  si5351_pll_calc(pll_freq, &pll_reg, ref_correction);
 

	
 
  // Derive the register values to write 
 

	
 
  // Prepare an array for parameters to be written to
 
//  uint8_t *params = new uint8_t[20];
 
  uint8_t i = 0;
 
  uint8_t temp;
 

	
 
  // Registers 26-27
 
  temp = ((pll_reg.p3 >> 8) & 0xFF);
 
  params[i++] = temp;
 

	
 
  temp = (uint8_t)(pll_reg.p3  & 0xFF);
 
  params[i++] = temp;
 

	
 
  // Register 28
 
  temp = (uint8_t)((pll_reg.p1 >> 16) & 0x03);
 
  params[i++] = temp;
 

	
 
  // Registers 29-30
 
  temp = (uint8_t)((pll_reg.p1 >> 8) & 0xFF);
 
  params[i++] = temp;
 
@@ -884,110 +885,100 @@ void si5351_set_clock_fanout(enum si5351
 
		}
 
		else
 
		{
 
			reg_val &= ~(SI5351_XTAL_ENABLE);
 
		}
 
		break;
 
	case SI5351_FANOUT_MS:
 
		if(enable)
 
		{
 
			reg_val |= SI5351_MULTISYNTH_ENABLE;
 
		}
 
		else
 
		{
 
			reg_val &= ~(SI5351_MULTISYNTH_ENABLE);
 
		}
 
		break;
 
	}
 
	
 
	si5351_write(SI5351_FANOUT_ENABLE, reg_val);
 
}
 

	
 

	
 

	
 

	
 
/* AAAH REFREAKINGIMPLEMENT WITH COMMON STANDARD I2C THINGS:
 
~/Projects/featherhab-fw/libopencm3/lib/stm32/common/i2c_common_all.c
 
*/
 

	
 
uint8_t si5351_write_bulk(uint8_t addr, uint8_t bytes, uint8_t *data)
 
{
 
    HAL_Delay(300);
 
    uint32_t res = HAL_I2C_Mem_Write(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data, bytes, 100);
 
    led_blink(res);
 
    HAL_Delay(300);
 

	
 

	
 

	
 
/*
 
	Wire.beginTransmission(SI5351_BUS_BASE_ADDR);
 
	Wire.write(addr);
 
	for(int i = 0; i < bytes; i++)
 
	{
 
		Wire.write(data[i]);
 
	}
 
	Wire.endTransmission();
 
*/
 
}
 

	
 
uint8_t si5351_write(uint8_t addr, uint8_t data)
 
{
 
    HAL_Delay(300);
 
    uint8_t data_arr[1] = {data};
 
    uint8_t res = HAL_I2C_Mem_Write(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data, 1, 100);
 
    volatile uint8_t res = HAL_I2C_Mem_Write(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data_arr, 1, 100);
 

	
 
    led_blink(res);
 
    HAL_Delay(300);
 
/*
 
	Wire.beginTransmission(SI5351_BUS_BASE_ADDR);
 
	Wire.write(addr);
 
	Wire.write(data);
 
	Wire.endTransmission();
 
*/
 
}
 

	
 
uint8_t si5351_read(uint8_t addr)
 
{
 
	uint8_t data_arr[1] = {0};
 

	
 
    HAL_Delay(300);
 
    uint8_t res = HAL_I2C_Mem_Read(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data_arr, 1, 100);
 

	
 
    led_blink(res);
 
    HAL_Delay(300);
 
/*
 
	Wire.beginTransmission(SI5351_BUS_BASE_ADDR);
 
	Wire.write(addr);
 
	Wire.endTransmission();
 

	
 
	Wire.requestFrom(SI5351_BUS_BASE_ADDR, 1, false);
 

	
 
	while(Wire.available())
 
	{
 
		reg_val = Wire.read();
 
	}
 
*/	
 
	return data_arr[1];
 
	return data_arr[0];
 
}
 

	
 
/*********************/
 
/* Private functions */
 
/*********************/
 

	
 
uint64_t si5351_pll_calc(uint64_t freq, struct Si5351RegSet *reg, int32_t correction)
 
{
 
	uint64_t ref_freq = xtal_freq * SI5351_FREQ_MULT;
 
	uint32_t a, b, c, p1, p2, p3;
 
	uint64_t lltmp, rfrac, denom;
 
	int64_t ref_temp;
 

	
 
	// Factor calibration value into nominal crystal frequency
 
	// Measured in parts-per-billion
 

	
 
	ref_freq = ref_freq + (int32_t)((((((int64_t)correction) << 31) / 1000000000LL) * ref_freq) >> 31);
 

	
 
	// PLL bounds checking
 
	if (freq < SI5351_PLL_VCO_MIN * SI5351_FREQ_MULT)
 
	{
 
		freq = SI5351_PLL_VCO_MIN * SI5351_FREQ_MULT;
 
	}
 
	if (freq > SI5351_PLL_VCO_MAX * SI5351_FREQ_MULT)
src/main.c
Show inline comments
 
@@ -2,76 +2,86 @@
 
#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);
 
 
 
char call[7] = "N0CALL";
 
char loc[5] = "AA00";
 
uint8_t dbm = 27;
 
uint8_t tx_buffer[255];
 
 
int main(void)
 
{
 
    HAL_Init();
 
 
    sysclk_init();
 
    gpio_init();
 
    led_blink(5);
 
    //led_blink(5);
 
    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_XTAL_FREQ
 
    si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
 
    si5351_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
 
    si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA);
 
    si5351_set_ms_source(SI5351_CLK1, SI5351_PLLA);
 
    si5351_set_ms_source(SI5351_CLK2, SI5351_PLLA);
 
    si5351_set_ms_source(SI5351_CLK3, SI5351_PLLA);
 
 
    si5351_set_freq(100000UL * 100, 0, SI5351_CLK0);
 
    si5351_set_freq(1000000UL * 100, SI5351_PLL_FIXED, SI5351_CLK0);
 
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_2MA); // Set for max power if desired (8ma max)
 
 
 
    si5351_output_enable(SI5351_CLK0, 1); // Disable the clock initially
 
 
    //wspr_encode(call, loc, dbm, tx_buffer);
 
 
    si5351_pll_reset(SI5351_PLLA);
 
 
    HAL_Delay(1000);
 
 
    uint32_t led_timer = HAL_GetTick();
 
    uint32_t last_gps  = HAL_GetTick();
 
 
    while (1)
 
    {
 
        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;
0 comments (0 inline, 0 general)