银杏科技有限公司旗下技术文档发布平台 | |||
技术支持电话 | 0379-69926675-801 | ||
技术支持邮件 | Gingko@vip.163.com | ||
版本 | 日期 | 作者 | 修改内容 |
---|---|---|---|
V1.0 | 2020-07-27 | gingko | 初次建立 |
1. 在主界面选择File–>New Project 或者直接点击ACCEE TO MCU SELECTOR 2. 出现芯片型号选择,搜索自己芯片的型号,双击型号,或者点击Start Project进入配置在搜索栏的下面,提供的各种查找方式,可以选择芯片内核,型号,等等,可以帮助你查找芯片。本实验选取的芯片型号为:STM32H750IBKx。 3. 配置RCC,使用外部时钟源 4. 时基源选择SysTick 5. 将PA10,PB7,PB8设置为GPIO_Output 6. 引脚模式配置 7. 时钟源设置,选择外部高速时钟源,配置为最大主频 8. 工程文件的设置, 这里就是工程的各种配置 我们只用到有限几个,其他的默认即可 IDE我们使用的是 MDK V5.27 9. 点击Code Generator,进行进一步配置
自行选择方式即可
int main(void) { HAL_Init(); SystemClock_Config(); i2c.initialize(); axp152.initialize(); axp152.set_dcdc1(3500);//[ARM & FPGA] axp152.set_dcdc2(1200);//[FPGA INT] axp152.set_dcdc3(3300);//[DCOUT3] axp152.set_dcdc4(3300);//[DCOUT4] axp152.set_aldo1(3300);//[BK3] axp152.set_aldo2(3300);//[ALDOOUT2] axp152.set_dldo1(3300);//[BK0] axp152.set_dldo2(3300);//[BK1] MX_GPIO_Init(); while (1) { } }
//定义常量的寄存器地址 #define AXP152_CHIP_VERSION 0x03 #define AXP152_DCDC1_VOLTAGE 0x26 //DC-DC1 电压设置寄存器 #define AXP152_DCDC2_VOLTAGE 0x23 //DC-DC2 电压设置寄存器 #define AXP152_DCDC3_VOLTAGE 0x27 //DC-DC3 电压设置寄存器 #define AXP152_DCDC4_VOLTAGE 0x2B //DC-DC4 电压设置寄存器 #define AXP152_DLDO1_VOLTAGE 0x29 //DLDO1 电压设置寄存器 #define AXP152_DLDO2_VOLTAGE 0x2A //DLDO2 电压设置寄存器 #define AXP152_ALDO1_ALD02_VOLTAGE 0x28 //ALDO1/2 电压设置寄存器 #define AXP152_SHUTDOWN 0x32 //关机和关机时序控制寄存器 #define AXP152_POWEROFF (1 << 7) #define AXP152_I2C_ADDR 0x60 //I2C设备地址
//axp152_mvolt_to_target 电压范围调整函数 static unsigned char axp152_mvolt_to_target(int mvolt, int min, int max, int div) { if (mvolt < min) mvolt = min; else if (mvolt > max) mvolt = max; return (mvolt - min) / div; //set_dcdc1 设定dcdc1输出电压 int set_dcdc1(unsigned int mvolt) { unsigned char target = axp152_mvolt_to_target(mvolt, 1700, 3500, 100); if(mvolt >= 2400 || mvolt <= 2800)target = target - 2; if(mvolt >= 3000 || mvolt <= 3500)target = target - 3; return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_DCDC1_VOLTAGE,&target,1); } //set_dcdc2 设定dcdc2输出电压 int set_dcdc2(unsigned int mvolt) { unsigned char target = axp152_mvolt_to_target(mvolt, 700, 2275, 25); return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_DCDC2_VOLTAGE,&target,1); } //set_dcdc3 设定dcdc3输出电压 int set_dcdc3(unsigned int mvolt) { unsigned char target = axp152_mvolt_to_target(mvolt, 700, 3500, 50); return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_DCDC3_VOLTAGE,&target,1); } //set_dcdc4 设定dcdc4输出电压 int set_dcdc4(unsigned int mvolt) { unsigned char target = axp152_mvolt_to_target(mvolt, 700, 3500, 25); return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_DCDC4_VOLTAGE,&target,1); } //set_dldo1 设定dldo1输出电压 int set_dldo1(unsigned int mvolt) { unsigned char target = axp152_mvolt_to_target(mvolt, 700, 3500, 100); return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_DLDO1_VOLTAGE,&target,1); } //set_dldo2 设定dldo2输出电压 int set_dldo2(unsigned int mvolt) { unsigned char target = axp152_mvolt_to_target(mvolt, 700, 3500, 100); return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_DLDO2_VOLTAGE,&target,1); } //set_aldo1 设定aldo1输出电压 int set_aldo1(unsigned int mvolt) { unsigned char data; unsigned char target; if(mvolt >= 1200 && mvolt <= 2000){ target = axp152_mvolt_to_target(mvolt, 1200, 2000, 100); }else if(mvolt == 2500){ target = 0x09; }else if(mvolt == 2700){ target = 0x0A; }else if(mvolt == 2800){ target = 0x0B; }else if(mvolt >= 3000 || mvolt <= 3300){ target = axp152_mvolt_to_target(mvolt, 3000, 3300, 100); target += 0x0C; } i2c.read_nbyte(AXP152_I2C_ADDR,AXP152_ALDO1_ALD02_VOLTAGE,&data,1); data &= 0x0F; target = target << 4; target &= 0xF0; target = data | target; return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_ALDO1_ALD02_VOLTAGE,&target,1); } //set_aldo2 设定aldo2输出电压 int set_aldo2(unsigned int mvolt) { unsigned char data; unsigned char target; if(mvolt >= 1200 && mvolt <= 2000){ target = axp152_mvolt_to_target(mvolt, 1200, 2000, 100); }else if(mvolt == 2500){ target = 0x09; }else if(mvolt == 2700){ target = 0x0A; }else if(mvolt == 2800){ target = 0x0B; }else if(mvolt >= 3000 || mvolt <= 3300){ target = axp152_mvolt_to_target(mvolt, 3000, 3300, 100); target += 0x0C; } i2c.read_nbyte(AXP152_I2C_ADDR,AXP152_ALDO1_ALD02_VOLTAGE,&data,1); data &= 0xF0; target = target & 0x0F; target = data | target; return i2c.write_nbyte(AXP152_I2C_ADDR,AXP152_ALDO1_ALD02_VOLTAGE,&target,1); }
用万用表测量各测试点电压与程序设定电压一致。