A heroic effort to push things forward. Now working includes the I2C interface and the code to talk to and start up the frequency synth. Flip flops are on, frequencies are being divided. No luck on actually getting a signal all the way through though. I currently suspect the transformers or the mixers..... how high can a quadrature sampling detector go again? :/

This commit is contained in:
Michael Colton 2016-04-21 00:57:58 -06:00
parent 1890b25a4f
commit a211a0b9dd
12 changed files with 8263 additions and 7377 deletions

Binary file not shown.

View File

@ -68,7 +68,7 @@
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="TRACE&#10;"/>
<listOptionValue builtIn="false" value="OS_USE_TRACE_SEMIHOSTING_DEBUG"/>
<listOptionValue builtIn="false" value="HSE_VALUE=24000000"/>
<listOptionValue builtIn="false" value="HSE_VALUE=26000000"/>
<listOptionValue builtIn="false" value="STM32F429xx"/>
<listOptionValue builtIn="false" value="__FPU_PRESENT"/>
<listOptionValue builtIn="false" value="ARM_MATH_CM4"/>
@ -91,7 +91,7 @@
<listOptionValue builtIn="false" value="__FPU_PRESENT"/>
<listOptionValue builtIn="false" value="TRACE&#10;"/>
<listOptionValue builtIn="false" value="OS_USE_TRACE_SEMIHOSTING_DEBUG"/>
<listOptionValue builtIn="false" value="HSE_VALUE=24000000"/>
<listOptionValue builtIn="false" value="HSE_VALUE=26000000"/>
<listOptionValue builtIn="false" value="STM32F429xx"/>
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="USE_FULL_ASSERT"/>
@ -121,7 +121,7 @@
<listOptionValue builtIn="false" value="DEBUG"/>
<listOptionValue builtIn="false" value="OS_USE_TRACE_SEMIHOSTING_DEBUG"/>
<listOptionValue builtIn="false" value="TRACE&#10;"/>
<listOptionValue builtIn="false" value="HSE_VALUE=24000000"/>
<listOptionValue builtIn="false" value="HSE_VALUE=26000000"/>
<listOptionValue builtIn="false" value="STM32F429xx"/>
<listOptionValue builtIn="false" value="__FPU_PRESENT"/>
<listOptionValue builtIn="false" value="USE_FULL_ASSERT"/>
@ -793,12 +793,26 @@
<entry excluding="Source/TransformFunctions/arm_cfft_radix2_q31.c|Source/TransformFunctions/arm_cfft_radix2_q15.c|Source/TransformFunctions/arm_cfft_radix2_init_q31.c|Source/TransformFunctions/arm_cfft_radix2_init_q15.c|Source/TransformFunctions/arm_cfft_radix2_init_f32.c|Source/TransformFunctions/arm_cfft_radix2_f32.c|Source/FilteringFunctions|Source/ControllerFunctions|Source/MatrixFunctions|Source/StatisticsFunctions|Source/SupportFunctions" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="DSP_Lib"/>
<entry excluding="uart.h|ILI9341_t3.h" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="include"/>
<entry excluding="uart.c|ILI9341_t3.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="include/cmsis/stm32f439xx.h|include/cmsis/stm32f437xx.h|include/cmsis/stm32f427xx.h|include/cmsis/stm32f417xx.h|include/cmsis/stm32f415xx.h|include/cmsis/stm32f407xx.h|include/cmsis/stm32f405xx.h|include/cmsis/stm32f401xe.h|include/cmsis/stm32f401xc.h|src/stm32f4-hal/stm32f4xx_hal_adc_ex.c|src/stm32f4-hal/stm32f4xx_hal_can.c|src/stm32f4-hal/stm32f4xx_hal_crc.c|src/stm32f4-hal/stm32f4xx_hal_cryp.c|src/stm32f4-hal/stm32f4xx_hal_cryp_ex.c|src/stm32f4-hal/stm32f4xx_hal_dac_ex.c|src/stm32f4-hal/stm32f4xx_hal_dcmi.c|src/stm32f4-hal/stm32f4xx_hal_dma2d.c|src/stm32f4-hal/stm32f4xx_hal_dma_ex.c|src/stm32f4-hal/stm32f4xx_hal_eth.c|src/stm32f4-hal/stm32f4xx_hal_hash.c|src/stm32f4-hal/stm32f4xx_hal_hash_ex.c|src/stm32f4-hal/stm32f4xx_hal_hcd.c|src/stm32f4-hal/stm32f4xx_hal_i2c.c|src/stm32f4-hal/stm32f4xx_hal_i2c_ex.c|src/stm32f4-hal/stm32f4xx_hal_i2s.c|src/stm32f4-hal/stm32f4xx_hal_i2s_ex.c|src/stm32f4-hal/stm32f4xx_hal_irda.c|src/stm32f4-hal/stm32f4xx_hal_ltdc.c|src/stm32f4-hal/stm32f4xx_hal_msp_template.c|src/stm32f4-hal/stm32f4xx_hal_nand.c|src/stm32f4-hal/stm32f4xx_hal_nor.c|src/stm32f4-hal/stm32f4xx_hal_pccard.c|src/stm32f4-hal/stm32f4xx_hal_pcd.c|src/stm32f4-hal/stm32f4xx_hal_rng.c|src/stm32f4-hal/stm32f4xx_hal_rtc_ex.c|src/stm32f4-hal/stm32f4xx_hal_sai.c|src/stm32f4-hal/stm32f4xx_hal_sd.c|src/stm32f4-hal/stm32f4xx_hal_sdram.c|src/stm32f4-hal/stm32f4xx_hal_smartcard.c|src/stm32f4-hal/stm32f4xx_hal_sram.c|src/stm32f4-hal/stm32f4xx_hal_wwdg.c|src/stm32f4-hal/stm32f4xx_ll_fmc.c|src/stm32f4-hal/stm32f4xx_ll_fsmc.c|src/stm32f4-hal/stm32f4xx_ll_sdmmc.c|src/stm32f4-hal/stm32f4xx_ll_usb.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="system"/>
<entry excluding="include/cmsis/stm32f439xx.h|include/cmsis/stm32f437xx.h|include/cmsis/stm32f427xx.h|include/cmsis/stm32f417xx.h|include/cmsis/stm32f415xx.h|include/cmsis/stm32f407xx.h|include/cmsis/stm32f405xx.h|include/cmsis/stm32f401xe.h|include/cmsis/stm32f401xc.h|src/stm32f4-hal/stm32f4xx_hal_adc_ex.c|src/stm32f4-hal/stm32f4xx_hal_can.c|src/stm32f4-hal/stm32f4xx_hal_crc.c|src/stm32f4-hal/stm32f4xx_hal_cryp.c|src/stm32f4-hal/stm32f4xx_hal_cryp_ex.c|src/stm32f4-hal/stm32f4xx_hal_dac_ex.c|src/stm32f4-hal/stm32f4xx_hal_dcmi.c|src/stm32f4-hal/stm32f4xx_hal_dma2d.c|src/stm32f4-hal/stm32f4xx_hal_dma_ex.c|src/stm32f4-hal/stm32f4xx_hal_eth.c|src/stm32f4-hal/stm32f4xx_hal_hash.c|src/stm32f4-hal/stm32f4xx_hal_hash_ex.c|src/stm32f4-hal/stm32f4xx_hal_hcd.c|src/stm32f4-hal/stm32f4xx_hal_i2s.c|src/stm32f4-hal/stm32f4xx_hal_i2s_ex.c|src/stm32f4-hal/stm32f4xx_hal_irda.c|src/stm32f4-hal/stm32f4xx_hal_ltdc.c|src/stm32f4-hal/stm32f4xx_hal_msp_template.c|src/stm32f4-hal/stm32f4xx_hal_nand.c|src/stm32f4-hal/stm32f4xx_hal_nor.c|src/stm32f4-hal/stm32f4xx_hal_pccard.c|src/stm32f4-hal/stm32f4xx_hal_pcd.c|src/stm32f4-hal/stm32f4xx_hal_rng.c|src/stm32f4-hal/stm32f4xx_hal_rtc_ex.c|src/stm32f4-hal/stm32f4xx_hal_sai.c|src/stm32f4-hal/stm32f4xx_hal_sd.c|src/stm32f4-hal/stm32f4xx_hal_sdram.c|src/stm32f4-hal/stm32f4xx_hal_smartcard.c|src/stm32f4-hal/stm32f4xx_hal_sram.c|src/stm32f4-hal/stm32f4xx_hal_wwdg.c|src/stm32f4-hal/stm32f4xx_ll_fmc.c|src/stm32f4-hal/stm32f4xx_ll_fsmc.c|src/stm32f4-hal/stm32f4xx_ll_sdmmc.c|src/stm32f4-hal/stm32f4xx_ll_usb.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="system"/>
</sourceEntries>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
<storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs"/>
<storageModule moduleId="ilg.gnuarmeclipse.managedbuild.packs">
<option id="cmsis.device.name" value="STM32F429VI"/>
<option id="cmsis.subfamily.name" value="STM32F429"/>
<option id="cmsis.family.name" value="STM32F4 Series"/>
<option id="cmsis.device.vendor.name" value="STMicroelectronics"/>
<option id="cmsis.device.vendor.id" value="13"/>
<option id="cmsis.device.pack.vendor" value="Keil"/>
<option id="cmsis.device.pack.name" value="STM32F4xx_DFP"/>
<option id="cmsis.device.pack.version" value="2.8.0"/>
<option id="cmsis.core.name" value="Cortex-M4"/>
<option id="cmsis.compiler.define" value="STM32F429xx"/>
<memory section="IRAM1" size="0x30000" start="0x20000000" startup="0"/>
<memory section="IRAM2" size="0x10000" start="0x10000000" startup="0"/>
<memory section="IROM1" size="0x200000" start="0x08000000" startup="1"/>
</storageModule>
</cconfiguration>
<cconfiguration id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.release.168796915">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="ilg.gnuarmeclipse.managedbuild.cross.config.elf.release.168796915" moduleId="org.eclipse.cdt.core.settings" name="Release">
@ -960,7 +974,7 @@
</folderInfo>
<sourceEntries>
<entry flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="src"/>
<entry excluding="src/stm32f4-hal/stm32f4xx_hal_adc.c|src/stm32f4-hal/stm32f4xx_hal_adc_ex.c|src/stm32f4-hal/stm32f4xx_hal_can.c|src/stm32f4-hal/stm32f4xx_hal_crc.c|src/stm32f4-hal/stm32f4xx_hal_cryp.c|src/stm32f4-hal/stm32f4xx_hal_cryp_ex.c|src/stm32f4-hal/stm32f4xx_hal_dac.c|src/stm32f4-hal/stm32f4xx_hal_dac_ex.c|src/stm32f4-hal/stm32f4xx_hal_dcmi.c|src/stm32f4-hal/stm32f4xx_hal_dma.c|src/stm32f4-hal/stm32f4xx_hal_dma2d.c|src/stm32f4-hal/stm32f4xx_hal_dma_ex.c|src/stm32f4-hal/stm32f4xx_hal_eth.c|src/stm32f4-hal/stm32f4xx_hal_hash.c|src/stm32f4-hal/stm32f4xx_hal_hash_ex.c|src/stm32f4-hal/stm32f4xx_hal_hcd.c|src/stm32f4-hal/stm32f4xx_hal_i2c.c|src/stm32f4-hal/stm32f4xx_hal_i2c_ex.c|src/stm32f4-hal/stm32f4xx_hal_i2s.c|src/stm32f4-hal/stm32f4xx_hal_i2s_ex.c|src/stm32f4-hal/stm32f4xx_hal_irda.c|src/stm32f4-hal/stm32f4xx_hal_ltdc.c|src/stm32f4-hal/stm32f4xx_hal_msp_template.c|src/stm32f4-hal/stm32f4xx_hal_nand.c|src/stm32f4-hal/stm32f4xx_hal_nor.c|src/stm32f4-hal/stm32f4xx_hal_pccard.c|src/stm32f4-hal/stm32f4xx_hal_pcd.c|src/stm32f4-hal/stm32f4xx_hal_rng.c|src/stm32f4-hal/stm32f4xx_hal_rtc.c|src/stm32f4-hal/stm32f4xx_hal_rtc_ex.c|src/stm32f4-hal/stm32f4xx_hal_sai.c|src/stm32f4-hal/stm32f4xx_hal_sd.c|src/stm32f4-hal/stm32f4xx_hal_sdram.c|src/stm32f4-hal/stm32f4xx_hal_smartcard.c|src/stm32f4-hal/stm32f4xx_hal_spi.c|src/stm32f4-hal/stm32f4xx_hal_sram.c|src/stm32f4-hal/stm32f4xx_hal_tim.c|src/stm32f4-hal/stm32f4xx_hal_tim_ex.c|src/stm32f4-hal/stm32f4xx_hal_uart.c|src/stm32f4-hal/stm32f4xx_hal_usart.c|src/stm32f4-hal/stm32f4xx_hal_wwdg.c|src/stm32f4-hal/stm32f4xx_ll_fmc.c|src/stm32f4-hal/stm32f4xx_ll_fsmc.c|src/stm32f4-hal/stm32f4xx_ll_sdmmc.c|src/stm32f4-hal/stm32f4xx_ll_usb.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="system"/>
<entry excluding="src/stm32f4-hal/stm32f4xx_hal_adc.c|src/stm32f4-hal/stm32f4xx_hal_adc_ex.c|src/stm32f4-hal/stm32f4xx_hal_can.c|src/stm32f4-hal/stm32f4xx_hal_crc.c|src/stm32f4-hal/stm32f4xx_hal_cryp.c|src/stm32f4-hal/stm32f4xx_hal_cryp_ex.c|src/stm32f4-hal/stm32f4xx_hal_dac.c|src/stm32f4-hal/stm32f4xx_hal_dac_ex.c|src/stm32f4-hal/stm32f4xx_hal_dcmi.c|src/stm32f4-hal/stm32f4xx_hal_dma.c|src/stm32f4-hal/stm32f4xx_hal_dma2d.c|src/stm32f4-hal/stm32f4xx_hal_dma_ex.c|src/stm32f4-hal/stm32f4xx_hal_eth.c|src/stm32f4-hal/stm32f4xx_hal_hash.c|src/stm32f4-hal/stm32f4xx_hal_hash_ex.c|src/stm32f4-hal/stm32f4xx_hal_hcd.c|src/stm32f4-hal/stm32f4xx_hal_i2s.c|src/stm32f4-hal/stm32f4xx_hal_i2s_ex.c|src/stm32f4-hal/stm32f4xx_hal_irda.c|src/stm32f4-hal/stm32f4xx_hal_ltdc.c|src/stm32f4-hal/stm32f4xx_hal_msp_template.c|src/stm32f4-hal/stm32f4xx_hal_nand.c|src/stm32f4-hal/stm32f4xx_hal_nor.c|src/stm32f4-hal/stm32f4xx_hal_pccard.c|src/stm32f4-hal/stm32f4xx_hal_pcd.c|src/stm32f4-hal/stm32f4xx_hal_rng.c|src/stm32f4-hal/stm32f4xx_hal_rtc.c|src/stm32f4-hal/stm32f4xx_hal_rtc_ex.c|src/stm32f4-hal/stm32f4xx_hal_sai.c|src/stm32f4-hal/stm32f4xx_hal_sd.c|src/stm32f4-hal/stm32f4xx_hal_sdram.c|src/stm32f4-hal/stm32f4xx_hal_smartcard.c|src/stm32f4-hal/stm32f4xx_hal_spi.c|src/stm32f4-hal/stm32f4xx_hal_sram.c|src/stm32f4-hal/stm32f4xx_hal_tim.c|src/stm32f4-hal/stm32f4xx_hal_tim_ex.c|src/stm32f4-hal/stm32f4xx_hal_uart.c|src/stm32f4-hal/stm32f4xx_hal_usart.c|src/stm32f4-hal/stm32f4xx_hal_wwdg.c|src/stm32f4-hal/stm32f4xx_ll_fmc.c|src/stm32f4-hal/stm32f4xx_ll_fsmc.c|src/stm32f4-hal/stm32f4xx_ll_sdmmc.c|src/stm32f4-hal/stm32f4xx_ll_usb.c" flags="VALUE_WORKSPACE_PATH|RESOLVED" kind="sourcePath" name="system"/>
</sourceEntries>
</configuration>
</storageModule>

Binary file not shown.

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="ilg.gnuarmeclipse.debug.gdbjtag.openocd.launchConfigurationType">
<stringAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.PERIPHERALS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#13;&#10;&lt;peripherals&gt;&#13;&#10;&lt;peripheral name=&quot;I2C2&quot;/&gt;&#13;&#10;&lt;/peripherals&gt;&#13;&#10;"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doContinue" value="true"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doDebugInRam" value="false"/>
<booleanAttribute key="ilg.gnuarmeclipse.debug.gdbjtag.openocd.doFirstReset" value="true"/>
@ -49,8 +50,8 @@
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_REGISTER_GROUPS" value=""/>
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/PSDR.elf"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="PSDR"/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value=""/>
<booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="true"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="ilg.gnuarmeclipse.managedbuild.cross.config.elf.debug.1375704298"/>
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
<listEntry value="/PSDR"/>
</listAttribute>

View File

@ -28,7 +28,7 @@
// (SEGGER J-Link device name: STM32F407VG).
#define BLINK_PORT_NUMBER (4)
#define BLINK_PIN_NUMBER (7)
#define BLINK_PIN_NUMBER (12)
#define BLINK_ACTIVE_LOW (0)
#endif

View File

@ -17,6 +17,7 @@
#include <uart.h>
#include "stm32f4xx_hal_dma.h"
#include "stm32f4xx_hal_usart.h"
#include "stm32f4xx_hal_i2c.h"
typedef struct _Gpio_Pin
{
@ -70,7 +71,7 @@ extern const Gpio_Pin LCD_NSS;
extern const Gpio_Pin RX_TO_GPS;
extern const Gpio_Pin TX_FROM_GPS;
extern const Gpio_Pin GPS_RESET;
extern const Gpio_Pin GPS_FIX_LED;
//extern const Gpio_Pin GPS_FIX_LED;
extern const Gpio_Pin GPS_PPS;
extern const Gpio_Pin GPS_POWER;
extern const Gpio_Pin LCD_SCK;
@ -145,6 +146,13 @@ extern const Gpio_Pin FILTER_S1;
extern const Gpio_Pin TRX_SWITCH;
extern const Gpio_Pin I2C_SCL;
extern const Gpio_Pin I2C_SDA;
extern const Gpio_Pin FLIP_FLOP_ENABLE;
extern const Gpio_Pin RED_LED;
// extern const Gpio_Pin NC_1;
// extern const Gpio_Pin DAC_SWITCHES;
// extern const Gpio_Pin GSM_PWRKEY;

10
Source/include/i2c.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef I2C_H_
#define I2C_H_
#include <hal.h>
//#include "stm32f4xx_hal_i2c.h"
#define SI5338_ADDRESS 0x70
I2C_HandleTypeDef handleI2C;
#endif /* DDS_H_ */

View File

@ -19,6 +19,7 @@
#endif
#include "stm32f4xx.h"
#include "stm32f4xx_hal_conf.h"
//#include "core_cmInstr.h"
#include <stdio.h>
#include "stddef.h"
@ -28,6 +29,7 @@
#include "dds.h"
#include "Timer.h"
#include "BlinkLed.h"
//#include "stm32f4xx_hal_rcc.h"
#include "stm32f4xx_hal_gpio.h"
#include "Adafruit_GFX.h"
@ -45,13 +47,14 @@
#include "stm32f4xx_hal_cortex.h"
#include "misc.h"
#include "stm32f4xx_hal_dac.h"
//#include "stm32f4xx_hal_i2c.h"
#include "images.h"
#include "stm32f4xx_hal_dma.h"
#include "stm32f4xx_hal_def.h"
//#include "stm32f4xx_hal_def.h"
#include "stm32f4xx_hal_uart.h"
#include "stm32f4xx_hal_usart.h"
#include "i2c.h"
TIM_HandleTypeDef TimHandle;

View File

@ -150,6 +150,8 @@ const Gpio_Pin PADDLE_THUMB_NC =
const Gpio_Pin PADDLE_INDEX_NC =
{ GPIOD, GPIO_PIN_6 }; //2.5
//const Gpio_Pin MIC_BUTTON = { GPIOD, GPIO_PIN_12 };;//FORGOT TO CONNECT IT TO THE MCU!
//const Gpio_Pin IN_AMP_ENABLE = { GPIO, GPIO_PIN_ }; //FORGOT TO CONNECT IT TO THE MCU!
@ -165,9 +167,9 @@ const Gpio_Pin PADDLE_INDEX_NC =
//const Gpio_Pin POWER_SWITCH = { GPIOC, GPIO_Pin_15 };
//const Gpio_Pin ACCEL_NSS = { GPIOD, GPIO_Pin_2 }; // currently labeled SPI2_NSS on schem
const Gpio_Pin GPS_RESET =
{ GPIOD, GPIO_PIN_15 }; //2.5
const Gpio_Pin GPS_FIX_LED =
{ GPIOE, GPIO_PIN_15 }; //2.5
//const Gpio_Pin GPS_FIX_LED =
// { GPIOE, GPIO_PIN_15 }; //2.5
const Gpio_Pin GPS_PPS =
{ GPIOE, GPIO_PIN_7 }; //2.5
const Gpio_Pin GPS_POWER =
@ -189,6 +191,17 @@ const Gpio_Pin FILTER_S1 =
const Gpio_Pin TRX_SWITCH =
{ GPIOC, GPIO_PIN_3 }; //2.5
const Gpio_Pin I2C_SCL =
{ GPIOB, GPIO_PIN_10 };
const Gpio_Pin I2C_SDA =
{ GPIOB, GPIO_PIN_11 };
const Gpio_Pin FLIP_FLOP_ENABLE =
{ GPIOE, GPIO_PIN_8 };
const Gpio_Pin RED_LED =
{ GPIOE, GPIO_PIN_13 };
//// timer pins
//const Timer_Pin LED_G =
//{
@ -662,6 +675,13 @@ hal_setupPins (void)
gpioInitStructure.Pull = GPIO_PULLUP;
HAL_GPIO_Init (PADDLE_INDEX_NO.port, &gpioInitStructure);
gpioInitStructure.Pin = RED_LED.pin;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init (RED_LED.port, &gpioInitStructure);
HAL_GPIO_WritePin(RED_LED.port, RED_LED.pin, 0);
// Power Switch
// gpioInitStructure.GPIO_Pin = POWER_SWITCH.pin;
// gpioInitStructure.GPIO_Speed = GPIO_Speed_2MHz;
@ -800,11 +820,11 @@ hal_setupPins (void)
HAL_GPIO_Init (GPS_RESET.port, &gpioInitStructure);
HAL_GPIO_WritePin (GPS_RESET.port, GPS_RESET.pin, 1);
gpioInitStructure.Pin = GPS_FIX_LED.pin;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Mode = GPIO_MODE_INPUT; //I don't know if the module has ANYTHING hooked up to these pins yet.
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init (GPS_FIX_LED.port, &gpioInitStructure);
// gpioInitStructure.Pin = GPS_FIX_LED.pin;
// gpioInitStructure.Speed = GPIO_SPEED_LOW;
// gpioInitStructure.Mode = GPIO_MODE_INPUT; //I don't know if the module has ANYTHING hooked up to these pins yet.
// gpioInitStructure.Pull = GPIO_NOPULL;
// HAL_GPIO_Init (GPS_FIX_LED.port, &gpioInitStructure);
gpioInitStructure.Pin = GPS_PPS.pin;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
@ -817,7 +837,7 @@ hal_setupPins (void)
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP; //I don't know if the module has ANYTHING hooked up to these pins yet.
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init (IN_AMP_ENABLE.port, &gpioInitStructure);
HAL_GPIO_WritePin (IN_AMP_ENABLE.port, IN_AMP_ENABLE.pin, 1);
HAL_GPIO_WritePin (IN_AMP_ENABLE.port, IN_AMP_ENABLE.pin, 1); //high is on
gpioInitStructure.Pin = FILTER_S0.pin;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
@ -839,6 +859,15 @@ hal_setupPins (void)
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init (TRX_SWITCH.port, &gpioInitStructure);
HAL_GPIO_WritePin (TRX_SWITCH.port, TRX_SWITCH.pin, 0);
//I2C Pins are declared elsewhere. (in the i2c.c file)
gpioInitStructure.Pin = FLIP_FLOP_ENABLE.pin;
gpioInitStructure.Speed = GPIO_SPEED_LOW;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_PP;
gpioInitStructure.Pull = GPIO_NOPULL;
HAL_GPIO_Init (FLIP_FLOP_ENABLE.port, &gpioInitStructure);
HAL_GPIO_WritePin (FLIP_FLOP_ENABLE.port, TRX_SWITCH.pin, 0);
}
//

777
Source/src/i2c.c Normal file
View File

@ -0,0 +1,777 @@
#include <i2c.h>
HAL_I2C_MspInit(I2C_HandleTypeDef hi2c)
{
//Ensure that appropriate GPIO and I2C hardware is powered up
//um, they are elsewhere. Good enough for now.
//handleI2C = &hi2c;
GPIO_InitTypeDef gpioInitStructure;
//Check for stuck SDA condition and attempt to clear it
// gpioInitStructure.Pin = I2C_SDA.pin;
// gpioInitStructure.Speed = GPIO_SPEED_FAST;
// gpioInitStructure.Mode = GPIO_MODE_OUTPUT_OD;
// gpioInitStructure.Pull = GPIO_PULLUP;
// gpioInitStructure.Alternate = 0;
// HAL_GPIO_Init (I2C_SDA.port, &gpioInitStructure);
//
//
// gpioInitStructure.Pin = I2C_SCL.pin;
// gpioInitStructure.Speed = GPIO_SPEED_FAST;
// gpioInitStructure.Mode = GPIO_MODE_OUTPUT_OD;
// gpioInitStructure.Pull = GPIO_PULLUP;
// gpioInitStructure.Alternate = 0;
// HAL_GPIO_Init (I2C_SCL.port, &gpioInitStructure);
//
//
//
// //Attempt to clear stuck SDA state (caused by poorly timed reset, for example)
// int retries = 0;
// //while((!HAL_GPIO_ReadPin(I2C_SDA.port, I2C_SDA.pin)) && retries < 100)
// while(retries < 10)
// {
// HAL_GPIO_WritePin(I2C_SCL.port, I2C_SCL.pin, 0);
// HAL_GPIO_WritePin(I2C_SCL.port, I2C_SCL.pin, 1);
// retries++;
// }
//
// HAL_GPIO_WritePin(I2C_SDA.port, I2C_SDA.pin, 1);
// HAL_GPIO_WritePin(I2C_SCL.port, I2C_SCL.pin, 0);
// HAL_GPIO_WritePin(I2C_SDA.port, I2C_SDA.pin, 0);
//THESE HAVE TO BE SET UP IN THIS ORDER!! If they are flipped, the BUSY flag will get flipped and never clear and you'll have a bad day.
gpioInitStructure.Pin = I2C_SCL.pin;
gpioInitStructure.Speed = GPIO_SPEED_FAST;
gpioInitStructure.Mode = GPIO_MODE_AF_OD;
gpioInitStructure.Pull = GPIO_PULLUP;
gpioInitStructure.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init (I2C_SCL.port, &gpioInitStructure);
gpioInitStructure.Pin = I2C_SDA.pin;
gpioInitStructure.Speed = GPIO_SPEED_FAST;
gpioInitStructure.Mode = GPIO_MODE_AF_OD;
gpioInitStructure.Pull = GPIO_PULLUP;
gpioInitStructure.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init (I2C_SDA.port, &gpioInitStructure);
// (*hi2c).Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
// (*hi2c).Init.ClockSpeed = I2C_
}
clearStuckBusyFlag()
{
//disable I2C peripheral
//__I2C2_CLK_DISABLE();
I2C2->CR1 &= 0b1111111111111110;
//set pins as OD high,
GPIO_InitTypeDef gpioInitStructure;
gpioInitStructure.Pin = I2C_SDA.pin;
gpioInitStructure.Speed = GPIO_SPEED_FAST;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_OD;
gpioInitStructure.Pull = GPIO_NOPULL;
gpioInitStructure.Alternate = 0;
HAL_GPIO_Init (I2C_SDA.port, &gpioInitStructure);
gpioInitStructure.Pin = I2C_SCL.pin;
gpioInitStructure.Speed = GPIO_SPEED_FAST;
gpioInitStructure.Mode = GPIO_MODE_OUTPUT_OD;
gpioInitStructure.Pull = GPIO_NOPULL;
gpioInitStructure.Alternate = 0;
HAL_GPIO_Init (I2C_SCL.port, &gpioInitStructure);
HAL_GPIO_WritePin(I2C_SCL.port, I2C_SCL.pin, 1);
HAL_GPIO_WritePin(I2C_SDA.port, I2C_SDA.pin, 1);
//set them low (and check them)
HAL_GPIO_WritePin(I2C_SCL.port, I2C_SCL.pin, 0);
HAL_GPIO_WritePin(I2C_SDA.port, I2C_SDA.pin, 0);
//set them high (and check them)
HAL_GPIO_WritePin(I2C_SCL.port, I2C_SCL.pin, 1);
HAL_GPIO_WritePin(I2C_SDA.port, I2C_SDA.pin, 1);
//return pins to AF configuration
gpioInitStructure.Pin = I2C_SDA.pin;
gpioInitStructure.Speed = GPIO_SPEED_FAST;
gpioInitStructure.Mode = GPIO_MODE_AF_OD;
gpioInitStructure.Pull = GPIO_PULLUP;
gpioInitStructure.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init (I2C_SDA.port, &gpioInitStructure);
gpioInitStructure.Pin = I2C_SCL.pin;
gpioInitStructure.Speed = GPIO_SPEED_FAST;
gpioInitStructure.Mode = GPIO_MODE_AF_OD;
gpioInitStructure.Pull = GPIO_PULLUP;
gpioInitStructure.Alternate = GPIO_AF4_I2C2;
HAL_GPIO_Init (I2C_SCL.port, &gpioInitStructure);
//set the reset bit in I2Cx_CR1 register then clear it
I2C2->CR1 |= 0b1000000000000000;
I2C2->CR1 &= 0b0111111111111111;
//turn I2C peripheral back on
//__I2C2_CLK_ENABLE();
I2C2->CR1 |= 0b0000000000000001;
}
#define NUM_REGS_MAX 350
#define SI5338_ADDRESS 0x70
#define LOCK_MASK 0x15
#define LOS_MASK 0x04
//typedef struct Reg_Data{
// unsigned unsigned char Reg_Addr;
// unsigned unsigned char Reg_Val;
// unsigned unsigned char Reg_Mask;
//} Reg_Data;
//Reg_Data const code Reg_Store[NUM_REGS_MAX] = {
unsigned char Reg_Store[][3] = {
{ 0,0x00,0x00},
{ 1,0x00,0x00},
{ 2,0x00,0x00},
{ 3,0x00,0x00},
{ 4,0x00,0x00},
{ 5,0x00,0x00},
{ 6,0x08,0x1D},
{ 7,0x00,0x00},
{ 8,0x70,0x00},
{ 9,0x0F,0x00},
{ 10,0x00,0x00},
{ 11,0x00,0x00},
{ 12,0x00,0x00},
{ 13,0x00,0x00},
{ 14,0x00,0x00},
{ 15,0x00,0x00},
{ 16,0x00,0x00},
{ 17,0x00,0x00},
{ 18,0x00,0x00},
{ 19,0x00,0x00},
{ 20,0x00,0x00},
{ 21,0x00,0x00},
{ 22,0x00,0x00},
{ 23,0x00,0x00},
{ 24,0x00,0x00},
{ 25,0x00,0x00},
{ 26,0x00,0x00},
{ 27,0x70,0x80},
{ 28,0x16,0xFF},
{ 29,0x90,0xFF},
{ 30,0xB0,0xFF},
{ 31,0xC0,0xFF},
{ 32,0xE3,0xFF},
{ 33,0xE3,0xFF},
{ 34,0xE3,0xFF},
{ 35,0x00,0xFF},
{ 36,0x06,0x1F},
{ 37,0x00,0x1F},
{ 38,0x00,0x1F},
{ 39,0x00,0x1F},
{ 40,0x63,0xFF},
{ 41,0x0C,0x7F},
{ 42,0x23,0x3F},
{ 43,0x00,0x00},
{ 44,0x00,0x00},
{ 45,0x00,0xFF},
{ 46,0x00,0xFF},
{ 47,0x14,0x3F},
{ 48,0x38,0xFF},
{ 49,0x00,0xFF},
{ 50,0xC4,0xFF},
{ 51,0x07,0xFF},
{ 52,0x10,0xFF},
{ 53,0x00,0xFF},
{ 54,0xB0,0xFF},
{ 55,0x00,0xFF},
{ 56,0x00,0xFF},
{ 57,0x00,0xFF},
{ 58,0x00,0xFF},
{ 59,0x01,0xFF},
{ 60,0x00,0xFF},
{ 61,0x00,0xFF},
{ 62,0x00,0x3F},
{ 63,0x10,0xFF},
{ 64,0x00,0xFF},
{ 65,0x00,0xFF},
{ 66,0x00,0xFF},
{ 67,0x00,0xFF},
{ 68,0x00,0xFF},
{ 69,0x00,0xFF},
{ 70,0x00,0xFF},
{ 71,0x00,0xFF},
{ 72,0x00,0xFF},
{ 73,0x00,0x3F},
{ 74,0x10,0xFF},
{ 75,0x00,0xFF},
{ 76,0x00,0xFF},
{ 77,0x00,0xFF},
{ 78,0x00,0xFF},
{ 79,0x00,0xFF},
{ 80,0x00,0xFF},
{ 81,0x00,0xFF},
{ 82,0x00,0xFF},
{ 83,0x00,0xFF},
{ 84,0x00,0x3F},
{ 85,0x10,0xFF},
{ 86,0x00,0xFF},
{ 87,0x00,0xFF},
{ 88,0x00,0xFF},
{ 89,0x00,0xFF},
{ 90,0x00,0xFF},
{ 91,0x00,0xFF},
{ 92,0x00,0xFF},
{ 93,0x00,0xFF},
{ 94,0x00,0xFF},
{ 95,0x00,0x3F},
{ 96,0x10,0x00},
{ 97,0x0F,0xFF},
{ 98,0x2E,0xFF},
{ 99,0x24,0xFF},
{100,0x00,0xFF},
{101,0x00,0xFF},
{102,0x00,0xFF},
{103,0x19,0xFF},
{104,0x00,0xFF},
{105,0x00,0xFF},
{106,0x80,0xBF},
{107,0x00,0xFF},
{108,0x00,0xFF},
{109,0x00,0xFF},
{110,0xC0,0xFF},
{111,0x00,0xFF},
{112,0x00,0xFF},
{113,0x00,0xFF},
{114,0x40,0xFF},
{115,0x00,0xFF},
{116,0x80,0xFF},
{117,0x00,0xFF},
{118,0x40,0xFF},
{119,0x00,0xFF},
{120,0x00,0xFF},
{121,0x00,0xFF},
{122,0x40,0xFF},
{123,0x00,0xFF},
{124,0x00,0xFF},
{125,0x00,0xFF},
{126,0x00,0xFF},
{127,0x00,0xFF},
{128,0x00,0xFF},
{129,0x00,0x0F},
{130,0x00,0x0F},
{131,0x00,0xFF},
{132,0x00,0xFF},
{133,0x00,0xFF},
{134,0x00,0xFF},
{135,0x00,0xFF},
{136,0x00,0xFF},
{137,0x00,0xFF},
{138,0x00,0xFF},
{139,0x00,0xFF},
{140,0x00,0xFF},
{141,0x00,0xFF},
{142,0x00,0xFF},
{143,0x00,0xFF},
{144,0x00,0xFF},
{145,0x00,0x00},
{146,0xFF,0x00},
{147,0x00,0x00},
{148,0x00,0x00},
{149,0x00,0x00},
{150,0x00,0x00},
{151,0x00,0x00},
{152,0x00,0xFF},
{153,0x00,0xFF},
{154,0x00,0xFF},
{155,0x00,0xFF},
{156,0x00,0xFF},
{157,0x00,0xFF},
{158,0x00,0x0F},
{159,0x00,0x0F},
{160,0x00,0xFF},
{161,0x00,0xFF},
{162,0x00,0xFF},
{163,0x00,0xFF},
{164,0x00,0xFF},
{165,0x00,0xFF},
{166,0x00,0xFF},
{167,0x00,0xFF},
{168,0x00,0xFF},
{169,0x00,0xFF},
{170,0x00,0xFF},
{171,0x00,0xFF},
{172,0x00,0xFF},
{173,0x00,0xFF},
{174,0x00,0xFF},
{175,0x00,0xFF},
{176,0x00,0xFF},
{177,0x00,0xFF},
{178,0x00,0xFF},
{179,0x00,0xFF},
{180,0x00,0xFF},
{181,0x00,0x0F},
{182,0x00,0xFF},
{183,0x00,0xFF},
{184,0x00,0xFF},
{185,0x00,0xFF},
{186,0x00,0xFF},
{187,0x00,0xFF},
{188,0x00,0xFF},
{189,0x00,0xFF},
{190,0x00,0xFF},
{191,0x00,0xFF},
{192,0x00,0xFF},
{193,0x00,0xFF},
{194,0x00,0xFF},
{195,0x00,0xFF},
{196,0x00,0xFF},
{197,0x00,0xFF},
{198,0x00,0xFF},
{199,0x00,0xFF},
{200,0x00,0xFF},
{201,0x00,0xFF},
{202,0x00,0xFF},
{203,0x00,0x0F},
{204,0x00,0xFF},
{205,0x00,0xFF},
{206,0x00,0xFF},
{207,0x00,0xFF},
{208,0x00,0xFF},
{209,0x00,0xFF},
{210,0x00,0xFF},
{211,0x00,0xFF},
{212,0x00,0xFF},
{213,0x00,0xFF},
{214,0x00,0xFF},
{215,0x00,0xFF},
{216,0x00,0xFF},
{217,0x00,0xFF},
{218,0x00,0x00},
{219,0x00,0x00},
{220,0x00,0x00},
{221,0x0D,0x00},
{222,0x00,0x00},
{223,0x00,0x00},
{224,0xF4,0x00},
{225,0xF0,0x00},
{226,0x00,0x00},
{227,0x00,0x00},
{228,0x00,0x00},
{229,0x00,0x00},
{231,0x00,0x00},
{232,0x00,0x00},
{233,0x00,0x00},
{234,0x00,0x00},
{235,0x00,0x00},
{236,0x00,0x00},
{237,0x00,0x00},
{238,0x14,0x00},
{239,0x00,0x00},
{240,0x00,0x00},
{242,0x00,0x02},
{243,0xF0,0x00},
{244,0x00,0x00},
{245,0x00,0x00},
{247,0x00,0x00},
{248,0x00,0x00},
{249,0xA8,0x00},
{250,0x00,0x00},
{251,0x84,0x00},
{252,0x00,0x00},
{253,0x00,0x00},
{254,0x00,0x00},
{255, 1, 0xFF}, // set page bit to 1
{ 0,0x00,0x00},
{ 1,0x00,0x00},
{ 2,0x00,0x00},
{ 3,0x00,0x00},
{ 4,0x00,0x00},
{ 5,0x00,0x00},
{ 6,0x00,0x00},
{ 7,0x00,0x00},
{ 8,0x00,0x00},
{ 9,0x00,0x00},
{ 10,0x00,0x00},
{ 11,0x00,0x00},
{ 12,0x00,0x00},
{ 13,0x00,0x00},
{ 14,0x00,0x00},
{ 15,0x00,0x00},
{ 16,0x00,0x00},
{ 17,0x01,0x00},
{ 18,0x00,0x00},
{ 19,0x00,0x00},
{ 20,0x90,0x00},
{ 21,0x31,0x00},
{ 22,0x00,0x00},
{ 23,0x00,0x00},
{ 24,0x01,0x00},
{ 25,0x00,0x00},
{ 26,0x00,0x00},
{ 27,0x00,0x00},
{ 28,0x00,0x00},
{ 29,0x00,0x00},
{ 30,0x00,0x00},
{ 31,0x00,0xFF},
{ 32,0x00,0xFF},
{ 33,0x01,0xFF},
{ 34,0x00,0xFF},
{ 35,0x00,0xFF},
{ 36,0x90,0xFF},
{ 37,0x31,0xFF},
{ 38,0x00,0xFF},
{ 39,0x00,0xFF},
{ 40,0x01,0xFF},
{ 41,0x00,0xFF},
{ 42,0x00,0xFF},
{ 43,0x00,0x0F},
{ 44,0x00,0x00},
{ 45,0x00,0x00},
{ 46,0x00,0x00},
{ 47,0x00,0xFF},
{ 48,0x00,0xFF},
{ 49,0x01,0xFF},
{ 50,0x00,0xFF},
{ 51,0x00,0xFF},
{ 52,0x90,0xFF},
{ 53,0x31,0xFF},
{ 54,0x00,0xFF},
{ 55,0x00,0xFF},
{ 56,0x01,0xFF},
{ 57,0x00,0xFF},
{ 58,0x00,0xFF},
{ 59,0x00,0x0F},
{ 60,0x00,0x00},
{ 61,0x00,0x00},
{ 62,0x00,0x00},
{ 63,0x00,0xFF},
{ 64,0x00,0xFF},
{ 65,0x01,0xFF},
{ 66,0x00,0xFF},
{ 67,0x00,0xFF},
{ 68,0x90,0xFF},
{ 69,0x31,0xFF},
{ 70,0x00,0xFF},
{ 71,0x00,0xFF},
{ 72,0x01,0xFF},
{ 73,0x00,0xFF},
{ 74,0x00,0xFF},
{ 75,0x00,0x0F},
{ 76,0x00,0x00},
{ 77,0x00,0x00},
{ 78,0x00,0x00},
{ 79,0x00,0xFF},
{ 80,0x00,0xFF},
{ 81,0x00,0xFF},
{ 82,0x00,0xFF},
{ 83,0x00,0xFF},
{ 84,0x90,0xFF},
{ 85,0x31,0xFF},
{ 86,0x00,0xFF},
{ 87,0x00,0xFF},
{ 88,0x01,0xFF},
{ 89,0x00,0xFF},
{ 90,0x00,0xFF},
{ 91,0x00,0x0F},
{ 92,0x00,0x00},
{ 93,0x00,0x00},
{ 94,0x00,0x00},
{255, 0, 0xFF} }; // set page bit to 0
unsigned char hello = 1;
void write_Si5338(unsigned char address, unsigned char value)
{
unsigned char txBuf[2];
txBuf[0] = address;
txBuf[1] = value;
HAL_I2C_Master_Transmit(&handleI2C, 0xE0, &txBuf, 2, 100);
//HAL_I2C_Mem_Write(&handleI2C, 0xE0, address, 1, value, 1, 100);
// Wire.beginTransmission(SI5338_ADDRESS);
// Wire.write(address);
// //delay(10);
// Wire.write(value);
// Wire.endTransmission();
// delay(10);
// Serial.print(address, DEC);
// Serial.print(" w ");
// Serial.print(value, DEC);
// Serial.print("\r\n");
}
#define MULTISYNTH0 53
void writeMultiSynthParameters(int multisynth, unsigned long a, unsigned long b, unsigned long c)
{
unsigned long long msx_p1 = ((a * c + b) * 128) / c - 512;
unsigned long long msx_p2 = (b * 128) % c;
unsigned long long msx_p3 = c;
write_Si5338(multisynth, ( msx_p1 & 0xFF));
write_Si5338(multisynth + 1, ( msx_p1 >> 8) & 0xFF);
write_Si5338(multisynth + 2, (( msx_p1 >> 16) & 0b00000011) + (( msx_p2 << 2 ) & 0b11111100));
write_Si5338(multisynth + 3, ( msx_p2 >> 6 ) & 0xFF);
write_Si5338(multisynth + 4, ( msx_p2 >> 14 ) & 0xFF);
write_Si5338(multisynth + 5, ( msx_p2 >> 22 ) & 0xFF);
write_Si5338(multisynth + 6, ( msx_p3 & 0xFF));
write_Si5338(multisynth + 7, ( msx_p3 >> 8) & 0xFF);
write_Si5338(multisynth + 8, ( msx_p3 >> 16) & 0xFF);
write_Si5338(multisynth + 9, ( msx_p3 >> 24) & 0b00111111);
}
unsigned char read_Si5338(unsigned char address, int increment)
{
unsigned char retVal = 0;
HAL_I2C_Master_Transmit(&handleI2C, 0xE0, &address, 1, 100);
HAL_I2C_Master_Receive(&handleI2C, 0xE0, &retVal, 1, 100);
// Wire.beginTransmission(SI5338_ADDRESS);
// //Wire.write(0x00);
// Wire.write(address);
// Wire.endTransmission();
//
// //delay(2);
// Wire.beginTransmission(SI5338_ADDRESS);
// Wire.requestFrom(SI5338_ADDRESS,1);
//
// while(Wire.available())
// {
// retVal = Wire.read();
// delay(10);
// Serial.print(address, DEC);
// Serial.print(" r ");
// Serial.print(retVal, DEC);
// Serial.print(" - ");
// Serial.print(Reg_Store[increment][1], DEC);
// Serial.print("\r\n");
// }
return retVal;
}
//add, val, mask
void sendRegToSi5338(int increment)
{
unsigned char addr = Reg_Store[increment][0];
unsigned char data = Reg_Store[increment][1];
unsigned char mask = Reg_Store[increment][2];
// ignore registers with masks of 0x00
if(mask != 0x00){
if(mask == 0xFF){
// do a regular I2C write to the register
// at addr with the desired data value
write_Si5338(addr, data);
} else {
// do a read-modify-write using I2C and
// bit-wise operations
// get the current value from the device at the
// register located at addr
unsigned char curr_val = read_Si5338(addr, increment);
// clear the bits that are allowed to be
// accessed in the current value of the register
unsigned char clear_curr_val = curr_val & (~ mask);
// clear the bits in the desired data that
// are not allowed to be accessed
unsigned char clear_new_val = data & mask;
// combine the cleared values to get the new
// value to write to the desired register
unsigned char combined = clear_curr_val | clear_new_val;
write_Si5338(addr, combined);
}
} else {
//Serial.println("skip");
}
}
void i2cSetup() {
// put your setup code here, to run once:
//pinMode(A3, INPUT);
//digitalWrite(A3, LOW);
//Serial.begin(115200);
//Serial.write("\n\r\n\rHi Michael, you can do this\n\r");
//Wire.begin();
//delay(50);
////This part is working correctly!
// for(int i = 0; i < NUM_REGS_MAX; i++)
// {
// Serial.println(Reg_Store[i][1], HEX);
// }
//Serial.println("and now this part");
//Serial.println("and now THIS part");
//delay(2000);
//write_Si5338(230, 1 << 4);
//write_Si5338(241, 1 << 7);
write_Si5338(230, 0x10); //OEB_ALL = 1
write_Si5338(241, 0xE5); //DIS_LOL = 1
//delay(100);
for(int i = 0; i < NUM_REGS_MAX; i++)
{
sendRegToSi5338(i);
}
//for(int counter=0; counter<NUM_REGS_MAX; counter++){
//unsigned char curr = Reg_Store[counter];
//if(curr.Reg_Mask != 0x00) {
// if(curr.Reg_Mask == 0xFF) {
// // do a write transaction only
// // since the mask is all ones
// I2C_ByteWrite(curr.Reg_Addr, curr.Reg_Val);
// } else {
// //do a read-modify-write
// curr_chip_val = I2C_ByteRead(curr.Reg_Addr);
// clear_curr_val = curr_chip_val & ~curr.Reg_Mask;
// clear_new_val = curr.Reg_Val & curr.Reg_Mask;
// combined = clear_new_val | clear_curr_val;
// I2C_ByteWrite(curr.Reg_Addr, combined);
// }
// }
//}
// write_Si5338(49, 0 << 7);
// write_Si5338(246, 1 << 1);
// delay(30);
// write_Si5338(241, 0 << 7);
// //skipped some steps
//
// write_Si5338(230, 0 << 4);
// check LOS alarm for the xtal input
// on IN1 and IN2 (and IN3 if necessary) -
// change this mask if using inputs on IN4, IN5, IN6
unsigned char reg = read_Si5338(218,1) & LOS_MASK;
while(reg != 0){
reg = read_Si5338(218, 1) & LOS_MASK;
}
//delay(100);
write_Si5338(49, read_Si5338(49,1) & 0x7F); //FCAL_OVRD_EN = 0
write_Si5338(246, 2); //soft reset
write_Si5338(241, 0x65); //DIS_LOL = 0
// wait for Si5338 to be ready after calibration (ie, soft reset)
//delay(50);
//make sure the device locked by checking PLL_LOL and SYS_CAL
reg = read_Si5338(218,1) & LOCK_MASK;
while(reg != 0){
reg = read_Si5338(218,1) & LOCK_MASK;
}
//delay(100);
//copy FCAL values
write_Si5338(45, read_Si5338(235,1));
write_Si5338(46, read_Si5338(236,1));
// clear bits 0 and 1 from 47 and
// combine with bits 0 and 1 from 237
reg = (read_Si5338(47,1) & 0xFC) | (read_Si5338(237,1) & 3);
write_Si5338(47, reg);
write_Si5338(49, read_Si5338(49,1) | 0x80); // FCAL_OVRD_EN = 1
write_Si5338(230, 0x00); // OEB_ALL = 0
//Serial.println("and that's it");
// for(int i = 0; i < NUM_REGS_MAX; i++)
// {
// read_Si5338(i, i);
//
// }
//while(1);
}
void i2cLoop() {
// put your main code here, to run repeatedly:
//delay(400);
//write_Si5338(31, 0xC1); //output driver off?
//long integer = 8;
//long neumerator = 0;
//do
//{
//
// writeMultiSynthParameters(MULTISYNTH0, integer, neumerator, 10000UL);
// //neumerator += 1000;
// //if(neumerator > 9999)
// //{
// // neumerator = 0;
// integer++;
//
// //}
// if( integer >= 500) integer = 8;
//
//} while (true);
long integer = 199;
long neumerator = 0;
//do
//{
writeMultiSynthParameters(MULTISYNTH0, integer, neumerator, 10000UL);
//neumerator += 1000;
//if(neumerator > 9999)
//{
// neumerator = 0;
// integer++;
//}
//if( integer >= 500) integer = 8;
//neumerator = (analogRead(A3) * 10); //578914 referal nu 801 435 7764 john thank you
//integer = (analogRead(A2) /10) + 150;
//
//} while (true);
write_Si5338(31, 0xC0); //output driver off?
//delay(400);
write_Si5338(31, 0xC1); //output driver off?
writeMultiSynthParameters(MULTISYNTH0, 397, 0, 10000UL);
write_Si5338(31, 0xC0); //output driver off?
}

View File

@ -270,6 +270,7 @@ void setupPeripheralPower()
__GPIOE_CLK_ENABLE();
__DMA1_CLK_ENABLE();
__DMA2_CLK_ENABLE();
__I2C2_CLK_ENABLE();
}
void configDMA(SPI_HandleTypeDef *hspi)
@ -795,6 +796,58 @@ main(int argc, char* argv[])
configDMA(&SpiHandle );
//I2C_HandleTypeDef hi2c;
//HAL_I2C_MspInit(&hi2c);
//__HAL_I2C_DISABLE(I2C2);
clearStuckBusyFlag();
handleI2C.Instance = I2C2;
HAL_I2C_DeInit(&handleI2C);
handleI2C.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
handleI2C.Init.ClockSpeed = 400000;
handleI2C.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
handleI2C.Init.DutyCycle = I2C_DUTYCYCLE_16_9;
handleI2C.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
handleI2C.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
handleI2C.Init.OwnAddress1 = 0x30F;
handleI2C.Init.OwnAddress2 = 0xFE;
if(HAL_I2C_Init(&handleI2C) != HAL_OK)
{
trace_puts("I2C didn't Init correctly");
}
//handleI2C.Instance->SR2 = 0; //What the heck is wrong with this thing?!
//clearStuckBusyFlag();
HAL_StatusTypeDef result = HAL_ERROR;
while(result!= HAL_OK)
result = HAL_I2C_IsDeviceReady(&handleI2C, (0x70 << 1), 100, 100); //We need to shift the address to the left for it to work (because of the R/W bit)
//HAL_I2C_Master_Transmit(&hi2c, 230, 0x10, 1, 1000); //write_Si5338(230, 0x10); //OEB_ALL = 1
//*handleI2C = hi2c;
//HAL_I2C_Master_Transmit(&handleI2C, 230, 0x4F, 1, 1000); //write_Si5338(230, 0x10); //OEB_ALL = 1
//HAL_I2C_Master_Transmit(handleI2C, 230, 0x4F, 1, 1000); //write_Si5338(230, 0x10); //OEB_ALL = 1
//handleI2C = &hi2c;
//HAL_I2C_Master_Transmit(&handleI2C, 230, 0x4F, 1, 1000); //write_Si5338(230, 0x10); //OEB_ALL = 1
//HAL_I2C_Master_Transmit(handleI2C, 230, 0x4F, 1, 1000); //write_Si5338(230, 0x10); //OEB_ALL = 1
i2cSetup();
i2cLoop();
//trace_puts(( == HAL_OK ? "SI5338 Ready" : "SI5338 Not ready"));
//HAL_I2C_MspInit(&hi2c);
timer_start();
blink_led_init();
@ -829,7 +882,7 @@ main(int argc, char* argv[])
setGainPot(128, 128);
setGainPot(255, 255);
//testing Uart
configUartPeripheral();
@ -873,6 +926,8 @@ main(int argc, char* argv[])
Adafruit_GFX_fillRect(310, 8, 3, 3, HAL_GPIO_ReadPin(PADDLE_THUMB_NO.port, PADDLE_THUMB_NO.pin) ? ILI9340_RED : ILI9340_BLUE);
Adafruit_GFX_fillRect(310, 12, 3, 3, HAL_GPIO_ReadPin(PADDLE_INDEX_NO.port, PADDLE_INDEX_NO.pin) ? ILI9340_RED : ILI9340_BLUE);
HAL_GPIO_WritePin(RED_LED.port, RED_LED.pin, HAL_GPIO_ReadPin(GPS_PPS.port, GPS_PPS.pin));
if(!HAL_GPIO_ReadPin(PADDLE_THUMB_NO.port, PADDLE_THUMB_NO.pin))
//if(1) //I am locking it in transmit for some testing.
{