Arduino Due interfacing with AD7705 problem?

Hello geek

I have wrote a code of interfacing AD7705 with Arduino due,i am not getting any errors thou!
but i am unable to get any output.Can anyone highlight me where i am going wrong and what need to changed in the code

Here is the code:

#include <SPI.h>
 uint32_t pwmPin = 6;                                                                            
uint32_t maxDutyCount = 42000000/2000000; //2;
uint32_t clkAFreq = 42000000ul;
uint32_t pwmFreq = 42000000ul;

//const int drdy = 6;

//const int cs = 10;

//const int freqOutputPin = 3; 
#define CS 10
#define DOUT 11
#define DIN 12
#define SCLK 13
#define DRDY 7


//const int ocr2aval  = 3;

 

 

//const int prescale  = 1;

//const float period    = 2.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6);

//const float freq      = 1.0e6 / period;

 

 

void setup()

{

  //pinMode(freqOutputPin, OUTPUT);

  Serial.begin(9600);

  SPI.begin();

  //SPI.beginTransaction(SPISettings(200,MSBFIRST,SPI_MODE0));

  pinMode(DRDY,INPUT);

  pinMode(CS,OUTPUT);

  digitalWrite(CS,LOW);



  pmc_enable_periph_clk(PWM_INTERFACE_ID);
  PWMC_ConfigureClocks(clkAFreq, 0, 2*clkAFreq); //VARIANT_MCK);
  PIO_Configure(
    g_APinDescription[pwmPin].pPort,
    g_APinDescription[pwmPin].ulPinType,
    g_APinDescription[pwmPin].ulPin,
    g_APinDescription[pwmPin].ulPinConfiguration);
  uint32_t channel = g_APinDescription[pwmPin].ulPWMChannel;
  PWMC_ConfigureChannel(PWM_INTERFACE, channel , pwmFreq, 0, 0);
  PWMC_SetPeriod(PWM_INTERFACE, channel, maxDutyCount);
  PWMC_EnableChannel(PWM_INTERFACE, channel);
  PWMC_SetDutyCycle(PWM_INTERFACE, channel, maxDutyCount/2); //1);
  pmc_mck_set_prescaler(42);
}

void loop()
{


  writetoadc(0x20);

  delay(100);

  writetoadc(0x03);

  delay(100);

  writetoadc(0x10);

  delay(100);

  writetoadc(0x40);

  delay(100);


 

 

//void loop()

//{
while(digitalRead(DRDY) == 1)
  //while(digitalRead(drdy)==1);

  writetoadc(0x38);

  int value = getadcdata();

  //Serial.print("Value:");

  //Serial.println(value);

}

 

 

void writetoadc(byte command)

{

  SPI.transfer(command);

  //SPI.endTransaction();

  digitalWrite(MOSI,HIGH);

  return;

}

 

 

int getadcdata()

{

  unsigned int result = 0;

  byte input = 0;

  result = SPI.transfer(0x00);

  result = result << 8;

  input = SPI.transfer(0x00);

  result = result | input;

  //SPI.endTransaction();

  //digitalWrite(MOSI,HIGH);

  return (result);

}

Hello guys

I am finding a problem getting a output for the interfacing AD7705.i have a written a code,thou there is no error.
Please anyone can guide me through my mistakes and can give any suggestion.would be great help for me.
Thank you

#include <SPI.h>
 uint32_t pwmPin = 6;                                                                            
uint32_t maxDutyCount = 42000000/2000000; //2;
uint32_t clkAFreq = 42000000ul;
uint32_t pwmFreq = 42000000ul;

//const int drdy = 6;

//const int cs = 10;

//const int freqOutputPin = 3; 
#define CS 10
#define DOUT 11
#define DIN 12
#define SCLK 13
#define DRDY 7


//const int ocr2aval  = 3;

 

 

//const int prescale  = 1;

//const float period    = 2.0 * prescale * (ocr2aval+1) / (F_CPU/1.0e6);

//const float freq      = 1.0e6 / period;

 

 

void setup()

{

  //pinMode(freqOutputPin, OUTPUT);

  Serial.begin(9600);

  SPI.begin();

  //SPI.beginTransaction(SPISettings(200,MSBFIRST,SPI_MODE0));

  pinMode(DRDY,INPUT);

  pinMode(CS,OUTPUT);

  digitalWrite(CS,LOW);



  pmc_enable_periph_clk(PWM_INTERFACE_ID);
  PWMC_ConfigureClocks(clkAFreq, 0, 2*clkAFreq); //VARIANT_MCK);
  PIO_Configure(
    g_APinDescription[pwmPin].pPort,
    g_APinDescription[pwmPin].ulPinType,
    g_APinDescription[pwmPin].ulPin,
    g_APinDescription[pwmPin].ulPinConfiguration);
  uint32_t channel = g_APinDescription[pwmPin].ulPWMChannel;
  PWMC_ConfigureChannel(PWM_INTERFACE, channel , pwmFreq, 0, 0);
  PWMC_SetPeriod(PWM_INTERFACE, channel, maxDutyCount);
  PWMC_EnableChannel(PWM_INTERFACE, channel);
  PWMC_SetDutyCycle(PWM_INTERFACE, channel, maxDutyCount/2); //1);
  pmc_mck_set_prescaler(42);
}

void loop()
{


  writetoadc(0x20);

  delay(100);

  writetoadc(0x03);

  delay(100);

  writetoadc(0x10);

  delay(100);

  writetoadc(0x40);

  delay(100);


 

 

//void loop()

//{
while(digitalRead(DRDY) == 1)
  //while(digitalRead(drdy)==1);

  writetoadc(0x38);

  int value = getadcdata();

  //Serial.print("Value:");

  //Serial.println(value);

}

 

 

void writetoadc(byte command)

{

  SPI.transfer(command);

  //SPI.endTransaction();

  digitalWrite(MOSI,HIGH);

  return;

}

 

 

int getadcdata()

{

  unsigned int result = 0;

  byte input = 0;

  result = SPI.transfer(0x00);

  result = result << 8;

  input = SPI.transfer(0x00);

  result = result | input;

  //SPI.endTransaction();

  //digitalWrite(MOSI,HIGH);

  return (result);

}

You don't tell us where you are expecting an output?
The AD7705 is an ADC and expect analog input and will give a digital output to the DUE.

mark07:
Hello guys

I am finding a problem getting a output for the interfacing AD7705.i have a written a code,thou there is no error.
Please anyone can guide me through my mistakes and can give any suggestion.would be great help for me.
Thank you

Backup a little and tell us exactly what you are attempting to do.
A Wiring diagram would be good to have.

also using the Arduino IDE there is an option to format the sketch/code for the forums.

formatted sketch/code is easier to read without having to reformat it myself.

There is an Instructable for interfacing AD7705 with an UNO, this might help:

Provided you really need 16-bit ADC conversions at 500 sps, you can achieve this with your builtin ADC channels on the DUE. You will have to oversample and average accordingly to obtain 16-bit conversions from 12-bit conversions.

From the Silicon Labs Application Note AN118(IMPROVING ADC RESOLUTION BY OVERSAMPLING AND AVERAGING):

Assume a system is using a 12-bit ADC to output a
temperature value once every second (1 Hz). To
increase the resolution of the measurement to 16-
bits, we calculate the oversampling frequency as
follows:
fos = 4pow4 * 1Hz = 256Hz
Thus, if we oversample the temperature sensor at
fs=256 Hz, we will collect enough samples within
the required sampling period to average them and
can now use 16-bits of the output data for a 16-bit
measurement. To do so, we accumulate (add 256
consecutive samples together), then divide the total
by 256. Such a process
is commonly referred to as decimation.
This results in 16-bits of useful data. Such an operation
is referred to as accumulate and dump.

If fs = 500 Hz, fos = 128 KHz, well below the maximum conversion frequency of your builtin ADCs.

Moderator mode: added code tags - please check how to post code (in firsts topic in every section)

Cross posted here:

https://forum.arduino.cc/index.php?topic=523280.0

What is the explanation for all the commented out lines?

cross posts merged