ADS1252 Voltmeter ESP32

Hi
I ran this sample code and it works fine. How can I modify it to use it as a DC voltmeter (and possibly AC voltmeter in the future)?

//https://github.com/aeonSolutions/AeonLabs-ADS1252-24bit-ESP32-Arduino-Library/blob/main/example/ADS1252_Test.ino
#include <SPI.h>

#define MISOPIN 36 //36 //17, pin #5 1252
#define SCLKPIN 35
#define CLKPIN 19 //37 // 37 //20

// calculation formulas:
float f_ADSCLK = 10000000;// 10 MHz

float f_MCLK = f_ADSCLK / 6; 
float DRATE = f_MCLK / 64;
float p_MCLK = 1 / f_MCLK;
float t2 = 6 * p_MCLK;
float t3 = 6 * p_MCLK;
float t7 =30;

float  DRDY_partition = 36 * p_MCLK;
float DOUT_partition = 348 * p_MCLK;
float CONVCYCLE = DRDY_partition + DOUT_partition; // = 384 * p_MCLK;
float t_RESET_5 = 5 * CONVCYCLE; 

void setup(){
 Serial.begin(115200);
 
 pinMode(SCLKPIN, OUTPUT);
 pinMode(MISOPIN, INPUT);
 pinMode(CLKPIN, OUTPUT);
 
 // put ADC on reset at the outset
 reset_adc();
 
 // SPI.begin(VSPI_SCLK, VSPI_MISO, VSPI_MOSI, VSPI_SS); //SCLK, MISO, MOSI, SS
 SPI.begin(SCLKPIN, MISOPIN, 19, CLKPIN );
 SPI.setFrequency(f_ADSCLK);

 // initialize SPI (with default settings, including...
 // CPOL = 0: so that SCLK is normally LOW
 // CPHA = 0: data sampled on rising edge (LOW to HIGH)
 // perhaps try changing CPHA ??
 
 digitalWrite(SCLKPIN, LOW);
 // release ADC from reset; now we're at a known point
 // in the timing diagram, and just have to wait for
 // the beginning of a conversion cycle
Serial.println("setup completed");
}

//***************************************
void loop(){
 Serial.println("reset adc");
 // put ADC on reset at the outset
 reset_adc();
 Serial.println("reset completed");
 long int initTime= millis();
 
  Serial.print("MISO PIN RAW: ");
  Serial.println( digitalRead(MISOPIN) );
  
 while( (digitalRead(MISOPIN) != HIGH) && (millis()-initTime < 5000) ){  // 5 sec timeout
  Serial.print(millis()-initTime);
  Serial.print(" (");
  Serial.print( digitalRead(MISOPIN) );
  Serial.print(")...");
  delay(1000);
 } 
 Serial.println("miso pin probe completed");
 
 if (initTime - millis() >= 5000 ){ 
  Serial.println("Timeout waiting for response");
 }
 Serial.println("read adc"); 
 read_adc();
 digitalWrite(SCLKPIN, LOW);
 delay(1000);
}

//************************************************
// to reset ADC, we need SCLK HIGH for min of 4 CONVCYCLES
// so here, hold SCLK HIGH for 5 CONVCYCLEs = 1440 usec
void reset_adc(){
 digitalWrite(SCLKPIN, HIGH);
 delay(t_RESET_5);
}

// *********************************************
void read_adc(){
  // go to drdy_wait routine, where we wait for
  // DRDY phase to pass, and thus for DOUT phase to begin
  drdy_wait();

  byte byte1; byte byte2; byte byte3;
  byte flipper = 0b11111111; // 8 bit number to flip bits of a byte
  byte addone = 0b1; // to add one to the two's complement

  if ( digitalRead(MISOPIN) == HIGH ){
    SPI.beginTransaction(SPISettings(f_ADSCLK, MSBFIRST, SPI_MODE0));
    digitalWrite(SCLKPIN, LOW);
    delay(t2);
    delay(t3);
    //delay(t7);
    byte3 = SPI.transfer(0x00);
    byte2 = SPI.transfer(0x00);
    byte1 = SPI.transfer(0x00);
  } 
   
  // read in adc data (sending out don't care bytes)
  // and store read data into three bytes */
  digitalWrite(SCLKPIN, HIGH);
  SPI.endTransaction();

  Serial.println(byte1, DEC);
  Serial.println(byte2, DEC);
  Serial.println(byte3, DEC);
  Serial.println();

  int check = byte3 << 1;
  if (check == 1){
    // Negative number in two's complement form. need to flip bytes. and add one to them.
    //    negative = "-";
    // flip the bits
    
    byte3 = byte3^flipper;
    byte2 = byte2^flipper;
    byte1 = byte1^flipper;
}else{
  // negative = "+";
  // no need to flip or add one
  addone = 0b0;
}

  float ads_output =0;   
  ads_output = 5*(((byte3 << 16) + (byte2 << 8) + (byte1 + addone))) >> 24; 

  Serial.println(ads_output,10);

  //cout << " two's Complement : " <<  5*(((byte3 << 16) + (byte2 << 8) + (byte1 + addone))/pow(2,24)) << endl;

  // print out data;
  // will these instructions eat into time significantly?
  // possible improvement: store all data from multiple cycles
  // into array, and print out only later at end.
}

//***********************************************
// wait for DRDY to pass and to reach start-point of DOUT
void drdy_wait(){
 delay(DRDY_partition);
}

Read the ADC value. Scale it to volts. Display the result.

I know what to do but I don't know how.

This code is giving blank serial monitor screen

#include <Arduino.h>

#define MISOPIN 36 //36 //17, pin #5 1252
#define SCLKPIN 35
#define CLKPIN 19 //37 // 37 //20

// Variables to store 24-bit data
byte byte1, byte2, byte3;
long adcValue = 0;

void reset_adc() {
  // To reset ADC, SCLK must be HIGH for min of 4 conversion cycles (1440 usec)
  digitalWrite(SCLKPIN, HIGH);
  delayMicroseconds(1440);
  digitalWrite(SCLKPIN, LOW);
  delayMicroseconds(10); // Short delay to stabilize
}

void read_adc() {
  // Wait for DRDY to pass (indicated by MISO going LOW)
  while (digitalRead(MISOPIN) == HIGH);

  // Read 24 bits
  byte1 = 0; byte2 = 0; byte3 = 0;

  // Reading 24 bits (3 bytes)
  for (int i = 0; i < 8; i++) {
    digitalWrite(SCLKPIN, HIGH); delayMicroseconds(1);
    byte1 = (byte1 << 1) | digitalRead(MISOPIN);
    digitalWrite(SCLKPIN, LOW); delayMicroseconds(1);
  }
  for (int i = 0; i < 8; i++) {
    digitalWrite(SCLKPIN, HIGH); delayMicroseconds(1);
    byte2 = (byte2 << 1) | digitalRead(MISOPIN);
    digitalWrite(SCLKPIN, LOW); delayMicroseconds(1);
  }
  for (int i = 0; i < 8; i++) {
    digitalWrite(SCLKPIN, HIGH); delayMicroseconds(1);
    byte3 = (byte3 << 1) | digitalRead(MISOPIN);
    digitalWrite(SCLKPIN, LOW); delayMicroseconds(1);
  }

  // Combine bytes
  adcValue = ((long)byte1 << 16) | ((long)byte2 << 8) | (long)byte3;

  // Handle 2's complement for negative numbers if necessary
  if (adcValue & 0x800000) {
    adcValue |= 0xFF000000;
  }
}

void setup() {
  Serial.begin(115200);

  pinMode(SCLKPIN, OUTPUT);
  pinMode(MISOPIN, INPUT);
  pinMode(CLKPIN, OUTPUT);

  digitalWrite(SCLKPIN, LOW);
  reset_adc();
}

void loop() {
  // Poll DRDY/DOUT pin (goes HIGH when data is ready)
  if (digitalRead(MISOPIN) == HIGH) {
    read_adc();
    Serial.println(adcValue);
  }
}

What part don't you know?

  1. Read the ADC value
  2. Scale it
  3. Display it

I don't have the ADS1252 for testing but it looks like the original code is a DC voltmeter.

This is on serial, no respond to changes on input pins

4.0000000000
reset adc
reset completed
MISO PIN RAW: 1
miso pin probe completed
read adc
255
255
255

4.0000000000
reset adc
reset completed
MISO PIN RAW: 1
miso pin probe completed
read adc
255
255
255

here is another code, results not showing on serial monitor, monitor is blank

#define ADS_SCLK 35
#define ADS_DOUT 36
#define ADS_CLK 35

void setup() {
  Serial.begin(115200);
  pinMode(ADS_SCLK, OUTPUT);
  pinMode(ADS_DOUT, INPUT);
  digitalWrite(ADS_SCLK, LOW);
}

long readADS1252() {
  long value = 0;
  
  // Wait for DRDY to go LOW (indicates data is ready)
  while (digitalRead(ADS_DOUT) == HIGH); 
  
  // Read 24 bits
  for (int i = 0; i < 24; i++) {
    digitalWrite(ADS_SCLK, HIGH);
    delayMicroseconds(1); // Small delay for timing
    value = (value << 1) | digitalRead(ADS_DOUT);
    digitalWrite(ADS_SCLK, LOW);
    delayMicroseconds(1);
  }
  
  // Convert 24-bit two's complement to 32-bit signed long
  if (value & 0x800000) {
    value |= 0xFF000000;
  }
  
  return value;
}

void loop() {
  long adcVal = readADS1252();
  Serial.println(adcVal);
  delay(100);
}

Please show a diagram of how you have things connected.

Are you going to answer my question?

pins ESP32

#define MISOPIN 36 – > 5 ADS1252
#define SCLKPIN 35 – > 6 ADS1252
#define CLKPIN 37 – > 4 ADS1252

The ADS1252 requires 5V power.
You will now need voltage translators on the digital pins.

I ansfered in post # 8, the code contains all parts of your questions but it is not working.

In post #1 it is working at 3.3V

Can't see how, the datasheet clearly states 5V.

changed to 5V, doesn't help

... and connections to CLK, SCLK, and DOUT ... none of which are shown in the drawing.

Congratulations. You've just signed up to be an unpaid test pilot.

Personally, I'd pick a different A2D. This one has an oddball data interface that's not really SPI. That's why the GitHub code you posted had to jump through hoops to get it to "work" with SPI. Otherwise, you have to bit-bang it. Neither of these choices is very desirable.

NO NO, you will need voltage translators in order to work with a 3.3V ESP. Disconnect right away.

but is described below it

#define MISOPIN 36 – > 5 ADS1252
#define SCLKPIN 35 – > 6 ADS1252
#define CLKPIN 37 – > 4 ADS1252

You can try one of these for logic level shifting.