详解si5338 si53xx 设计使用及STM32 iic驱动设计

背景

在实际项目中经常使用si5338 si53xx,进行多路时钟的倍频以生成想要的时钟信号,但是针对si5338 si53xx设计使用缺少相关的资料,本文详解si5338 si53xx 设计使用及STM32 iic驱动设计,本文使用工程在项目中得到测试,在多个项目中同时使用。这里做个详解,加速今后的项目开发。本文使用的资源如下图所示

ClockBuilderPro_project------------>> 使用ClockBuilder Pro生成的工程,及配置头文件

ClockBuilder-Pro-Installer.zip------->>ClockBuilder Pro安装文件

si5338.rar------------------------>>stm32cubeide代码工程

详解si5338 si53xx 设计使用及STM32 iic驱动设计.pdf----->>使用说明文档

详解si5338si53xx设计使用及STM32iic驱动设计全套资料原理图代码使用手册ClockBuilder设计工程资源-CSDN文库

硬件设计

这里还是先要把硬件原理图给出来,因为后面si5338 si53xx,都需要根据原理图进行参数的配置,这里可以看出输入时钟25Mhz,支持四路时钟输出,I2C_LSB管脚接地,电压电压1.8v。

连接STM32F407如下表所示:

Label

Si5338A

STM32F407

备注

STM32_1V8_I2C2_SCL

SCL

PF1

STM32_1V8_I2C2_SCL电平转3.3v后连接PF1

STM32_1V8_I2C2_SDA

SDA

PF0

STM32_1V8_I2C2_SDA电平转3.3v后连接PF0

使用ClockBuilder Pro生成寄存器配置列表

安装ClockBuilder Pro

si5338 si53xx的寄存器配置需要采用官方提供的ClockBuilder Pro,下面详述步骤,首先安装ClockBuilder Pro,如下图所示:

解压ClockBuilder-Pro-Installer.zip

双击ClockBuilder-Pro-2.45.exe,都选择默认配置,即可完成软件安装

ClockBuilder Pro有更新的版本了,这里采用ClockBuilder-Pro-2.45,读者也可以去下载最新的版本使用,基本上步骤都是一样的。

新建工程

 

输入时钟配置 

输出时钟配置

导出配置寄存器文件 

选择C头文件的格式,记得这里生成的头文件,可以直接复制到软件设计中提供侧工程,头文件。 

完成配置头文件导出

配置文件内容复制到工程

复制Si5338-RevB-Registers.h文件内容,替换如下工程中register_map.h中所有内容,编译工程即可。

软件设计

软件采用stm32cubeide,配置,使用串口1作为调试串口,波特率配置9600,参考代码

/* USER CODE BEGIN PV */

#ifdef __GNUC__
#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
#define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif

PUTCHAR_PROTOTYPE
{

	while((USART1->SR&0x40)==0){};
		USART1->DR = ch;

    return ch;
}
/* USER CODE END PV */

 时钟采用8Mhz外部时钟倍频

仿真器采用sw接口

配置GPIO PF0 PF1为默认输出

 采用IO模拟IIC读写si53xx数据,参考代码

static void si5338_configure(void)
{
	uint32_t counter, timeout = 100;
   	uint8_t curr_chip_val, clear_curr_val, clear_new_val, combined, reg;
   	Reg_Data curr;
	//----------------------------------------------------------------
	// See Si5338 datasheet Figure 9 for more details on this procedure
	
	// delay added to wait for Si5338 to be ready to communicate 
	// after turning on
	///counter = 0;
	///while(counter < SI5338_DELAY) { counter++; }

	I2C_ByteWrite(230, 0x10);                   //OEB_ALL = 1
	I2C_ByteWrite(241, 0xE5);                   //DIS_LOL = 1

	//for all the register values in the Reg_Store array
	//get each value and mask and apply it to the Si5338
	for(counter=0; counter<NUM_REGS_MAX; counter++){
			
		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);
			}
		}
	}

	// 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
	reg = I2C_ByteRead(218) & LOS_MASK;
	while(reg != 0){
		reg = I2C_ByteRead(218) & LOS_MASK;
		timeout --;
		//osDelay(1);
		delay_ms(1);
		if(timeout == 0){
			printf("si5338_configure timeout1\n");
			break;
		}					
	}

	I2C_ByteWrite(49, I2C_ByteRead(49) & 0x7F); //FCAL_OVRD_EN = 0
	I2C_ByteWrite(246, 2);                      //soft reset
	I2C_ByteWrite(241, 0x65);                   //DIS_LOL = 0

	// wait for Si5338 to be ready after calibration (ie, soft reset)
	///counter = 0;
	///while(counter < SI5338_DELAY) { counter++; }
	///counter = 0;
	///while(counter < SI5338_DELAY) { counter++; }
	//osDelay(24);
	delay_ms(24);

	//make sure the device locked by checking PLL_LOL and SYS_CAL
	timeout = 100;
	reg = I2C_ByteRead(218) & LOCK_MASK;
	while(reg != 0){
		reg = I2C_ByteRead(218) & LOCK_MASK;
		timeout --;
		//msleep(1);
		if(timeout == 0){
			printf("si5338_configure timeout2\n");
			break;
		}				
	}

	//copy FCAL values
	I2C_ByteWrite(45, I2C_ByteRead(235));
	I2C_ByteWrite(46, I2C_ByteRead(236));
	// clear bits 0 and 1 from 47 and 
	// combine with bits 0 and 1 from 237
	reg = (I2C_ByteRead(47) & 0xFC) | (I2C_ByteRead(237) & 3);
	I2C_ByteWrite(47, reg);

	I2C_ByteWrite(49, I2C_ByteRead(49) | 0x80); // FCAL_OVRD_EN = 1
	I2C_ByteWrite(230, 0x00);                   // OEB_ALL = 0

	printf("si5338_configure success!\n");
	//------------------------------------------------------------


}

测试记录

能够正确配置si5338,串口1,log打印如下图所示

使用工程及其他资料如下:

ClockBuilderPro_project------------>> 使用ClockBuilder Pro生成的工程,及配置头文件

ClockBuilder-Pro-Installer.zip------->>ClockBuilder Pro安装文件

si5338.rar------------------------>>stm32cubeide代码工程

详解si5338 si53xx 设计使用及STM32 iic驱动设计.pdf----->>使用说明文档

详解si5338si53xx设计使用及STM32iic驱动设计全套资料原理图代码使用手册ClockBuilder设计工程资源-CSDN文库

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

大牛攻城狮

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值