LTC1867 + ESP32

esdfsf

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

Have built a board, as a prototype, so I'm trying to make it work as a Proof of concept

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

#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, 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, 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, LOW);

  }
  digitalWrite(SELPIN, HIGH); //turn off device
Serial.println(adcvalue);
 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

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:
https://www.analog.com/media/en/technical-documentation/data-sheets/LTC1863-1867.pdf

Any help or guiadance how to sort this, will be appreciated.

Thanks in advance.

I'm missing the schematics of your board. You must not connect the LTC1867 to the ESP32 directly as it runs on 5V while the ESP32 runs on 3.3V. The problematic pins is MISO which outputs a 5V signal that may destroy the connected pin on the ESP.

I don't see why you're trying to emulate the SPI interface in software as the ESP32 has hardware support for it.
BTW, your software emulation does it wrongly: the LTC1867 provide the output value while SCKL is high but you're reading it while you pulled it low.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.