Post Go back to editing

Cannot get meaningful data from any channel above 0

Thread Summary

The user encountered an issue with the MAX11616 ADC on a Raspberry Pi 4 where only channel 0 provided valid readings. The problem was resolved by finding an example for the MAX11615 on GitHub, which provided the necessary configuration changes.
AI Generated Content
Category: Hardware
Product Number: MAX11616

I have been trying for several days to get the MAX11616 running on a custom HAT with a Raspberry Pi 4 in C.  With the current setup, if I only select channel 0, I get valid measurements.  But anything above channel 0 and the readings are all the same.  I hope someone can point out the error of my way.  Here is the code; I tried adding code from the insert, but the OK did nothing


int i2c_ADC = -1;
uint8_t ADC_add = 0x35;
uint8_t setup = 0xD2;//0xF2; // Correct setup byte
 uint16_t raw;

void ADC_Init(void)
{
       i2c_ADC = open("/dev/i2c-1", O_RDWR);
       if (i2c_ADC < 0) { perror("open"); exit(1); }

       if (ioctl(i2c_ADC, I2C_SLAVE, ADC_add) < 0) { perror("ioctl"); exit(1); }

       usleep(5000); // power-up delay

// Send setup byte
        if (write(i2c_ADC, &setup, 1) != 1)
        {
              perror("write setup");
             exit(1);
        }

       usleep(5000); // allow init to take hold
}


void ADC_Read(void)
{
    uint8_t data[2];
    uint8_t config = 0x0F; // SCAN=00, CS=11, SGL=1
    int counter;

       write(i2c_ADC, &config, 1);
      ioctl(i2c_ADC, I2C_SLAVE, ADC_add); // forces STOP
      usleep(50); // let the chip settle

//  Dummy read — throw away the first conversion
      read(i2c_ADC, data, 2);

//  read all 12 channels
       for (counter = 0; counter < 12; counter++)
      {
             if (read(i2c_ADC, data, 2) != 2)
             {
                   perror("read data");
                  return;
             }
             data[0] = data[0] & 0x0f;
            ADC_Array[counter] = ((data[0] << 8) | data[1]);
       }
//display data
    for (counter = 0; counter < 12; counter++)
    {
             printf("ADC_Array[%d] = %04x\n",counter, ADC_Array[counter]);
    }
}

Kind regards,

David

Parents Reply Children
No Data

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.