Okay, I'm a bit stuck here. I cant get my Arduino to communicate via SPI with a DAC and could really use some advice or direction.
I recently acquired the MCP4912 two channel DAC (data sheet = http://ww1.microchip.com/downloads/en/DeviceDoc/22250A.pdf). Programming my Arduino to talk to this DAC seemed straight forward but I'm having a really difficult time making it happen. Here are the specific problems I'm having:
I cant seem to definitively establish whether this DAC uses MSB or LSB to communicate
I dont know how to use the SPI.h library to send 16 bits of data
I'm not sure what speed to set the SPI clock to
I've sifted through the data sheet and found what bit corresponds to what function:
0 through 1 = n/a
2 through 11 = output voltage value
12 = shutdown switch (I want to set to 1)
13 = gain switch (I want to set to 1)
14 = buffer switch (I want to set to 0)
15 = A or B channel switch (A = 0 and B = 1)
I'm just toying around with this thing but here's the code thus far:
You also need to ensure you take the chip out of shutdown mode. Bit 12 must be 1. Also, make sure the LDAC pin is tied to ground, or you are driving it properly to transfer the voltage settings to the outputs.
Wow! A lot of extremely helpful responses! Thank you everybody for helping me verify that this IC uses MSB.
And thank you very much for your help majenko! As soon as I loaded your library it worked perfectly! Predictable and easy to integrate for a noob, like myself. This library you created is going to save me a lot of time and coding! Thank you again for making that available!
I will also set the LDAC latch to ground.
majenko:
I have knocked up a little library for this family of chips: