Right, so I'm making a driver for the AD5024. A 4 channel DAC chip made by analog devices. Datasheet here: http://www.analog.com/static/imported-files/data_sheets/AD5024_AD5044_AD5064.pdf
Now, here's the trick. I have the chip working flawlessly on C# .NET Microframework. I am using very similar code with only a few tweaks to the variable types and of course the hardware interface changes.
NETMF driver: AD5024 NETMF driver - Pastebin.com
Failing Arduino driver: Arduino AD5024 driver (not working) - Pastebin.com
- I know the data bytes are being formed correctly. I did a Serial.print() in the loop that sends the SPI data, and I can clearly see everything is working properly. The issue exists in the SPI interface itself.
I am using the following code to begin the SPI bus:
pinMode(10, OUTPUT); // Slave select, so that
SPI.begin(); // SPI to DAC
SPI.setBitOrder(MSBFIRST);
SPI.setDataMode(SPI_MODE0);
SPI.setClockDivider(SPI_CLOCK_DIV16); // SPI clock 1000Hz
Keep in mind, this doesn't work no matter what mode is set to.
Now, to make troubleshooting a bit easier, I took scope grabs of the same command (ad5024Write(AD5024_COM_UPDATE_TO_N, AD5024_ADDR_DACD, 257);).
Note the difference between the NETMF (working) and the Arduino (obviously not working). For one, the clock is inverted, but a bigger one is in the HIGH blobs and their position under the clock.
NETMF:
Arduino:
Does anybody have ANY idea what on earth is going on here? I have 3 engineers totally stumped as to what I could change in the SPI lib to change this, or what could be going wrong.