DAC MCP4922

Merci Kamil, j'ai donc réduis le code au minimum sa donne sa:

#define DATAOUT 51//MOSI
#define SPICLOCK  52//sck
#define SLAVESELECT 53//ss

void setup()
{
  byte clr;
  pinMode(DATAOUT, OUTPUT);
// pinMode(DATAIN, INPUT);
  pinMode(SPICLOCK,OUTPUT);
  pinMode(SLAVESELECT,OUTPUT);
  digitalWrite(SLAVESELECT,HIGH); //disable device
  
  SPCR = (1<<SPE)|(1<<MSTR);
  clr=SPSR;
  clr=SPDR;
  //delay(10);


}

void write_value(uint16_t sample)
{
  uint8_t dacSPI0 = 0;
  uint8_t dacSPI1 = 0;
  dacSPI0 = (sample >> 8) & 0x00FF;
  dacSPI0 |= 0x10;
  dacSPI1 = sample & 0x00FF;
  digitalWrite(SLAVESELECT,LOW);
  SPDR = dacSPI0;                    // Start the transmission
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };
  
  SPDR = dacSPI1;
  while (!(SPSR & (1<<SPIF)))     // Wait the end of the transmission
  {
  };  
  digitalWrite(SLAVESELECT,HIGH);
  //delay(5);
}


void loop()
{
  
         write_value(1800);
   
}

le problème est que la sortie de mon DAC s'atture a 5V quand "Sample = 2000" alors que la valeur de mon "Val_Num_12" varie entre 0 et 4095 :confused:
je pourrai simplement la mapper dans cette intervalle mais j'aimerai comprendre pourquoi, "sample" ne va pas juska 4095 ( 12 bits)