user4759: I've been trying to work with an AD5685R DAC. Per that datasheet, to get DAC1 to output max voltage (5V), I would perform:
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3); // DAC uses CPHA=1, CPOL=1

digitalWrite(CS, LOW);
SPI.transfer(0x31); // upper nibble sends a "write and update" command, lower nibble says "DAC1"
SPI.transfer(0xFF);
SPI.transfer(0xFC); // 14-bit DAC, last 2 bits are dontcares, make them 0
digitalWrite(CS, HIGH);

Replace 0xFFFC with 0x0000 to get 0 volts out. 
Sending this command as written somehow writes to DAC4 instead of DAC1! and while 5V will come out when I write 0xFFFC, I get to 2.5V when writing 0x0000 instead of 0V. 
If I command this with a Bus Pirate and directly write the bytes out, it works exactly as desired. 
I used the Bus Pirate to sniff the SPI traffic and it turns out I'm not getting what I've commanded. Rather than 0x31 0x00 0x00 for instance, I get 0x18 0x80 0x00.
If we break this out into bits:
0x310000: 0011 0001 0000 0000 0000 0000 // commanded
0x188000: 0001 1000 1000 0000 0000 0000 // actually sent

So the command actually sent out is shifted by 1 bit!
Here's the bit pattern for 16383 counts (i.e., 2^14-1):
0x31FFFC: 0011 0001 1111 1111 1111 1100 // commanded
0x18FFFE: 0001 1000 1111 1111 1111 1110 // actually sent

The opcode corresponding to 0x18 is "write to input register 4" (the output occurs because I've pulled the /LDAC pin permanently low, see the datasheet), which explains why I'm getting an output on DAC4 instead of DAC1.
This occurs with both a Sparkfun Pro Micro and an Arduino Mega 2560. 
What is going on here? Why is the Arduino not sending out what I've actually commanded? Again, writing the hex codes directly to the DAC using a Bus Pirate works perfectly.

user10794: CPOL is clock polarity, and CPHA is clock phase.
The SPI modes are:

Mode 0 (the default) - clock is normally low (CPOL = 0), and the data is sampled on the transition from low to high (leading edge) (CPHA = 0)



Mode 1 - clock is normally low (CPOL = 0), and the data is sampled on the transition from high to low (trailing edge) (CPHA = 1)



Mode 2 - clock is normally high (CPOL = 1), and the data is sampled on the transition from high to low (leading edge) (CPHA = 0)



Mode 3 - clock is normally high (CPOL = 1), and the data is sampled on the transition from low to high (trailing edge) (CPHA = 1)



According to your datasheet:

Data from the SDIN line is clocked into the 24-bit input shift register on the falling edge of SCLK. 

Judging by the diagrams on the datasheet, Mode 1 is what you want. You want the trailing edge of high to low.
More information at SPI - Serial Peripheral Interface - for Arduino

4759: <p>I've been trying to work with an <a href="http://www.analog.com/static/imported-files/data_sheets/AD5686R_5685R_5684R.pdf" rel="nofollow">AD5685R DAC</a>. Per that datasheet, to get <code>DAC1</code> to output max voltage (5V), I would perform:</p>

<pre><code>SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE3); // DAC uses CPHA=1, CPOL=1

digitalWrite(CS, LOW);
SPI.transfer(0x31); // upper nibble sends a "write and update" command, lower nibble says "DAC1"
SPI.transfer(0xFF);
SPI.transfer(0xFC); // 14-bit DAC, last 2 bits are dontcares, make them 0
digitalWrite(CS, HIGH);
</code></pre>

<p>Replace <code>0xFFFC</code> with <code>0x0000</code> to get 0 volts out. </p>

<p>Sending this command as written somehow writes to <code>DAC4</code> instead of <code>DAC1</code>! and while 5V will come out when I write <code>0xFFFC</code>, I get to 2.5V when writing <code>0x0000</code> instead of 0V. </p>

<p>If I command this with a Bus Pirate and directly write the bytes out, it works exactly as desired. </p>

<p>I used the Bus Pirate to sniff the SPI traffic and it turns out I'm not getting what I've commanded. Rather than <code>0x31 0x00 0x00</code> for instance, I get <code>0x18 0x80 0x00</code>.</p>

<p>If we break this out into bits:</p>

<pre><code>0x310000: 0011 0001 0000 0000 0000 0000 // commanded
0x188000: 0001 1000 1000 0000 0000 0000 // actually sent
</code></pre>

<p>So the command actually sent out is shifted by 1 bit!</p>

<p>Here's the bit pattern for 16383 counts (i.e., 2^14-1):</p>

<pre><code>0x31FFFC: 0011 0001 1111 1111 1111 1100 // commanded
0x18FFFE: 0001 1000 1111 1111 1111 1110 // actually sent
</code></pre>

<p>The opcode corresponding to <code>0x18</code> is "write to input register 4" (the output occurs because I've pulled the <code>/LDAC</code> pin permanently low, see the datasheet), which explains why I'm getting an output on <code>DAC4</code> instead of <code>DAC1</code>.</p>

<p>This occurs with both a Sparkfun Pro Micro and an Arduino Mega 2560. </p>

<p>What is going on here? Why is the Arduino not sending out what I've actually commanded? Again, writing the hex codes directly to the DAC using a Bus Pirate works perfectly.</p>
 10794: <p>CPOL is clock <strong>polarity</strong>, and CPHA is clock <strong>phase</strong>.</p>

<p>The SPI modes are:</p>

<ul>
<li>Mode 0 (the default) - clock is normally low (CPOL = 0), and the data is sampled on the transition from low to high (leading edge) (CPHA = 0)</li>
</ul>

<p><img src="https://i.stack.imgur.com/6jUNq.jpg" alt="SPI Mode 0"></p>

<ul>
<li>Mode 1 - clock is normally low (CPOL = 0), and the data is sampled on the transition from high to low (trailing edge) (CPHA = 1)</li>
</ul>

<p><img src="https://i.stack.imgur.com/RYDAt.jpg" alt="SPI Mode 1"></p>

<ul>
<li>Mode 2 - clock is normally high (CPOL = 1), and the data is sampled on the transition from high to low (leading edge) (CPHA = 0)</li>
</ul>

<p><img src="https://i.stack.imgur.com/3bNek.jpg" alt="SPI Mode 2"></p>

<ul>
<li>Mode 3 - clock is normally high (CPOL = 1), and the data is sampled on the transition from low to high (trailing edge) (CPHA = 1)</li>
</ul>

<p><img src="https://i.stack.imgur.com/hnOoa.jpg" alt="SPI Mode 3"></p>

<hr>

<p>According to your datasheet:</p>

<blockquote>
  <p>Data from the SDIN line is clocked into the 24-bit input shift register on the falling edge of SCLK. </p>
</blockquote>

<p>Judging by the diagrams on the datasheet, Mode 1 is what you want. You want the trailing edge of high to low.</p>

<p>More information at <a href="http://www.gammon.com.au/spi" rel="nofollow noreferrer">SPI - Serial Peripheral Interface - for Arduino</a></p>
