AD7710 with Arduino

Go To Last Post
6 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

Do you have any example to interface the AD7710 with Arduino ?

 

Comment: Please do not hijack another thread. Also select an appropriate forum and title. Moderator.

Last Edited: Mon. Feb 13, 2017 - 10:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Mon. Feb 13, 2017 - 09:54 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Really??

Of course the second thing i did was searching the google. After I tried it by myself but got nothing helpful
anyways thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, the first hit I see is:

 

https://github.com/gauteh/sonobu...

 

And

 

https://www.ccsinfo.com/forum/vi...

 

So what is it specifically about Arduino that you're stuck with?

 

Remember that the AD7710 neither knows nor cares anything about Arduino.

 

What have you learned from the many other threads here about the AD7710 (including the one your "hijack" was moved from) ?

 

Have you looked at the examples provided by the manufacturer themselves (also cited in that thread)?

 

https://www.avrfreaks.net/comment...

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

 

I have been looked on https://github.com/gauteh/sonobu... I think it is made for processing not for Arduino IDE.

Anyways I started with reading the datasheet carefully. Tried to use SPI in Arduino but I got random errors and could not write to the control register.

After reading "gauteh" lib i decided to use shiftIn and shiftout instead. And it works just fine.

 

/*
 * This example to interface arduino MEGA with AD7710 ADC.
 * It is based on "gauteh" library which it made for processing (I think). So it is not a straight forward lib for Arduino IDE.
 * "https://github.com/gauteh/sonobuoy-gautebuoy/tree/master/buoy/arduino/ad7710"
 * Tried to use SPI lib by setting the SPI clock to 2MHz, MSBFIRST and MODE0 but it does not work.
 * By using the SPI lib i could read the data register but not writing to the control register.
 * 
 * elec.en.de@gmail.com
 */
//#include <SPI.h>

# define aZero     22
# define RFS       24
# define TFS       26
# define DRDY      28
# define SCLK      52
# define SDATA     50

# define CONTROL_SELF_CALIBRATION      0b001000000000
# define CONTROL_GAIN2                 0b000001000000
# define CONTROL_GAIN4                 0b000010000000
# define CONTROL_GAIN8                 0b000011000000
# define CONTROL_GAIN16                0b000100000000
# define CONTROL_GAIN32                0b000101000000
# define CONTROL_GAIN64                0b000110000000
# define CONTROL_GAIN128               0b000111000000
# define CONTROL_CH2                   0b000000100000
# define CONTROL_24BIT                 0b000000001000
# define CONTROL_UNIPOLAR              0b000000000001
# define CONTROL_DEFAULT               0b000000000000
# define FREQUENCY_CODE                0b000001100100 //100

# define AD_CONTROL (CONTROL_SELF_CALIBRATION | CONTROL_24BIT | CONTROL_UNIPOLAR | CONTROL_GAIN128)

/* Sample is 24 bit / 8 = 3 bytes */
typedef byte sample[3];

sample ad_value = {0,0,0};
sample ad_config = {0,0,0};

void setup() {
  // SPI settings
/*SPI.begin();
SPI.setDataMode(SPI_MODE0); //Mode 0
SPI.setClockDivider(SPI_CLOCK_DIV8);
SPI.setBitOrder(MSBFIRST);*/
delay(10);

Serial.begin(115200);

/* Setting up pins */
  pinMode (aZero, OUTPUT);
  pinMode (RFS, OUTPUT);
  pinMode (TFS, OUTPUT);
  pinMode (DRDY, INPUT);
  pinMode (SCLK, OUTPUT);
  pinMode (SDATA, INPUT);



  Serial.println("Attach write pin in 10sec");
//delay(10000);
ad_configure();
Serial.println("Configuration is done!");
Serial.println("Attach read pin in 10sec");
//delay(10000);
Serial.println("Reading control register...");
ad_read_control_register();
Serial.println(ad_value[0],BIN);
Serial.println(ad_value[1],BIN);
Serial.println(ad_value[2],BIN);
}

void loop() {
  
  ad_sample(true);

/*Serial.println(ad_value[0],BIN);
Serial.println(ad_value[1],BIN);
Serial.println(ad_value[2],BIN);*/
uint32_t volt  = 0;
uint32_t volt1 = 0;
uint32_t volt2 = 0;

volt = ad_value[0];
volt = volt << 16;
volt1 = ad_value[1];
volt1 = volt1 << 8;
volt2 = ad_value[2];
volt |= volt1;
volt |= volt2;
/*Serial.println(volt,BIN);
Serial.println(volt,HEX);*/
Serial.println(volt);
double voltage = 0;
  voltage = volt * 2.5 / 16777215.0;
 Serial.print(voltage , 8);
  Serial.print(" ");
  Serial.println("volt");
delay(100);
}


  void ad_configure(){
    pinMode (SDATA, OUTPUT);
    
    digitalWrite (aZero, HIGH);
    digitalWrite (RFS, HIGH);
    digitalWrite (TFS, HIGH);

      /*
   * Activate 24 BIT words, self-calibration and set up notch
   * frequency.
   *
   */
   delay(100);
   digitalWrite (TFS, LOW);
   digitalWrite (aZero, LOW);
   delay (100);

// Build control configuration, total of 24 bits.
   unsigned long ctb = 0;
     ctb  = (unsigned long) AD_CONTROL << 12;
  ctb |= (unsigned long) FREQUENCY_CODE;
  Serial.println(ctb,BIN);

  for (int i = 2; i >= 0; i--) {

    byte b = ctb >> (8*i);
    shiftOut (SDATA, SCLK, MSBFIRST, b);
    //SPI.transfer(b);
  }
    delay (1);
    digitalWrite (TFS, HIGH);
    digitalWrite (aZero, HIGH);
    delay (1);

  /* Waiting for calibration to finish */
  while (digitalRead(DRDY)) delay(1);

  pinMode(SDATA, INPUT);
  
    }

    void ad_read_control_register ()
{


  /* Get control register */
  digitalWrite (aZero, LOW);
  delay(1);

  ad_sample (true); // Empty output register (see above)
  ad_sample (true);

  for (int i = 0; i < 3; i ++)
    ad_config[i] = ad_value[i];

  digitalWrite (aZero, HIGH);
  delay (1);

}

void ad_sample ()
{
  digitalWrite (RFS, LOW);

  // TODO: Check timing requirements from RFS HIGH to data ready.
  //       And check if that works in interrupt mode..

  /* Shift 24 bits = 3 bytes in from AD serial register */

  for (int i = 0; i < 3; i++)
    ad_value[i] = shiftIn (SDATA, SCLK, MSBFIRST);
  //ad_value[i] = SPI.transfer(0x00);
  digitalWrite (RFS, HIGH);
}

/* Version of sample that waits for DRDY */
void ad_sample (bool blocking)
{
  if (blocking)
    while (digitalRead(DRDY)) delayMicroseconds(1);

  return ad_sample ();
}

    void ad_read_data_register ()
{

  /* Get control register */
  digitalWrite (aZero, HIGH);
  delay(1);

  ad_sample (true); // Empty output register (see above)
  ad_sample (true);

  /*for (int i = 0; i < 3; i ++)
    ad_config[i] = ad_value[i];*/

  digitalWrite (aZero, HIGH);
  delay (1);
}

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 

I just made my Arduino Uno talk to AD7710 using the standard Arduino SPI interface. As mentioned in the AD7710 datasheet, you short the Arduino's MISO and MOSI pins together and connect them to SDATA on the AD7710.

 

Some things to note: 

 

  1. As mentioned earlier, MOSI must be isolated somehow, otherwise there will be bus contention. My solution is to set MOSI to input whenever it is not transmitting. I tried with a 10k resistor but it doesn't seem to be working
  2. Max frequency of the AD7710 interface is 2MHz, and the SPI mode which works with AD7710 is MODE1 (CPOL=0, CPHA=1). We can configure this using
    SPI.beginTransaction(SPISettings(2E6, MSBFIRST, SPI_MODE1));

Full code sample (just helps u read and write to the ADC control register, and output to serial port, doesn't mess with actual data processing)

#include <SPI.h>

#define SCK 13
#define MISO 12
#define MOSI 11
#define nDRDY 10
#define nRFS 9
#define nTFS 8
#define A0 7
#define TRIGGER 3

void setup() {
  // initialize ADC interface pins
  pinMode(nDRDY, INPUT);
  pinMode(nRFS, OUTPUT);
  pinMode(nTFS, OUTPUT);
  pinMode(A0, OUTPUT);

  digitalWrite(nRFS, HIGH);
  digitalWrite(nTFS, HIGH);
  digitalWrite(A0, HIGH);

  SPI.begin();
  SPI.beginTransaction(SPISettings(2E6, MSBFIRST, SPI_MODE1));
  pinMode(MOSI, INPUT); // set MOSI to hi-z when not transmitting
  delay(1);
  adc_write();
  Serial.begin(9600);
  Serial.println(F("Begin test..."));
}

void loop() {
  adc_read();
  //SPI.transfer(0x00);
  //delay(1000);
  //adc_write();
  delay(1000);
}

void adc_write() {
  pinMode(MOSI, OUTPUT); // set MOSI to output to transmit

  digitalWrite(A0, LOW);    // write to 24-bit control register
  digitalWrite(nTFS, LOW);

  SPI.transfer16(0xA103); // test message
  SPI.transfer(0x71); // test message

  digitalWrite(nTFS, HIGH);
  pinMode(MOSI, INPUT); // set MOSI to hi-z when done transmitting
}

void adc_read() {
  unsigned long a;
  byte b;
  pinMode(MOSI, INPUT); // set MOSI to hi-z when not transmitting
  digitalWrite(A0, LOW);
  digitalWrite(nRFS, LOW);
  a = SPI.transfer16(0x00);
  b = SPI.transfer(0x00);

  digitalWrite(nRFS, HIGH);

  Serial.println(a, HEX);
  Serial.println(b, HEX);
}

 

Last Edited: Mon. Oct 9, 2017 - 02:37 AM