详解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文库

相关推荐
LN花开富贵1 小时前
stm32g431rbt6芯片中VREF+是什么?在电路中怎么设计?
笔记·stm32·单片机·嵌入式硬件·学习
qq21084629531 小时前
【stm32笔记】使用rtt-studio与stm32CubeMx联合创建项目
笔记·stm32·嵌入式硬件
CV金科1 小时前
蓝桥杯—STM32G431RBT6按键的多方式使用(包含软件消抖方法精讲)从原理层面到实际应用(一)
stm32·单片机·嵌入式硬件·蓝桥杯
luckyluckypolar1 小时前
STM32——输入捕获
stm32·单片机·嵌入式硬件·物联网
Projectsauron3 小时前
STM32 芯片启动过程
stm32·单片机·芯片启动过程
艾格北峰21 小时前
STM32 BootLoader 刷新项目 (六) 获取帮助-命令0x52
arm开发·stm32·单片机·嵌入式硬件
m0_739312871 天前
【STM32】独立看门狗(IWDG)原理详解及编程实践(上)
stm32·单片机·嵌入式硬件
CV金科1 天前
蓝桥杯-STM32G431RBT6(串口)
c语言·stm32·单片机·嵌入式硬件·蓝桥杯
CV金科1 天前
蓝桥杯-STM32G431RBT6(UART解析字符串sscanf和解决串口BUG)
c语言·stm32·单片机·嵌入式硬件·mcu·算法·bug
Caihua_X1 天前
ARM和51和stm32的区别
arm开发·stm32·嵌入式硬件