1
+ /*
2
+ * @Description(CN):
3
+ * 基于Arduino_DriveBus库的SY6970充电芯片例程
4
+ * 以下是使用该款芯片需要注意的几个点:
5
+ * 1. SY6970在获取芯片电压电流的时候需要开启ADC测量功能才能正常检测到电压电流等数据
6
+ * 如果未开启则获得的是错误信息
7
+ * 2. 在使用Arduino_DriveBus库时,初始化阶段会对芯片进行一次初始化的写入数据,具体
8
+ * 初始化内容可以前往芯片文件下的XXX_Initialization_Operations[]这个数组查看
9
+ * 3. Arduino_DriveBus库使用枚举的方式寄存操作芯片的命令和值,具体的可执行命令已经在
10
+ * 芯片文件的@Description有说明
11
+ *
12
+ * @Description(EN):
13
+ * SY6970 Charging Chip Routine based on Arduino_DriveBus Library
14
+ * Here are a few points to note when using this chip:
15
+ * 1. When obtaining voltage and current data from the SY6970 chip, the ADC measurement
16
+ * function must be enabled to correctly detect the voltage, current, and other data. If not enabled,
17
+ * error messages will be obtained.
18
+ * 2. When using the Arduino_DriveBus library, the chip is initialized with data during the initialization
19
+ * phase. The specific initialization content can be viewed in the XXX_Initialization_Operations[] array in
20
+ * the chip file.
21
+ * 3. The Arduino_DriveBus library uses enumerations to register commands and values for operating
22
+ * the chip. The specific executable commands are explained in the chip file under @Description.
23
+ *
24
+ * @version: V1.0.0
25
+ * @Author: Xk_w
26
+ * @Date: 2023-11-17 13:34:38
27
+ * @LastEditors: Xk_w
28
+ * @LastEditTime: 2023-11-27 17:33:55
29
+ * @License: GPL 3.0
30
+ */
31
+ #include " Arduino_DriveBus_Library.h"
32
+ #include " pin_config.h"
33
+
34
+ std::shared_ptr<Arduino_IIC_DriveBus> IIC_Bus =
35
+ std::make_shared<Arduino_HWIIC>(IIC_SDA, IIC_SCL, &Wire);
36
+
37
+ std::unique_ptr<Arduino_IIC> SY6970 (new Arduino_SY6970(IIC_Bus, SY6970_DEVICE_ADDRESS,
38
+ DRIVEBUS_DEFAULT_VALUE, DRIVEBUS_DEFAULT_VALUE));
39
+
40
+ static bool Temp1 = 0 ;
41
+
42
+ void setup ()
43
+ {
44
+ Serial.begin (115200 );
45
+ Serial.println (" Ciallo" );
46
+
47
+ while (SY6970->begin () == false )
48
+ {
49
+ Serial.println (" SY6970 initialization fail" );
50
+ delay (2000 );
51
+ }
52
+ Serial.println (" SY6970 initialization successfully" );
53
+
54
+ // 开启ADC测量功能
55
+ while (SY6970->IIC_Write_Device_State (SY6970->Device ::POWER_DEVICE_ADC_MEASURE,
56
+ SY6970->Device_State ::POWER_DEVICE_ON) == false )
57
+ {
58
+ Serial.println (" SY6970 ADC Measure ON fail" );
59
+ delay (2000 );
60
+ }
61
+ Serial.println (" SY6970 ADC Measure ON successfully" );
62
+
63
+ // 禁用看门狗定时器喂狗功能
64
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_WATCHDOG_TIMER, 0 );
65
+ // 热调节阈值设置为60度
66
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_THERMAL_REGULATION_THRESHOLD, 60 );
67
+ // 充电目标电压电压设置为4224mV
68
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_CHARGING_TARGET_VOLTAGE_LIMIT, 4224 );
69
+ // 最小系统电压限制为3600mA
70
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_MINIMUM_SYSTEM_VOLTAGE_LIMIT, 3600 );
71
+ // 设置OTG电压为5062mV
72
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_OTG_VOLTAGE_LIMIT, 5062 );
73
+ // 输入电流限制设置为600mA
74
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_INPUT_CURRENT_LIMIT, 600 );
75
+ // 快速充电电流限制设置为2112mA
76
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_FAST_CHARGING_CURRENT_LIMIT, 2112 );
77
+ // 预充电电流限制设置为192mA
78
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_PRECHARGE_CHARGING_CURRENT_LIMIT, 192 );
79
+ // 终端充电电流限制设置为320mA
80
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_TERMINATION_CHARGING_CURRENT_LIMIT, 320 );
81
+ // OTG电流限制设置为500mA
82
+ SY6970->IIC_Write_Device_Value (SY6970->Arduino_IIC_Power ::Device_Value::POWER_DEVICE_OTG_CHARGING_LIMIT, 500 );
83
+ }
84
+
85
+ void loop ()
86
+ {
87
+ Serial.printf (" --------------------SY6970--------------------\n " );
88
+ Serial.printf (" System running time: %d\n\n " , (uint32_t )millis () / 1000 );
89
+ Serial.printf (" IIC_Bus.use_count(): %d\n\n " , (int32_t )IIC_Bus.use_count ());
90
+
91
+ Serial.printf (" IIC device ID: %#X \n " , (int32_t )SY6970->IIC_Read_Device_ID ());
92
+
93
+ Serial.printf (" \n BUS Status: %s \n " ,
94
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_BUS_STATUS)).c_str ());
95
+ Serial.printf (" BUS Connection Status: %s \n " ,
96
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_BUS_CONNECTION_STATUS)).c_str ());
97
+ Serial.printf (" Charging Status: %s \n " ,
98
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_CHARGING_STATUS)).c_str ());
99
+ Serial.printf (" Input Source Status: %s \n " ,
100
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_INPUT_SOURCE_STATUS)).c_str ());
101
+ Serial.printf (" Input USB Status: %s \n " ,
102
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_INPUT_USB_STATUS)).c_str ());
103
+ Serial.printf (" System Voltage Status: %s \n " ,
104
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_SYSTEM_VOLTAGE_STATUS)).c_str ());
105
+ Serial.printf (" Thermal Regulation Status: %s \n " ,
106
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_THERMAL_REGULATION_STATUS)).c_str ());
107
+
108
+ Serial.printf (" \n Watchdog Fault Status: %s \n " ,
109
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_WATCHDOG_FAULT_STATUS)).c_str ());
110
+ Serial.printf (" OTG Fault Status: %s \n " ,
111
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_OTG_FAULT_STATUS)).c_str ());
112
+ Serial.printf (" Charging Fault Status: %s \n " ,
113
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_CHARGING_FAULT_STATUS)).c_str ());
114
+ Serial.printf (" Battery Fault Status: %s \n " ,
115
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_BATTERY_FAULT_STATUS)).c_str ());
116
+ Serial.printf (" NTC Fault Status: %s \n " ,
117
+ (SY6970->IIC_Read_Device_State (SY6970->Arduino_IIC_Power ::Status_Information::POWER_NTC_FAULT_STATUS)).c_str ());
118
+
119
+ Serial.printf (" \n Input Voltage: %d mV \n " ,
120
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_INPUT_VOLTAGE));
121
+ Serial.printf (" Battery Voltage: %d mV \n " ,
122
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_BATTERY_VOLTAGE));
123
+ Serial.printf (" System Voltage: %d mV \n " ,
124
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_SYSTEM_VOLTAGE));
125
+ Serial.printf (" NTC Voltage Percentage: %.03f %% \n " ,
126
+ (float )SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_NTC_VOLTAGE_PERCENTAGE) / 1000.0 );
127
+ Serial.printf (" Charging Current: %d mA \n " ,
128
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_CHARGING_CURRENT));
129
+ Serial.printf (" Thermal Regulation Threshold: %d ^C \n " ,
130
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_THERMAL_REGULATION_THRESHOLD));
131
+
132
+ Serial.printf (" \n Charging Voltage Limit: %d mV \n " ,
133
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_CHARGING_TARGET_VOLTAGE_LIMIT));
134
+ Serial.printf (" Minimum System Voltage Limit: %d mV \n " ,
135
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_MINIMUM_SYSTEM_VOLTAGE_LIMIT));
136
+ Serial.printf (" OTG Voltage Limit: %d mV \n " ,
137
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_OTG_VOLTAGE_LIMIT));
138
+ Serial.printf (" Input Current Limit: %d mA \n " ,
139
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_INPUT_CURRENT_LIMIT));
140
+ Serial.printf (" Fast Charge Current Limit: %d mA \n " ,
141
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_FAST_CHARGING_CURRENT_LIMIT));
142
+ Serial.printf (" Precharge Charge Current Limit: %d mA \n " ,
143
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_PRECHARGE_CHARGING_CURRENT_LIMIT));
144
+ Serial.printf (" Termination Charge Current Limit: %d mA \n " ,
145
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_TERMINATION_CHARGING_CURRENT_LIMIT));
146
+ Serial.printf (" OTG Current Limit: %d mA \n " ,
147
+ SY6970->IIC_Read_Device_Value (SY6970->Arduino_IIC_Power ::Value_Information::POWER_OTG_CURRENT_LIMIT));
148
+
149
+ Serial.printf (" --------------------SY6970--------------------\n\n " );
150
+
151
+ delay (1000 );
152
+
153
+ Temp1 = !Temp1;
154
+ if (Temp1 == 0 )
155
+ {
156
+ }
157
+ else
158
+ {
159
+ }
160
+ }
0 commit comments