Canberk Sönmez
/
LTC2945_Monitor
LTC2945 ported
Diff: main.cpp
- Revision:
- 2:7e390bcce297
- Parent:
- 0:6be57f391716
- Child:
- 3:2ab78e7e8518
--- a/main.cpp Wed Aug 23 11:05:46 2017 +0000 +++ b/main.cpp Fri Aug 25 07:46:48 2017 +0000 @@ -3,17 +3,25 @@ #include "LT_I2C.h" #include "LTC2945.h" -I2C i2c(p28, p27); +I2C i2c(p9, p10); // sda, scl +extern I2C* i2c_object; + Serial pc(USBTX, USBRX); -#define LTC2945_I2C_ADDRESS 0xD4 +const int ltc2945_addr = 0xDE>>1; -#define ASSERT(x) if (! (x)) { pc.printf("%s:%d %s failed!\n", __FILE__, __LINE__, #x); } +int test_write(int byte) { + return i2c_object->write(byte); +} + +#define ASSERT(x) if (! (x)) { printf("%s:%d %s failed!\n", __FILE__, __LINE__, #x); } +#define DEBUG_LINE printf("DEBUG: %s:%d\n", __FILE__, __LINE__); int main() { - ASSERT(lt_i2c_init_attach(&i2c) == 0); + ASSERT(lt_i2c_init_attach(&i2c) == LT_I2C_INIT_FINE); + i2c.frequency(10000); const float LTC2945_DELTA_SENSE_lsb = 2.5006105E-05; //!< Typical Delta lsb weight in volts const float LTC2945_VIN_lsb = 2.5006105E-02; //!< Typical VIN lsb weight in volts @@ -30,24 +38,26 @@ float VIN; while (true) { + ack = 0; adc_command = LTC2945_SENSE_MONITOR | LTC2945_CONTINUOUS_MODE; // Builds commands to set LTC2945 to continuous mode - ack |= LTC2945_write(LTC2945_I2C_ADDRESS, LTC2945_CONTROL_REG, adc_command); // Sets the LTC2945 to continuous mode + ack |= LTC2945_write(ltc2945_addr, LTC2945_CONTROL_REG, adc_command); // Sets the LTC2945 to continuous mode ASSERT(ack == 0); - resistor = .01; // Resistor Value On Demo Board - - ack |= LTC2945_read_24_bits(LTC2945_I2C_ADDRESS, LTC2945_POWER_MSB2_REG, &power_code); // Reads the ADC registers that contains V^2 + resistor = .0182445; // Resistor Value On Demo Board + + ack |= LTC2945_read_24_bits(ltc2945_addr, LTC2945_POWER_MSB2_REG, &power_code); // Reads the ADC registers that contains V^2 ASSERT(ack == 0); power = LTC2945_code_to_power(power_code, resistor, LTC2945_Power_lsb); // Calculates power from power code, resistor value and power lsb - - ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_DELTA_SENSE_MSB_REG, ¤t_code); // Reads the voltage code across sense resistor + + ack |= LTC2945_read_12_bits(ltc2945_addr, LTC2945_DELTA_SENSE_MSB_REG, ¤t_code); // Reads the voltage code across sense resistor ASSERT(ack == 0); current = LTC2945_code_to_current(current_code, resistor, LTC2945_DELTA_SENSE_lsb); // Calculates current from current code, resistor value and current lsb - ack |= LTC2945_read_12_bits(LTC2945_I2C_ADDRESS, LTC2945_VIN_MSB_REG, &VIN_code); // Reads VIN voltage code + ack |= LTC2945_read_12_bits(ltc2945_addr, LTC2945_VIN_MSB_REG, &VIN_code); // Reads VIN voltage code ASSERT(ack == 0); VIN = LTC2945_VIN_code_to_voltage(VIN_code, LTC2945_VIN_lsb); // Calculates VIN voltage from VIN code and lsb - - pc.printf("power: %f, current: %f, Vin: %f\n", power, current, VIN); - wait_ms(500); + + + printf("power: %f, current: %f, Vin: %f\n", power, current, VIN); + wait_ms(500); } }