Go Down

Topic: [SOLVED] Problems with SPI 12-bit Dual DAC (LTC1454) (Read 2 times) previous topic - next topic


Here is the code I would use. This sends 0x0123 to dacA, and 0x0789 to dacB.
Code: [Select]
void setup() {
  int dacA = 0x0123;
  int dacB = 0x0789;
  byte spiA,spiB,spiC;
  // shift 0x0123 to 0x1230
  dacA = dacA << 4;

  // put the high 8 bits dacA in spiA
  spiA = highByte(dacA);

  // put low 4 bits dacA with high 4 bits dacB
  spiB = lowByte(dacA) | highByte(dacB);

  // put low 8 bits dacB in spiC
  spiC = lowByte(dacB);

  Serial.print("spiA = ");Serial.println(spiA,HEX);
  Serial.print("spiB = ");Serial.println(spiB,HEX);
  Serial.print("spiC = ");Serial.println(spiC,HEX);

void loop() {


Jan 19, 2013, 02:35 pm Last Edit: Jan 19, 2013, 02:38 pm by tomfleet Reason: 1

You probably didn't read the datasheet before you coded.

The transfer is 12-bit Ch-A, then 12-bit Ch-B, msb first.

If I were you, I would write a macro or a function to perform that, like this:

Code: [Select]
#define ltc1454_write(word_a, word_b) do {spi_write((word_a) >> 4); spi_write(((word_a) << 4) | ((word_b) >> 4)); spi_write(word_b);} while (0)

so ltc1454_write(0x01f5, 0x0255); willl send 0x1f5 to channel a, and 0x0255 to channel b.

If you ever want to work with a device, you have to read its datasheet thoroughly.

Or there is no hope.


I'd somehow think I'd be having larger problems, had I not read the datasheet at all! Points for suggesting that I had probably not read it correctly though! I had originally gotten the channel transfer ordered correctly, I was just getting in such a twist last night that I made a silly mistake in trying to correct some code that was fundamentally flawed elsewhere.

Thanks to both of you for correcting my understanding of the SPI data transfer, I had not thought to concatenate the two 12-bit words into 3 bytes, as suggested. I will be giving this a shot right now. Both your examples of bit-shifting the bytes make the required actions very clear to me now!

Thanks again for the explanations,




Hi guys,

Just wanted to say thanks again, the code has been adjusted accordingly, and my scope is showing 3 perfect, phase-shifted sine waves  :)

Thanks again for the pointers.




Do you still have the code you used to solve this problem?

Thanks a lot,
L'impossibile...richiede solo piu' tempo!

Go Up