ESP32 + ADC LTC1867

Hi, I’m trying to make it work the ADC LTC1867 with the ESP32 in arduino IDE.

I tried to use a function (as I have in an sketch to do it with the MCP3208), by the same principle, let me share the code

#include "ADC.h"
#define DATAOUT 5//MOSI 
#define DATAIN  18//MISO 
#define SPICLOCK  19//Clock 

void setup() {
  Serial.begin(115200);  // put your setup code here, to run once:
  Serial.println("Serial port started");
  pinMode(17, OUTPUT);
  pinMode(16, OUTPUT);


  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK, OUTPUT);

  digitalWrite(17, HIGH);
  digitalWrite(16, HIGH);
  digitalWrite(DATAOUT, LOW);
  digitalWrite(SPICLOCK, LOW);



}

void loop() {
  for (int i = 0; i <= 7; i++)
  {
    read_adc( 17 , i);
    read_adc( 16 , i);
  }
  delay(1000);
}


int read_adc(byte SELPIN, int channel)
{
  int adcvalue = 0;
  byte commandbits = 0b1000010; //command bits - start, mode, chn (3), dont care (3)
 
  digitalWrite(SELPIN, LOW); //According datasheet device needs a little HIGH pulse
  digitalWrite(SELPIN, LOW); 
  digitalWrite(SELPIN, LOW); 
  digitalWrite(SELPIN, LOW); 
  digitalWrite(SELPIN, LOW); 
  digitalWrite(SELPIN, HIGH);
  digitalWrite(SELPIN, HIGH);
  digitalWrite(SELPIN, HIGH);
  digitalWrite(SELPIN, HIGH);
  digitalWrite(SELPIN, HIGH);
  digitalWrite(SELPIN, LOW); 


Serial.print("Selpin: ");
Serial.print(SELPIN);
Serial.print("  Channel: ");
Serial.print(channel);
Serial.print("      ");
byte aux1 = channel & 1;  // get the last bit
aux1 = aux1<<5; // move the bit to the its word position
channel = channel & 6;  //to make last bit 0 if it is not
channel =  channel << 2;
aux1 |= channel; 
commandbits |= aux1;

//  // setup bits to be written
  for (int i = 7; i >= 0; i--)
  {
    bool aux = commandbits & 1 << i;
    Serial.print(aux);
    digitalWrite(DATAOUT, aux);
    //cycle clock
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
  }
Serial.print("      ");



  //read bits from adc
  for (int i = 15; i >= 0; i--)
  {
    adcvalue += digitalRead(DATAIN) << i;
//    cycle clock
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, HIGH);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);
    digitalWrite(SPICLOCK, LOW);


  }
  digitalWrite(SELPIN, HIGH); //turn off device
Serial.println(adcvalue);

  //int adcvalue = random(2047, 4095);
  return adcvalue;
}

The words I am using to interrogate the ADC are:
//CH0 1 0 0 0 0 1 0
//CH1 1 1 0 0 0 1 0
//CH2 1 0 0 1 0 1 0
//CH3 1 1 0 1 0 1 0
//CH4 1 0 1 0 0 1 0
//CH5 1 1 1 0 0 1 0
/CH6 1 0 1 1 0 1 0
//CH7 1 1 1 1 0 1 0
I want single channel, unipolar, no sleep mode

Just used many “digitalWrite…” to avoid speed issues, (it works with the mcp3208 fine).

The answer I receive is a 0, in eight chanels, both ADC, it should show a value around to the mid range.

Here is the link to the datasheet:

Hope you may help me.

Hi again, does anyone has made work this ADC with arduino (and a library)? at this point I have doubts if the ADC are working, I've tried to make it work with an arduino mega without success, the measurement gives a 0 when it should be at the middle of the range (close to 32000).

Any advisement?

Thanks in advance