SPI communication between Arduino mega 2560 and ADC AD4114

Hi!

I am working on a project which suppose to get the digitalized values of current and voltage measurements of a battery module. Basically, implementing a battery monitoring system. To convert and read the values, I'm using AD4114 ADC with arduino mega 2560 as the controller via SPI communication. I am at the initial stage of the programming part. As the beginner step, I tried to reset the ADC and read the ID register to verify the communication. But i am getting the id as 40CE(hex format), but it should be 30DE as to the data sheet. I'll provide the code herewith as well. I'm analyzing the waveform via a logic analyzer. I'll attach the waveform as well. Can someone help me to debug this. without debugging I cannot go further.

THANK YOU!

**According to the data sheet of AD4114, to reset ADC "A write operation of at least 64 serial
clock cycles with DIN high returns the ADC to the default state by resetting the entire device, including the register contents." So in the code I have separately


used functions for Reset and ID register.

#include <SPI.h>


void setup() 
{
  pinMode(10,INPUT);
  pinMode(11,INPUT); 
  pinMode(12,INPUT);
  pinMode(13,INPUT); 
 
  
  Serial.begin(115200); // Set baud rate to 115200 for USART

  SPI.begin();

  SPI.setClockDivider(SPI_CLOCK_DIV16); // Divide the clock by 16
  SPI.setDataMode(SPI_MODE3);

  delay(1); // Allow some time for the ADC to power up

  resetADC();         /////////////////////////////////////////////// Perform ADC reset
  IDRegister();      //////////////////////////////////////////////Read ID register
}

void resetADC() 
{
  digitalWrite(SS, LOW); // Select the ADC

  // Write at least 64 serial clock cycles with DIN high to reset the entire device
   for (int i = 0; i < 10; i++) {
    SPI.transfer(0xFF);
  }
  
  digitalWrite(SS, HIGH); // Deselect the ADC
  delay(0.00001); // Add a delay after the reset

}

void IDRegister() {

  int32_t D1, D2, D3;
  char D1Arr[16];

  digitalWrite(SS, LOW); // Select the ADC

  // Command to read from the ID register
  SPI.transfer(0x00);
  SPI.transfer(0x47);

  // Read the two bytes of data from the ID register
  D2 = SPI.transfer(0xFF);
  D3 = SPI.transfer(0xFF);

  digitalWrite(SS, HIGH); // Deselect the ADC

  D1 = (D2 << 8) | D3;

  sprintf(D1Arr, "%04X", D1); // Display the data in hexadecimal format
  Serial.print("ID: ");
  Serial.print(D1Arr);
  Serial.println();
 delay(0.00001);
 
}


void loop() 
{

 
}

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