Hello,
I am working on developing battery charging management system using Atmega32 and LTC4162-s chip. I am using SMbus protocol. I have seen some reference code in Arduino Forum and LTC4162 chip datasheet, build my code for generate charging current and charging voltage. But I have no idea how to write this charging current and charging voltage values as command for start charging the battery. If any on have experience on this please give guide or any reference to complete this task.
I have attached my code below.
#include <Wire.h>
#include <SoftwareSerial.h>
#define I2CAddress 0x68
#define charging_current_cmd_ad 0x1A
#define charging_voltage_cmd_ad 0x1B
const int RS485RX_pin = 8;
const int RS485TX_pin = 9;
const int RS485FC_pin = 10;
const int SMBALERT = 18;
uint16_t I_charge=0;
uint16_t v_charge=0;
uint16_t C_current;
uint16_t C_voltage;
//int sda =17;
//int scl =16;
uint8_t count;
uint8_t values[2]={0,0};
SoftwareSerial RS485Serial(RS485RX_pin,RS485TX_pin);
int bat_reading =0;
void setup() {
RS485Serial.begin(9600);
pinMode(RS485FC_pin,OUTPUT);
digitalWrite(RS485FC_pin,LOW);
delay(1000);
Serial.begin(9600);
//Wire.begin();
Wire.begin(I2CAddress);
pinMode(SMBALERT,OUTPUT);
digitalWrite(SMBALERT,HIGH);
}
void CG_Current(){
uint16_t I_charge1;
uint16_t I_charge2;
uint16_t I_charge3;
uint16_t Sense_Resistor =0.011;
I_charge1 = C_current+1;
I_charge2 = I_charge1*0.001;
I_charge = I_charge2/Sense_Resistor; //charging current
Serial.print("Charging Current :");
Serial.println(I_charge);
}
void CG_voltage(){
uint16_t v_charge1;
uint16_t v_charge2;
uint16_t v_charge3;
uint16_t v_charge4;
v_charge1 = C_current+1;
v_charge2 = v_charge1*0.028571;
v_charge3 = 6 + v_charge2;
v_charge = v_charge3*1; // charging voltage 6V
// v_charge = v_charge3*2; // charging voltage 12V
// v_charge = v_charge3*3; // charging voltage 18V
// v_charge = v_charge3*4; // charging voltage 24V
Serial.print("Charging Voltage :");
Serial.println(v_charge);
}
void loop() {
digitalWrite(SMBALERT,HIGH);
delay(2000);
digitalWrite(RS485FC_pin,HIGH);
delay(2000);
//Charging Current
Wire.beginTransmission(I2CAddress);
Wire.write(charging_current_cmd_ad);// charging current command code set
Wire.endTransmission(false);
Wire.requestFrom(I2CAddress,2);
count = 0;
while(Wire.available()){
values[count++] = Wire.read();
}
uint16_t C_current = (uint16_t)(values[1] << 8 | (uint16_t)(values[0]));
Serial.print("charge_current_setting : ");
Serial.println(C_current);
delay(1000);
//Charging voltage
Wire.beginTransmission(I2CAddress);
Wire.write(charging_voltage_cmd_ad);
Wire.endTransmission(false);
Wire.requestFrom(I2CAddress, 2);
count = 0;
while(Wire.available()){
values[count++] = Wire.read();
}
uint16_t C_voltage = (uint16_t)(values[1]) << 8 | (uint16_t)(values[0]);
Serial.print("vcharge_setting : ");
Serial.println(C_voltage);
delay(1000);
}