Digital to Analog converter with DAC5311, Any suggestion? I made my DAC code with DAC5311 and Arduino Uno.
I think it has no problem, but it doesn't work well. Just print 0.(I use an oscilloscope.)
I don't know where has the problem. Please give me any suggestion.

#include &lt;SPI.h&gt;
#include &lt;math.h&gt;
#define pin_CS 10
#define pin_MOSI 11 
#define pin_SCLK 13
#define max_VOLT 5

void setVoltage(float voltage){
  if (voltage &lt; 0) voltage = 0;
  if (voltage &gt; max_VOLT) voltage = max_VOLT;
  uint16_t temp = int(voltage * pow(2, 8) / max_VOLT);
  temp = temp &lt;&lt; 6;
  uint8_t upper = temp &gt;&gt; 8;
  uint8_t lower = (temp &amp; 0xff);
  digitalWrite(pin_CS, LOW);
  SPI.transfer(upper);
  SPI.transfer(lower);
  digitalWrite(pin_CS, HIGH); 
}

void setup() {
  Serial.begin(9600);
  pinMode(pin_CS, OUTPUT);
  pinMode(pin_MOSI, OUTPUT);
  pinMode(pin_SCLK, OUTPUT);              
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  digitalWrite(pin_CS, HIGH);
}

void loop() {
  setVoltage(5);
  delay(10);
}
Classical +/- 1 problem

If you do this calculation by hand uint16_t temp = int(voltage * pow(2, 8) / max_VOLT);
you will get temp=256 and this is a value you can not convert with a 8 bit DAC.

Try uint16_t temp = int(voltage * (pow(2, 8)-1) / max_VOLT); instead.

(or event better for a µC uint16_t temp = (uint16_t) (voltage * (255 / max_VOLT));)