#include <SPI.h> // include the SPI library
const int csPin = 10; // CS pin for ADC
const int sdoPin = 12; // SDO pin for ADC
const int sckPin = 13; // SCK pin for ADC
void setup() {
Serial.begin(2000000); // start serial communication
pinMode(csPin, OUTPUT); // set CS pin as output
digitalWrite(csPin, HIGH); // set CS pin high to disable ADC communication
SPI.begin(); // start SPI communication
}
void loop() {
digitalWrite(csPin, LOW); // enable ADC communication
// configure the SPI communication with the ADC
SPISettings spiSettings(2000000, MSBFIRST, SPI_MODE3); // 1MHz clock frequency, MSB first, and SPI mode 3
SPI.beginTransaction(spiSettings); // start the transaction
// initiate a read operation on the ADC
unsigned int adcValue = SPI.transfer16(0x0000);
digitalWrite(csPin, HIGH); // disable ADC communication
// end the transaction
//SPI.endTransaction();
adcValue >>= 1;
float voltage = (adcValue * 4.096) / 16384; // calculate voltage based on reference voltage and ADC resolution
Serial.println(voltage); // print voltage to serial port
//delay(0.00001);
}