Hi all, I've got a Due connected to an Analog Devices AD420 DAC chip via SPI. My circuit for the IC is that of figure 6 on page 10 of the datasheet (http://www.analog.com/media/en/technical-documentation/data-sheets/AD420.pdf). SPI lines are hooked up as in figure 11, using pin 4 on the Due for my CS.
The problem I am having is that the SPI seems to work intermittently. My code is below, I'm toggling between 4, 8, 12, and 16 mA across a 250 ohm resistor, measuring the voltage on my multimeter. Sometimes it'll work and go 1, 2, 3, 4 (volts) as expected, other times it just stays at 1, other times, it'll blip up to 1.2 and back down to 1. I am certain about the bit order and SPI mode (from the datasheet). I've experimented with different clock divider values and even delays between sending bytes, nothing seems to make much of a difference.
I tried putting 470 pF capacitors on the SPI lines at the advice of someone else on here to curb fast rising edges on the clocks/data, didn't help either. Tried different cap values to some extent, didn't help. It's very strange, I just can't seem to find the pattern. I'm thinking that the problem is electrical vs. software because the only thing I've seemed to notice is that sort of "playing around" with the circuit seems to trigger periods of working operation, i.e. inserting or removing capacitors on the SPI lines. Next stop is buying an oscilloscope.
Any ideas before I sink money into that?
#include <SPI.h>
#define SS_PIN 4
unsigned int i;
void setup()
{
SPI.begin(SS_PIN);
SPI.setClockDivider(SS_PIN, 96);
SPI.setBitOrder(SS_PIN, MSBFIRST);
SPI.setDataMode(SS_PIN, SPI_MODE0);
i = 0;
}
void loop()
{
SPI.transfer(SS_PIN, 0x40*((i++)%4), SPI_CONTINUE);
//delayMicroseconds(1);
SPI.transfer(SS_PIN, 0x00);
delay(1500);
}