I2C not yet integrated
Tested working with single and differential voltages.
Connect SCL (pin 11) to D15 Connect SDA (pin 10) to D14 Connect pin 16 to +5v Connect pin 9 to gnd
Diff: main.cpp
- Revision:
- 1:4e4194db7cd6
- Parent:
- 0:1473318f27b6
- Child:
- 2:c9e727dcd00e
diff -r 1473318f27b6 -r 4e4194db7cd6 main.cpp --- a/main.cpp Wed Nov 16 15:54:08 2016 +0000 +++ b/main.cpp Tue Nov 29 03:20:35 2016 +0000 @@ -1,21 +1,18 @@ #include "mbed.h" #include "LTC2991.h" -//#include <Wire.h> #include <stdarg.h> int8_t ack; // 0 == ack, 1 == no ack const uint16_t LTC2991_TIMEOUT=1000; //!< Configures the maximum timeout allowed for an LTC2991 read. Serial pc(USBTX, USBRX, 9600); -void setup(); + +//void setup(); int main(); void readSingle(); void readDiff(); - - void setup() { - //Wire.begin(); - + ack = 0; while (true) { pc.printf("boot\n"); @@ -23,6 +20,7 @@ ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00); //! Sets registers to default starting values. ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V5678_REG, 0x00); ack |= LTC2991_register_write(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_PWM_Tinternal_REG, LTC2991_REPEAT_MODE); //! Configures LTC2991 for Repeated Acquisition mode + if (ack != 0) { pc.printf("Error: No Acknowledge. Check I2C Address.\n"); wait_ms(500); @@ -36,6 +34,7 @@ setup(); while(1) { readDiff(); + readSingle(); wait_ms(750); } } @@ -44,19 +43,28 @@ int8_t data_valid; int16_t code; float voltage; - + ack = 0; ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, 0x00, LTC2991_V1_V2_DIFFERENTIAL_ENABLE | LTC2991_V1_V2_TEMP_ENABLE); ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V1_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT); voltage = LTC2991_code_to_single_ended_voltage(code, LTC2991_SINGLE_ENDED_lsb); - pc.printf("V1: %4.2f V", voltage); + if (ack != 0) { + pc.printf("Error: No Acknowledge.\n"); + } else { + pc.printf("V1: %4.2f V\n", voltage); + } } + void readDiff() { int8_t data_valid; int16_t code; float voltage; - + ack = 0; ack |= LTC2991_register_set_clear_bits(LTC2991_I2C_ADDRESS, LTC2991_CONTROL_V1234_REG, LTC2991_V1_V2_DIFFERENTIAL_ENABLE, LTC2991_V1_V2_TEMP_ENABLE); ack |= LTC2991_adc_read_new_data(LTC2991_I2C_ADDRESS, LTC2991_V2_MSB_REG, &code, &data_valid, LTC2991_TIMEOUT); voltage = LTC2991_code_to_differential_voltage(code, LTC2991_DIFFERENTIAL_lsb); - pc.printf("V1-V2: %4.2f V", voltage); + if (ack != 0) { + pc.printf("Error: No Acknowledge.\n"); + } else { + pc.printf("V1-V2: %4.2f V\n", voltage, ack); + } } \ No newline at end of file