Arduino Due with AD5293

Hello Guys,

so I have been researching this topic for days now. There are a few topics available. But it seems, everyone just stops posting right before they have solved the problem. Here are a few Forums with this topic.

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

So my setup consists of an Arduino Due and an AD5293. Datasheet to be found here.

AD5293 Datasheet

I have connected the circuit as shown in the attachment and this is my piece of code.

#include <SPI.h>

const int slaveSelectPin = 10;

void setup() {
  pinMode (slaveSelectPin, OUTPUT);
  SPI.setDataMode(SPI_MODE1);
  SPI.setBitOrder(MSBFIRST);
  SPI.setClockDivider(SPI_CLOCK_DIV4);
  SPI.begin();
  Serial.begin(9600);
  
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(0x18);
  SPI.transfer(0x02);
  digitalWrite(slaveSelectPin,HIGH);

 // Transfer 0x500 to set to 1/4 full-scale
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(0x05); // 1/4 fullscale
  SPI.transfer(0x00);
  digitalWrite(slaveSelectPin,HIGH);
}

void loop() {
  unsigned int val;
  for (val = 0; val <= 1023; val++) {
    digitalPotWrite(val);
    delay(10);
  }
  for (val = 1023; val > 0; val--) {
    digitalPotWrite(val);
    delay(10);
  }
}

void digitalPotWrite(unsigned int val) {
  digitalWrite(slaveSelectPin, LOW);
  byte highbyte = val >> 8 + 0x04; //high wiper byte + command
  byte lowbyte = val & 0xFF;
  SPI.transfer(highbyte); //send wiper data high byte
  SPI.transfer(lowbyte); //send wiper data low byte
  digitalWrite(slaveSelectPin, HIGH);
  SPI.endTransaction();
}

So what am I doing wrong here?? I can't get the Wiper position to move from half position. I tried to just send the 1/4 full-scale in setup commenting the rest of it out. But even that doesn't seem to work. Any help is appreciated. Thank you soo much.

P.S. About the circuit, the external PS provides 24V. The ground is connected to the Arduino Gnd. I tried without the capacitors. So I included them recently. The SPI pins are connected to the 6 pin SPI header in the center of Arduino.

Why do you call SPI.endTransaction()? You never called SPI.beginTransaction(), so there is no transaction to end.

Did you connect the grounds ?

@PaulS: Hmm.. Thats true. i removed it. There are a begin statement earlier that I took out. It does not have any influence on the rest of the program though.

@ard_newbie: Yes both the Arduino and the external Power Supply grounds are shorted.

It seems that the AD5293 digital potentiometer works in SPI mode with CPOL = 0 and CPHA = 1, however you selected SPI_MODE1. Although this is not a standard designation, you should try SPI_MODE0, or the other 2 modes if it still doesn't work ( see Sam3x datasheet page 680)

Alright.. Figured it out. I guess the important statement is the SPI.beginTransaction(Settings) one. It initializes the SPI bus to the specified settings.

@ard_newbie You are right. The AD5293 works in SPI mode with CPOL = 0 and CPHA = 1. But that is SPI_MODE1. Check the Arduino documentation here.

The final code is here.

#include <SPI.h>

const int slaveSelectPin = 10;

void setup() {
  pinMode (slaveSelectPin, OUTPUT);
  SPI.begin();
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE1));
  Serial.begin(9600);
  
  
  digitalWrite(slaveSelectPin,LOW);
  SPI.transfer(0x18);
  SPI.transfer(0x02);
  digitalWrite(slaveSelectPin,HIGH);
  SPI.endTransaction();
}

void loop() {
  unsigned int val;
  for (val = 0; val <= 1023; val++) {
    digitalPotWrite(val);
    delay(100);
  }
  for (val = 1023; val > 0; val--) {
    digitalPotWrite(val);
    delay(100);
  } 
}

void digitalPotWrite(unsigned int val) {
  SPI.beginTransaction(SPISettings(SPI_CLOCK_DIV4, MSBFIRST, SPI_MODE1));
  digitalWrite(slaveSelectPin, LOW);
  byte highbyte = (val >> 8) + 0x04; //high wiper byte + command
  byte lowbyte = val & 0xFF;
  SPI.transfer(highbyte); //send wiper data high byte
  SPI.transfer(lowbyte); //send wiper data low byte
//  Serial.print(highbyte, HEX);
//  Serial.println(lowbyte, HEX);
  digitalWrite(slaveSelectPin, HIGH);
  SPI.endTransaction();
}