I2C not yet integrated

Dependencies:   mbed

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

Revision:
1:4e4194db7cd6
Parent:
0:1473318f27b6
Child:
2:c9e727dcd00e
--- a/LTC2991.cpp	Wed Nov 16 15:54:08 2016 +0000
+++ b/LTC2991.cpp	Tue Nov 29 03:20:35 2016 +0000
@@ -72,6 +72,8 @@
 #include "LTC2991.h"
 #include "mbed.h"
 
+Serial pc2(USBTX, USBRX, 9600);
+
 //#include <Wire.h>
 
 // Reads a 14-bit adc_code from LTC2991.
@@ -80,10 +82,13 @@
   int8_t ack = 0;
   uint16_t code;
   ack = i2c_read_word_data(i2c_address, msb_register_address, &code);
+   
 
   *data_valid = (code >> 15) & 0x01;   // Place Data Valid Bit in *data_valid
 
   *adc_code = code & 0x7FFF;  // Removes data valid bit to return proper adc_code value
+  
+  //pc2.printf("i2c_read_word_data result: raw code: %0x%X, ack %d\n", code, ack);
 
   return(ack);
 }
@@ -100,7 +105,8 @@
 
   for (timer_count = 0; timer_count < timeout; timer_count++)
   {
-
+    //pc2.printf("status_bit: %d\n", status_bit);
+    
     if (status_bit<8)
     {
       ack |=  LTC2991_register_read(i2c_address, LTC2991_STATUS_LOW_REG, &reg_data); //! 1)Read status register until correct data valid bit is set
@@ -117,7 +123,7 @@
         status_bit = 0;
       }
     }
-
+    
     if ((ack) || (((reg_data>>status_bit)&0x1)==1))
     {
       break;
@@ -129,10 +135,10 @@
   ack |= LTC2991_adc_read(i2c_address, msb_register_address, &(*adc_code), &(*data_valid));   //! 2) It's either valid or it's timed out, we read anyways
   if (*data_valid  !=1)
   {
-    ////Serial.print("Data not valid: ");
-    //Serial.println(*data_valid);
+    pc2.printf("Data not valid: 0x%X\n", *data_valid);
     return (1);
   }
+
   return(ack);
 }
 
@@ -155,7 +161,6 @@
 int8_t LTC2991_register_read(uint8_t i2c_address, uint8_t register_address, uint8_t *register_data)
 {
   int8_t ack = 0;
-
   ack = i2c_read_byte_data(i2c_address, register_address, register_data);
   return(ack);
 }
@@ -165,7 +170,6 @@
 int8_t LTC2991_register_write(uint8_t i2c_address, uint8_t register_address, uint8_t register_data)
 {
   int8_t ack = 0;
-
   ack = i2c_write_byte_data(i2c_address, register_address, register_data);
   return(ack);
 }