Go Down

Topic: I2C Register (Read 860 times) previous topic - next topic

ShaunLeeTP

Ok, this is a complete guess as I don't have an LTC2497 to test it on but maybe something like this will work:

Code: [Select]
#include <Wire.h>

#define ADCAddr 0x14         // I2C Address of LTC2497

// codes for single ended ADC channels 0,1,2 & 3
uint8_t adcChannel[4] = { B10110000, B10111000, B10110001, B10111001 };

// codes for differential ADC channels 0,1,2 & 3
//uint8_t adcChannel[4] = { B10100000, B10100001, B10100010, B10100011 };

void setup()
{
  Wire.begin();
  Serial.begin(9600);
}

void loop()
{
  for (adcChan = 0; adcChan < 4; adcChan++)
  {
    Serial.print( adcChann );
    Serial.print( ":" );

    // start a conversion on channel "adcChan"
    Wire.beginTransmission(ADCAddr);
    Wire.write(adcChannel[adcChan]);
    Wire.endTransmission();

    // slight delay for the conversion to complete
    // you might need to tweak the delay
    delay(10);

    // request 3 bytes from the ADC
    Wire.requestFrom(ADCAddr, 3);
    while (Wire.available()) {
      data = Wire.read();
      Serial.print(data, HEX);
    }
    Serial.println("");
  }
  // wait a second
  delay(1000);
}



Hopefully this will work for you.
Hi markd833

I managed to resolve the issue..it was very close to the code you posted...Post them here so everyone can learn..

Code: [Select]

#include <SPI.h>
#include <Wire.h>

#define ADCAddr 0x14         //Address of I2C

uint32_t data;
int dataBits;
int dataBits2;
uint8_t adcChannel[8] = { 0xB0, 0xB8, 0xB1, 0xB9,
                          0xB2, 0xBA, 0xB3, 0xBB };

void setup() {
  Wire.begin();
 
  Wire.beginTransmission(ADCAddr);
  Wire.write(0);
  Wire.write(adcChannel[0]);
  Wire.endTransmission();

  Serial.begin(9600);
  Serial.println("Welcome to BMS");
}


void loop() {
  for (int x = 0; x < 8; x++) {
    delay(170);
   
    Serial.print(adcChannel[x], HEX);
    Serial.println(":");

    Wire.beginTransmission(ADCAddr);
    Wire.write(adcChannel[x]);
    Wire.endTransmission();

    delay(170);

    Wire.requestFrom(ADCAddr, 3);

    while(Wire.available()) {
      data = Wire.read();
      Serial.println(data, BIN);
    }
    Serial.println();
  }
  // wait a second
  delay(1000);
}

markd833

Glad you got it working and thanks for sharing the answer.

Go Up