Hi all, I've got a Due and I'm trying to use it with an AD420 DAC to produce a 4-20mA analog output. My circuit for the AD420 is the current output standard configuration (figure 6 in the datasheet: http://www.analog.com/media/en/technical-documentation/data-sheets/AD420.pdf), and I have MOSI (Due) connected to DATA IN (AD420), SCK to CLOCK, and pin 4 (CS) to LATCH.
From the datasheet: 3.3 Mbps max, MSB first, data shifted in on rising edge, and clock idle on low, so I thought SPI_MODE1 (which worked for a few values), eventually tried SPI_MODE0 which seemed to work more often.
Here's the code I'm using:
#include <SPI.h>
#define SS_PIN 4
int i;
void setup()
{
SPI.begin(SS_PIN);
SPI.setClockDivider(SS_PIN, 168);
SPI.setBitOrder(SS_PIN, MSBFIRST);
SPI.setDataMode(SS_PIN, SPI_MODE0);
i = 0;
}
void loop()
{
SPI.transfer(SS_PIN, 0x40*((i++)%4), SPI_CONTINUE); // toggling between 4, 8, 12, and 16 mA
SPI.transfer(SS_PIN, 0x00);
delay(2000);
}
The problem I'm having is that it only seems to be working randomly. Sometimes I'll look at the current output (connected to a 250 ohm resistor) and it will be doing 1, 2, 3, and 4 volts as expected, other times it just stays at 1 V (4 mA). I checked the wiring several times, tried different SPI settings (modes and clock dividers) etc. Can't figure out what's going on. It'll work for a while, then I'll reboot the board, and nothing. Checked all my voltages (3.34V, 5.00V from Due, and 24.00V to Vcc on the AD420)
Any ideas/suggestions?
Also, I know this is the older style of SPI, I did it this way because I couldn't see anything about being able to specify a CS pin with the new style of coding.