1

enter image description here

I have to write 0xA5 to the DAC. So should I send 0x00100A50 or 0x001A5000? The command bits are 0x0 as i just want to write to the buffers. Say I want to send to channel 1 with channel Address 1 (D23 to D20 & the Don't Care bits are taken as 0. I am having this confusion because I am not familiar with left aligned binary data. If 0x001A5000 is the correct one, How can I write 0xA500 to the DAC?

Ashik
  • 13
  • 3

1 Answers1

0

What the left aligned data really means is that for the 70004, you have 14 bits Data followed by 2 bits of what is likely "Don't care" and for 60004, you have 12 bits Data followed 4 likely "Don't care" bits (adjacent to the mode bits). This "left aligned" mention allowed TI to fit all the info for three different devices into a single table.

Take care to also get the rest of the bit and byte order correct, as well as order of bits on the line.

Easiest way to read TI doc here is as a 32-bit entity. We'll suppose this uint32 serves that purpose:

uint32_t spicmd;

void SetRW(uint8_t RW){ //Treating don't cares as part of RW since it's easier to read in hex spicmd &= 0xFFFFFFF;//remove old bits spicmd |= ((uint32_t)RW) << 28;//set new bits; extra bits go over msb so no need to remove } void SetCommand(uint8_t RW){ //Treating don't cares as part of RW since it's easier to read in hex spicmd &= 0xFFFFFFF;//remove old bits spicmd |= ((uint32_t)RW) << 28;//set new bits; extra bits go over msb so no need to remove } //... The part you are interested in: depends on which dac you have void SetDatDAC80004(uint16_t DAT){ //80004 is 16-bit so nothing so no shift spicmd &= 0xFFF0000F;//remove old bits spicmd |= ((uint32_t)DAT) << 4;//set new bits } void SetDatDAC70004(uint16_t DAT){ //70004 is 14/16 bits so shift 2; rest is same as 80004 //alternatively, you could just have treated the lsb of your DAC as 4 times what you would for the 80004 SetDatDAC80004(DAT << 2); } void SetDatDAC60004(uint16_t DAT){ //60004 is 12/16 bits so shift 4; rest is same as 80004 //alternatively, you could just have treated the lsb of your DAC as 16 times what you would for the 80004 SetDatDAC80004(DAT << 4); }

//SPI is not inherently 32 bits so make sure your 32 bits goes out in the correct order

//Supposing you have the ability to send a spi byte extern void QueueSPIByte(uint8_t byte);

void QueueSPICmd(){ QueueSPIByte(spicmd >> 24); QueueSPIByte(spicmd >> 16); QueueSPIByte(spicmd >> 8); QueueSPIByte(spicmd); }

Abel
  • 1,524
  • 6
  • 12