33#include " Adafruit_HUSB238.h"
44#include " LTC2943.h"
55
6+ #define CHARGEOPTION0_MSB 0x01
7+ #define CHARGEOPTION0_LSB 0x00
8+
9+ #define CHARGECURRENT_MSB 0x03
10+ #define CHARGECURRENT_LSB 0x02
11+
12+ #define MAXCHARGEVOLTAGE_MSB 0x05
13+ #define MAXCHARGEVOLTAGE_LSB 0x04
14+
15+ #define CHARGEOPTION1_MSB 0x31
16+ #define CHARGEOPTION1_LSB 0x30
17+
18+ #define CHARGEOPTION2_MSB 0x33
19+ #define CHARGEOPTION2_LSB 0x32
20+
21+ #define CHARGEOPTION3_MSB 0x35
22+ #define CHARGEOPTION3_LSB 0x34
23+
24+ #define PROCHOTOPTION0_MSB 0x37
25+ #define PROCHOTOPTION0_LSB 0x36
26+
27+ #define PROCHOTOPTION1_MSB 0x39
28+ #define PROCHOTOPTION1_LSB 0x38
29+
30+ #define ADCOPTION_MSB 0x3B
31+ #define ADCOPTION_LSB 0x3A
32+
33+ #define CHARGERSTATUS_MSB 0x21
34+ #define CHARGERSTATUS_LSB 0x20
35+
36+ #define PROCHOTSTATUS_MSB 0x23
37+ #define PROCHOTSTATUS_LSB 0x22
38+
39+ #define IIN_DPM_MSB 0x25
40+ #define IIN_DPM_LSB 0x24
41+
42+ #define ADCVBUSPSYS_MSB 0x27
43+ #define ADCVBUSPSYS_LSB 0x26
44+
45+ #define ADCIBAT_MSB 0x29
46+ #define ADCIBAT_LSB 0x28
47+
48+ #define ADCIINCMPIN_MSB 0x2B
49+ #define ADCIINCMPIN_LSB 0x2A
50+
51+ #define ADCVSYSVBAT_MSB 0x2D
52+ #define ADCVSYSVBAT_LSB 0x2C
53+
54+ #define OTGVOLTAGE_MSB 0x07
55+ #define OTGVOLTAGE_LSB 0x06
56+
57+ #define OTGCURRENT_MSB 0x09
58+ #define OTGCURRENT_LSB 0x08
59+
60+ #define INPUTVOLTAGE_MSB 0x0B
61+ #define INPUTVOLTAGE_LSB 0x0A
62+
63+ #define MINSYSTEMVOLTAGE_MSB 0x0D
64+ #define MINSYSTEMVOLTAGE_LSB 0x0C
65+
66+ #define IIN_HOST_MSB 0x0F
67+ #define IIN_HOST_LSB 0x0E
68+
69+ #define MANUFACTURERID 0x2E
70+ #define DEVICEID 0x2F
71+
672// void setup() {
773// Wire.begin(2, 1);
874// Serial.begin(115200);
@@ -53,6 +119,20 @@ uint16_t readRegister(uint8_t reg)
53119 return Wire.read (); // Combine high and low byte
54120}
55121
122+ // Function to write a 16-bit value to consecutive I2C registers
123+ void writeRegister16 (uint8_t lsbReg, uint16_t data)
124+ {
125+ Wire.beginTransmission (BQ25713_ADDRESS );
126+ Wire.write (lsbReg + 1 ); // Write to MSB register first
127+ Wire.write ((data >> 8 ) & 0xFF ); // Write MSB
128+ Wire.endTransmission ();
129+
130+ Wire.beginTransmission (BQ25713_ADDRESS );
131+ Wire.write (lsbReg); // Write to LSB register
132+ Wire.write (data & 0xFF ); // Write LSB
133+ Wire.endTransmission ();
134+ }
135+
56136void setup ()
57137{
58138 Serial.begin (115200 );
@@ -71,30 +151,25 @@ void setup()
71151 ;
72152 }
73153 // Change to that voltage
74- husb238.selectPD ((PD_SRC_15V ));
154+ husb238.selectPD ((PD_SRC_20V ));
75155 // Perform the actual PD voltage request!
76156 husb238.requestPD ();
77157 delay (2000 );
78158
79- Wire.beginTransmission (BQ25713_ADDRESS );
80- Wire.write (0x01 );
81- Wire.write (0b00000000 );
82- Wire.endTransmission ();
159+ // 0x020E to register 0x00
83160
84- Wire.beginTransmission (BQ25713_ADDRESS );
85- Wire.write (0x03 );
86- Wire.write (0b00000100 );
87- Wire.endTransmission ();
161+ writeRegister16 (CHARGEOPTION0_LSB , 0x020E );
88162
89- Wire.beginTransmission (BQ25713_ADDRESS );
90- Wire.write (0x3B );
91- Wire.write (0b10100000 );
92- Wire.endTransmission ();
163+ // ADC configurations
93164
94- Wire.beginTransmission (BQ25713_ADDRESS );
95- Wire.write (0x3A );
96- Wire.write (0b11111111 );
97- Wire.endTransmission ();
165+ writeRegister16 (ADCOPTION_LSB , 0xa0ff );
166+
167+ // charging
168+
169+ writeRegister16 (CHARGECURRENT_LSB , 0x0800 );
170+
171+ // set input current to
172+ writeRegister16 (IIN_HOST_LSB , 0x4000 ); // 3200mA input current
98173}
99174
100175void debugPrint (String info, uint8_t data)
@@ -112,6 +187,7 @@ void debugPrint(String info, uint8_t data)
112187
113188void loop ()
114189{
190+
115191 delay (1000 ); // Short delay to stabilize
116192
117193 Serial.println (" \n\n " );
@@ -120,10 +196,15 @@ void loop()
120196 debugPrint (" ChargerStatus 0x20:" , readRegister (0x20 ));
121197 debugPrint (" ChargeOption0 0x01:" , readRegister (0x01 ));
122198 debugPrint (" ChargeOption0 0x00:" , readRegister (0x00 ));
199+ debugPrint (" ChargeCurrent 0x03:" , readRegister (0x03 ));
200+ debugPrint (" ChargeCurrent 0x02:" , readRegister (0x02 ));
123201 debugPrint (" ADCOptions 0x3B:" , readRegister (0x3B ));
124202 debugPrint (" ADCOptions 0x3A:" , readRegister (0x3A ));
203+ debugPrint (" IIN_HOST 0x0F:" , readRegister (IIN_HOST_MSB ));
204+ debugPrint (" Input Current:" , readRegister (ADCIINCMPIN_MSB ));
205+ debugPrint (" CMP Voltage:" , readRegister (ADCIINCMPIN_LSB ));
125206
126- debugPrint (" VSYS 0x26:" , readRegister (0x26 ));
207+ debugPrint (" PSYS 0x26:" , readRegister (0x26 ));
127208 debugPrint (" ICHG 0x29:" , readRegister (0x29 ));
128209 debugPrint (" IDCHG 0x28:" , readRegister (0x28 ));
129210
@@ -133,4 +214,6 @@ void loop()
133214 Serial.println (readRegister (0x2D ) * 0.064 );
134215 Serial.print (" VBAT: " );
135216 Serial.println (readRegister (0x2C ) * 0.064 );
217+
218+ writeRegister16 (CHARGECURRENT_LSB , 0x0800 );
136219}
0 commit comments