Hello everyone,
for my project I have to implement SPI communication for LTC2664 DAC with my Arduino Mega2560. I created a simple code to debug communication which should drive the output channel 0 to a certain constant voltage level.
According to datasheet (if I understood well) the frame to be sent is:
command code (4 bit): 0011 (Write Code to channel n, Update channel n (Power Up))
address code (4 bit): 0000 (channel 0)
data code (16 bit): 1100000000000000 (decimal 49152 for around 5V output with +-10V range hardware selected)
total frame (24 bit): 0011 0000 1100000000000000 - 30 C0 00
//Arduino SCK D52 - LTC2664 SCK
//Arduino MISO D50 - LTC2664 SDO
//Arduino MOSI D51 - LTC2664 SDI
//Arduino D42 - LTC2664 CS
//Arduino D43 - LTC2664 TGP
#include <SPI.h>
SPISettings mySetting(500000, MSBFIRST, SPI_MODE0);
const uint8_t ss = 42;
const uint8_t tgp = 43;
byte frame[3] = {0x30, 0xC0, 0x0};
int wait = 10;
int wait_1 = 100;
void SendSPICommand(byte frame[3], int del, int del_1) {
byte result;
Serial.print("Output frame is: ");
digitalWrite(ss, LOW);
delayMicroseconds(del_1);
result = SPI.transfer(frame[0]);
delayMicroseconds(del);
Serial.print(result,HEX);
result = SPI.transfer(frame[1]);
delayMicroseconds(del);
Serial.print(result,HEX);
result = SPI.transfer(frame[2]);
Serial.print(result,HEX);
Serial.print(" - ");
delayMicroseconds(del_1);
digitalWrite(ss, HIGH);
delayMicroseconds(del_1);
}
void setup() {
Serial.begin(9600);
pinMode(ss, OUTPUT);
pinMode(tgp, OUTPUT);
digitalWrite(ss, HIGH);
digitalWrite(tgp, LOW);
Serial.print("Input frame is: ");
Serial.print(frame[0],HEX);
Serial.print(" - ");
Serial.print(frame[1],HEX);
Serial.print(" - ");
Serial.print(frame[2],HEX);
Serial.println(" ");
SPI.setClockDivider(SPI_CLOCK_DIV128);
SPI.begin();
SPI.beginTransaction(mySetting);
SendSPICommand(frame, wait, wait_1);
SPI.endTransaction();
SPI.end();
}
void loop() {
}
Trying this on my LTC2664 board I always readback 0 in SDO and no voltage output appears. Things are not working.
I was wondering if you have any experience on this device and if you can give some suggestion to solve my issue.
Thank you