Arduino Due SPI issue with AD420 DAC

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.

thatcadguy:
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.

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.

There is a warning on page 7 of the Data Sheet.

Could this be catching you?

maybe if you add 470pf to the SPI lines

Chuck.

Thanks Chuck, I'll try that on Monday.

Also, I read that SPI is for shorter distances...I'm using 6 inch long jumpers to go from the Due to a breadboard, is this too long?

thatcadguy:
Thanks Chuck, I'll try that on Monday.

Also, I read that SPI is for shorter distances...I'm using 6 inch long jumpers to go from the Due to a breadboard, is this too long?

How fast is setDivisor(168)? I calc it as 500k?

Wire length usually causes transmission problems because of the additional capacitance. And the highspeed square wave signal creates a lot of ringing, bounding from overshooting to undershooting the expected level. The Due drives the signals with a really fast dV/dt. All transmission driver circuits normally control the maximum rate of voltage change per unit time to reduce echos and reflections generated. These echos can be interpreted as valid signals if they have a large enough amplitude. The warning in the Data sheet recommends adding the capacitance to slow the rate of change.
That sensor's Datasheet specs's the SCK speed down to 0, so unless you really need 30k updates per second, you could probably reduce it down to see if that changes the responses.

a setDivisor(255) would get you down to 20.5k update rate.

Or you could even bit bang it your self.

Chuck.

470 pF caps didn't work, next stop bit-banging I guess.