Portapack应用开发教程 (十六) Debug程序 D si5351芯片和iic实现

本文详细解读了hackrf板子上采用i2c接口的Si5351时钟芯片,介绍了其初始化、配置和通信原理,通过对比与portapack板子声卡芯片的区别,展示了芯片的I2C接口使用和i2c_pp库的实现。

前面一篇文章把portapack板子上的两颗iic的声卡芯片讲完了,接下来我想不要直接去看hackrf板子上的spi总线的芯片,而是讲另一个芯片si5351。

这颗si5351芯片是时钟芯片(由800MHz分频提供40MHz 50MHz 及采样时钟),它是iic接口,但是它是在hackrf板子上的。相当于是portapack板子上的iic声卡芯片与hackrf板子上的spi芯片之间的过渡。

代码位置在/firmware/application/hw/si5351.cpp和si5351.hpp

先观察si5351.hpp

#include "i2c_pp.hpp"

class Si5351 {

	constexpr Si5351(I2C& bus, I2C::address_t address) :
		_clock_control({
			ClockControl::power_off(), ClockControl::power_off(),
			ClockControl::power_off(), ClockControl::power_off(),
			ClockControl::power_off(), ClockControl::power_off(),
			ClockControl::power_off(), ClockControl::power_off()
		}),
		_bus(bus),
		_address(address),
		_output_enable(0x00)
	{
	}

}

上面是我摘录的类声明和构建函数,从参数里的I2C和I2C::address_t可以看出,显然这个芯片还是在用iic接口,这和声卡芯片是一样的,只是address值不同。 

这个address与声卡芯片类似是在firmware/application/portapack.cpp里指定的并做了初始化的。

si5351::Si5351 clock_generator {
	i2c0, 
/******************************************** 主控芯片:STM32F405RGT6主频168Mhz 晶体频率:HSE=8Mhz SYSCLK=168Mhz 模块型号:SI5351A 通讯方式: 函数功能:Si5351时钟芯片 作者:苏夏雨 授权:未经作者允许,禁止转载 ********************************************/ #ifndef _si5351a_h #define _si5351a_h #include "system.h" //Si5351寄存器声明 #define SI_CLK0_CONTROL 16 // Register definitions #define SI_CLK1_CONTROL 17 #define SI_CLK2_CONTROL 18 #define SI_SYNTH_PLL_A 26 #define SI_SYNTH_PLL_B 34 #define SI_SYNTH_MS_0 42 #define SI_SYNTH_MS_1 50 #define SI_SYNTH_MS_2 58 #define SI_PLL_RESET 177 #define SI_R_DIV_1 0x00 // R-division ratio definitions #define SI_R_DIV_2 0b00010000 #define SI_R_DIV_4 0b00100000 #define SI_R_DIV_8 0b00110000 #define SI_R_DIV_16 0b01000000 #define SI_R_DIV_32 0b01010000 #define SI_R_DIV_64 0b01100000 #define SI_R_DIV_128 0b01110000 #define SI_CLK_SRC_PLL_A 0x00 #define SI_CLK_SRC_PLL_B 0b00100000 #define XTAL_FREQ 25000000 // Crystal frequency //IIC总线引脚配置 #define SDA(n) {n?HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10,GPIO_PIN_RESET);} #define CLK(n) {n?HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_SET):HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11,GPIO_PIN_RESET);} //相关函数声明 void Si5351Init(void);//初始化Si5351的GPIO void SetPLLClk(uint8_t pll, uint8_t mult, uint32_t num, uint32_t denom);//设置PPL时钟 void SetFrequency(uint32_t frequency);//时钟Si5351时钟频率 void SetMultisynth(uint8_t synth,uint32_t divider,uint8_t rDiv);//设置多synth #endif
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值