[SOLVED] Problems with SPI 12-bit Dual DAC (LTC1454)

dhenry:
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:

#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.

Hi,

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,

Regards,

Tom