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();
}