Changeset - 0dd5c923fdea
[Not reviewed]
default
0 5 0
Ethan Zonca - 10 years ago 2016-01-19 22:08:19
ez@ethanzonca.com
i2c comms still not working
5 files changed with 34 insertions and 11 deletions:
0 comments (0 inline, 0 general)
inc/gpio.h
Show inline comments
 
@@ -11,16 +11,17 @@
 
#define VBATT_SENSE_Pin GPIO_PIN_6
 
#define VBATT_SENSE_GPIO_Port GPIOA
 
 
#define LED_BLUE_Pin GPIO_PIN_0
 
#define LED_BLUE_GPIO_Port GPIOB
 
#define LED_BLUE LED_BLUE_GPIO_Port , LED_BLUE_Pin
 
 
#define TCXO_EN_Pin GPIO_PIN_8
 
#define TCXO_EN_GPIO_Port GPIOA
 
#define TCXO_EN TCXO_EN_GPIO_Port  , TCXO_EN_Pin
 
 
 
void MX_GPIO_Init(void);
 
void gpio_init(void);
 
void led_blink(uint8_t n);
 
 
#endif 
 
lib/si5351/si5351.c
Show inline comments
 
@@ -16,24 +16,26 @@
 
 * This program is distributed in the hope that it will be useful,
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
 * GNU General Public License for more details.
 
 *
 
 * You should have received a copy of the GNU General Public License
 
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 */
 

	
 
#include <stdint.h>
 
#include "stm32f0xx_hal.h"
 
#include "si5351.h"
 
#include "gpio.h"
 

	
 

	
 
// Private prototypes
 
uint64_t si5351_pll_calc(uint64_t, struct Si5351RegSet *, int32_t);
 
uint64_t si5351_multisynth_calc(uint64_t, uint64_t, struct Si5351RegSet *);
 
void si5351_update_sys_status(struct Si5351Status *);
 
void si5351_update_int_status(struct Si5351IntStatus *);
 
void si5351_ms_div(enum si5351_clock, uint8_t, uint8_t);
 
uint8_t si5351_select_r_div(uint64_t *);
 

	
 
// Globals
 
int32_t ref_correction;
 
uint8_t lock_plla, lock_pllb;
 
@@ -900,57 +902,67 @@ void si5351_set_clock_fanout(enum si5351
 
	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_I2C_Mem_Write(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data, bytes, 100);
 
    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};
 
    HAL_I2C_Mem_Write(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data, 1, 100);
 
    uint8_t res = HAL_I2C_Mem_Write(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data, 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_I2C_Mem_Read(si5351_i2cport, SI5351_BUS_BASE_ADDR, addr, 1, data_arr, 1, 100);
 
    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();
 
	}
 
*/	
src/gpio.c
Show inline comments
 
#include "gpio.h"
 
 
void MX_GPIO_Init(void)
 
void gpio_init(void)
 
{
 
 
  GPIO_InitTypeDef GPIO_InitStruct;
 
 
  /* GPIO Ports Clock Enable */
 
  __GPIOF_CLK_ENABLE();
 
  __GPIOA_CLK_ENABLE();
 
  __GPIOB_CLK_ENABLE();
 
 
  /*Configure GPIO pins : PFPin PFPin */
 
  GPIO_InitStruct.Pin = OSC_EN_Pin;
 
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
@@ -44,12 +44,22 @@ void MX_GPIO_Init(void)
 
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 
  HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
 
 
  /*Configure GPIO pin : PtPin */
 
  GPIO_InitStruct.Pin = TCXO_EN_Pin;
 
  GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
 
  GPIO_InitStruct.Pull = GPIO_NOPULL;
 
  GPIO_InitStruct.Speed = GPIO_SPEED_LOW;
 
  HAL_GPIO_Init(TCXO_EN_GPIO_Port, &GPIO_InitStruct);
 
 
}
 
 
void led_blink(uint8_t n)
 
{
 
    for(int i = 0; i < n; i++)
 
    {
 
        HAL_GPIO_WritePin(LED_BLUE, 1);
 
        HAL_Delay(100);
 
        HAL_GPIO_WritePin(LED_BLUE, 0);
 
        HAL_Delay(100);
 
    }
 
}
src/i2c.c
Show inline comments
 
//
 
// I2C: Initialize I2C peripheral and return a reference to the port
 
//
 
 
#include "i2c.h"
 
#include "gpio.h"
 
 
I2C_HandleTypeDef hi2c1;
 
 
void i2c_init(void)
 
{
 
    __GPIOA_CLK_ENABLE();
 
 
    GPIO_InitTypeDef GPIO_InitStruct;
 
    GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;
 
    GPIO_InitStruct.Mode = GPIO_MODE_AF_OD;
 
    GPIO_InitStruct.Pull = GPIO_PULLUP;
 
    GPIO_InitStruct.Pull = GPIO_NOPULL;
 
    GPIO_InitStruct.Speed = GPIO_SPEED_HIGH;
 
    GPIO_InitStruct.Alternate = GPIO_AF4_I2C1;
 
    HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
 
 
    __I2C1_CLK_ENABLE();
 
 
    hi2c1.Instance = I2C1;
 
    hi2c1.Init.Timing = 0x2000090E;
 
    hi2c1.Init.OwnAddress1 = 0;
 
    hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
 
    hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLED;
 
    hi2c1.Init.OwnAddress2 = 0;
 
    hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
 
    hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLED;
 
    hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLED;
 
    HAL_I2C_Init(&hi2c1);
 
 
    HAL_I2CEx_AnalogFilter_Config(&hi2c1, I2C_ANALOGFILTER_ENABLED);
 
}
 
 
 
// Get pointer to I2C port
 
inline I2C_HandleTypeDef* i2c_get(void)
 
I2C_HandleTypeDef* i2c_get(void)
 
{
 
    return &hi2c1;
 
}
src/main.c
Show inline comments
 
@@ -10,40 +10,39 @@
 
 
 
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();
 
    MX_GPIO_Init();
 
    gpio_init();
 
    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_set_pll(SI5351_PLL_FIXED, SI5351_PLLA);
 
    si5351_set_ms_source(SI5351_CLK0, SI5351_PLLA);
 
 
    si5351_set_freq(100000UL * 100, 0, SI5351_CLK0);
 
 
    si5351_drive_strength(SI5351_CLK0, SI5351_DRIVE_2MA); // Set for max power if desired (8ma max)
 
@@ -94,15 +93,14 @@ void sysclk_init(void)
 
 
    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);
 
 
}
 
0 comments (0 inline, 0 general)