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

相关推荐
螺丝钉的扭矩一瞬间产生高能蛋白2 小时前
基于FreeRTOS和STM32的微波炉
stm32·单片机·嵌入式硬件
Aspiring Q2 小时前
vscode+keil嵌入式软件开发全流程
vscode·stm32·单片机
努力创造奇迹2 小时前
STM32 HAL库 内部传感器驱动实现
stm32·单片机·嵌入式硬件
田甲5 小时前
【STM32】STemWin库,使用template API
stm32·单片机·嵌入式硬件
四夕白告木贞6 小时前
stm32week11
stm32·单片机·嵌入式硬件·学习
the sun346 小时前
深入理解单片机的运行流程
stm32·单片机·嵌入式硬件
努力创造奇迹6 小时前
STM32 HAL库 低功耗的实现
stm32·单片机·嵌入式硬件
Despacito0o7 小时前
FreeRTOS二值信号量详解与实战教程
驱动开发·stm32·单片机·嵌入式硬件·mcu·51单片机·嵌入式实时数据库
强化学习与机器人控制仿真8 小时前
ROS & ROS2 机器人深度相机激光雷达多传感器标定工具箱入门教程(一)
开发语言·人工智能·stm32·深度学习·机器人·自动驾驶
技术干货贩卖机10 小时前
0基础 | 开发环境 |51单片机编译环境 Keil C251和C51,STM32的编译环境Keil 5 MDK-ARM
arm开发·stm32·嵌入式硬件