Trouble with SPI DAC...

Hey folks,

I'm hoping I could get a little help with some code to get a DAC (AD5644) to work with an arduino over SPI. More specifically, I'm having issues with the command and address bits in the first byte.

Here is the basic sketch I am trying out just to test things:

#include "SPI.h"


const int SSpin = 10;
byte firstbyte = 0;
byte secondbyte = 0;
byte commandbyte = 0;
byte resetbyte = 0;
word word1 = 0;




void setup()
{
  pinMode(SSpin, OUTPUT);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(0);
}


void loop()
{
  digitalWrite(SSpin,LOW);
  commandbyte = 0b00001111;
  SPI.transfer(commandbyte);
  firstbyte = 0b00011111;
  secondbyte = 0b11111111;
  SPI.transfer(firstbyte);
  SPI.transfer(secondbyte);
  digitalWrite(SSpin,HIGH);
  delay(1000);
  digitalWrite(SSpin,LOW);
  commandbyte = 0b00001111;
  SPI.transfer(commandbyte);
  word1 = 0;
  firstbyte = highByte(word1);
  secondbyte = lowByte(word1);
  SPI.transfer(firstbyte);
  SPI.transfer(secondbyte);
  digitalWrite(SSpin,HIGH);
  delay(1000);
  
}

All this does is flash all DAC outputs on and off, which makes sense, but when I replace the first byte with something like 0b00001000, which should write to DAC A of the converter, it flashes on DAC B, or when I try 0b00001010 for output on DAC C, it outputs to all DAC outs. I have not been able to isolate outputs DAC A or DAC C yet.

I'm sure I'm missing something pretty basic, but any suggestions or guidance would be really helpful!

Could your bit order be backward? That will mess with your bit patterns.

Thanks for replying,

Yeah, I've tried MSBFIRST and LSBFIRST and the later doesn't seem to work at all. Any other suggestions?