详解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,参考代码

cpp 复制代码
/* 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数据,参考代码

cpp 复制代码
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文库

相关推荐
洪核单片机14 小时前
DPJ-96基于STM32单片机wifi远程监控智慧教室 温湿度光照粉尘人数考勤
stm32·单片机·嵌入式硬件·智慧教室·教室人数考勤
云泽80817 小时前
STM32 USART 详解(八):C I/O 串口重定向原理与实现
c语言·stm32·嵌入式硬件
星栖与芯21 小时前
LiteOS-M 切换汇编逐行图解(1):汇编是什么·寄存器与栈
汇编·stm32·嵌入式硬件·harmonyos·鸿蒙系统
Zw-awa1 天前
重新认识结构体:为什么 STM32 库函数喜欢接收一大包参数
stm32
单片机仿真设计1 天前
【proteus仿真】基于 STM32 单片机太阳能双轴追踪系统 Proteus 仿真设计(仿真图+程序)
stm32·单片机·嵌入式硬件·proteus·课设
zhangzhangkeji1 天前
stm32 3-4 : 按键控制 LED,光敏传感器控制蜂鸣器
stm32·arm
Lzh编程小栈1 天前
STM32 DMA深度解析|原理、完整工作流程、寄存器、中断联动,嵌入式面试高频考点(F1系列)
c语言·stm32·单片机·mcu·面试
新晨单片机设计1 天前
S016A-基于STM32单片机电子秤(LCD1602显示)【Proteus仿真+Keil程序+原理图】
stm32·单片机·proteus
wuyk5551 天前
从零吃透 MQTT 通信|第 11 章 MQTT 项目调试验证、性能优化、常见疑难问题、OTA 升级基础
c语言·开发语言·stm32·学习·性能优化
辰域电子1 天前
STM32项目开源:粮仓环境安防监测系统(代码 + 原理图 + 仿真)
stm32·单片机·嵌入式硬件·开源·毕业设计·proteus