This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADS7142: Library or I2C details for ADS7142

Part Number: ADS7142

Dear all,

I'm just starting to use the ADS7142 with a TMR in order to save as much power as possible when the device is battery powered.

I'm encountering some difficulties implementing the I2C communication under Arduino using the ATtiny1634.

In details my read and write function are below:

void writeADCRegister(byte address, byte value)
{
  Wire.beginTransmission(ADC_ADDRESS & 0x7F);
  Wire.write(0x08);                 // Single Register Write Opcode
  Wire.write(address);                   
  Wire.write(value);                      
  Wire.endTransmission();                 // send the bytes in the buffer
}

uint8_t readADCRegister(byte address)
{
  uint8_t value;
  Wire.beginTransmission(ADC_ADDRESS & 0x7F);
  Wire.write(0x10);                   // Single Register Read Opcode
  Wire.write(address);   

  Wire.endTransmission();

 
  Wire.write(ADC_ADDRESS | 0x80);
  Wire.requestFrom(ADC_ADDRESS, 1);

  while(!Wire.available());

  value = Wire.read();
  Wire.endTransmission();
 
  return value;
}

where: 

#define ADC_ADDRESS   0x18  // ADDR pin to ground

It seems to work after a bit of proofs

  • Hi Alessio,

    I sounds like the communication is now working for you, is that correct?
  • Yes sorry now is correct,
    I opened the thread when the communication was wrong but after a bit of time I've solved.
    Now I have another issue with the threshold in autonomous mode.
    Opened in another thread.

    HERE THE CORRECT FUNCTIONS:

    #define ADC_ADDRESS   0x18  // ADDR pin to ground

    void writeADCRegister(byte address, byte value)
    {
      Wire.beginTransmission(ADC_ADDRESS & 0x7F);
      Wire.write(0x08);                 // Single Register Write Opcode
      Wire.write(address);                   
      Wire.write(value);                      
      Wire.endTransmission();                 // send the bytes in the buffer
    }

    uint8_t readADCRegister(byte address)
    {
      uint8_t value;
      Wire.beginTransmission(ADC_ADDRESS & 0x7F);
      Wire.write(0x10);                   // Single Register Read Opcode
      Wire.write(address);   
      Wire.endTransmission();
     
      Wire.write(ADC_ADDRESS | 0x80);
      Wire.requestFrom(ADC_ADDRESS, 1);

      while(!Wire.available());

      value = Wire.read();
      Wire.endTransmission();
     
      return value;
    }


    void readADCAccRegisters(uint16_t *ch0, uint16_t *ch1)      // ONLY WHEN IN HIGH RESOLUTION MODE
    {
      uint8_t value;
      Wire.beginTransmission(ADC_ADDRESS & 0x7F);
      Wire.write(0x30);                   // Reading a continuous block of registers
      Wire.write(0x08);                   // address of ACC_CH0_LSB Register
      Wire.endTransmission();

      Wire.write(ADC_ADDRESS | 0x80);
      Wire.requestFrom(ADC_ADDRESS, 4);

      while(!Wire.available());

      *ch0 = Wire.read() + ( (uint16_t)Wire.read() << 8 );
      *ch1 = Wire.read() + ( (uint16_t)Wire.read() << 8 );
    }



    Thanks

  • Hi Alessio,

    I just saw your response. Great to hear that it is working for you, and please let us know if you have any other questions.