Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 #include <SPI.h> // SYNC is called SS here, according to SPI library terminology const int LDAC = 7; // pin 7 const int CLR = 6; // pin 6 const int RESET = 8; // pin 8 void setup() { pinMode(SS,OUTPUT); pinMode(LDAC, OUTPUT); pinMode(CLR, OUTPUT); pinMode(RESET, OUTPUT); digitalWrite(LDAC, LOW); digitalWrite(CLR, HIGH); digitalWrite(RESET, HIGH); SPI.begin(); SPI.beginTransaction(SPISettings(30000000,MSBFIRST,SPI_MODE2)); } void setDACVal() { digitalWrite(SS,LOW); SPI.transfer(B00010111); // first Byte which includes configured bits for DAC register address (writing - 0001) SPI.transfer(B11111111); // second Byte (DC signal) SPI.transfer(B00000000); // third Byte (more bits of DC signal configuration), so total of 24 bits have been sent digitalWrite(SS,HIGH); } void loop() { setDACVal(); }
I cannot seem to get an output from the DAC,
If I understand correctly, AD5781 has to be configured before use. From the datasheet, page 25/29:Just checking in again -- can you see any errors in my code above, based on what I am trying to do here, as described in the former posts in this thread?
Code C - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 #include <SPI.h> // SYNC is called SS here, according to SPI library terminology const int LDAC = 7; // pin 7 const int CLR = 6; // pin 6 const int RESET = 8; // pin 8 void setup() { pinMode(SS,OUTPUT); pinMode(LDAC, OUTPUT); pinMode(CLR, OUTPUT); pinMode(RESET, OUTPUT); digitalWrite(LDAC, LOW); digitalWrite(CLR, HIGH); digitalWrite(RESET, HIGH); SPI.begin(); SPI.beginTransaction(SPISettings(8000000,MSBFIRST,SPI_MODE2)); // 8 MHz operation digitalWrite(SS,LOW); SPI.transfer(B00100000); // MSB of 0010 means write to control register SPI.transfer(B00000000); // all reserved bits are 0 SPI.transfer(B00000010); // clear the DACTRI and OPGND bits so that DAC is in normal operating mode digitalWrite(SS,HIGH); } void setDACVal() { digitalWrite(SS,LOW); SPI.transfer(B00010111); // first Byte which includes configured bits for DAC register address (writing - 0001) SPI.transfer(B11111111); // second Byte (DC signal) SPI.transfer(B00000000); // third Byte (more bits of DC signal configuration), so total of 24 bits have been sent digitalWrite(SS,HIGH); } void loop() { setDACVal(); }
Can you please review the code and let me know if I have done this correctly?
Or is there a clear flaw in my code that I'm not catching? Please help.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?