Hey Guys and Gals …I need some assistance with this pesky #C & I2C … I have an Arduino code I need transferred to C# and its got my head hurting today …If possible could someonedo a quick transpose for me …Itll be a good starting point…Thanks
Arduino Code for the LTC2945 Power sensor I2C
#include <Wire.h>
#define LTCADDR 0x6A
byte ADCvinMSB, ADCvinLSB, curSenseMSB, curSenseLSB, AinVMSB, AinVLSB;
unsigned int ADCvin, ADCcur, AinV;
float inputVoltage, ADCvoltage, current10, current1, current0p1, current0p01;
void setup() {//setup
Serial.begin(9600);
Wire.begin();
lcd.begin();
}
void loop() {
Wire.beginTransmission(LTCADDR);//first get Input Voltage - 80V max
Wire.write(0x1E);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
ADCvinMSB = Wire.read();
ADCvinLSB = Wire.read();
ADCvin = ((unsigned int)(ADCvinMSB) << 4) + ((ADCvinLSB >> 4) & 0x0F);//formats into 12bit integer
inputVoltage = ADCvin * 0.025; //25mV resolution
Wire.beginTransmission(LTCADDR);//get ADC Input 2V max
Wire.write(0x28);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
AinVMSB = Wire.read();
AinVLSB = Wire.read();
AinV = ((unsigned int)(AinVMSB) << 4) + ((AinVLSB >> 4) & 0x0F);//12 bit format
ADCvoltage = AinV * 0.5E-3; //500uV resolution
Wire.beginTransmission(LTCADDR);//get sense current
Wire.write(0x14);
Wire.endTransmission(false);
Wire.requestFrom(LTCADDR, 2, true);
delay(1);
curSenseMSB = Wire.read();
curSenseLSB = Wire.read();
ADCcur = ((unsigned int)(curSenseMSB) << 4) + ((curSenseLSB >> 4) & 0x0F);//12 bit format
//gets voltage across, 25uV resolution, then this converts to voltage for each sense resistor
current10 = ADCcur * (25E-3) / 10.0; //10mA max, unit is mA
current1 = ADCcur * (25E-3) / 1.0; //100mA max, unit is mA
current0p1 = ADCcur * (25E-3) / 0.1; //1A max, unit is mA
current0p01 = ADCcur * (25E-6) / 0.01;//10A max, unit is A
//Print everything out
Serial.print(“Vin:25mV/80V>”);
Serial.print(inputVoltage, 2);
// Serial.print(“V 10ohm:2.5uA/10mA>”);
//Serial.print(current10, 3);
//Serial.print(“mA 1ohm:25uA/100mA>”);
//Serial.print(current1, 2);
//Serial.print(“mA 0.1ohm:250uA/1A>”);
//Serial.print(current0p1, 1);
//Serial.print(“mA 0.01ohm:2.5mA/10A>”);
Serial.print(current0p01, 3);
Serial.print(“A ADC:0.5mV/2V>”);
Serial.print(ADCvoltage, 4);
Serial.println(“V”);
lcd.println(inputVoltage);
lcd.println(current0p01);
delay(10000);
//Check to see if data is ready with .dataAvailable()