Main Site Documentation

SPI configuration for AD420


#1

I’m trying to talk to Analog Devices AD420 using SPI, but it doesn’t work. What is the correct values to put i SPI.Configuration for this device?

Here is the datasheet for AD420: http://www.analog.com/static/imported-files/data_sheets/AD420.pdf


#2

Can you show some code showing how you tested it?

welcome to the community.


#3

First I need help to translate what is in the data sheet to the values that go into SPI.Configuration (I’m a software guy). And then I’am uncertain about the latch pin (chip select).

This is the test code with two different approaches.


using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;
using GHIElectronics.NETMF.Hardware;
using System.Threading;

namespace AD420
{
  public class Program
  {
    public static void Main()
    {
      //SpiOnly(0x00FF);
      SpiSeparateLatch(0x00FF);
    }

    public static void SpiOnly(ushort value)
    {
      ushort[] word = new ushort[1];
      SPI.Configuration config = new SPI.Configuration((Cpu.Pin)FEZ_Pin.Digital.IO28, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
      SPI spi = new SPI(config);

      word[0] = value;

      spi.Write(word);
    }

    public static void SpiSeparateLatch(ushort value)
    {
      ushort[] word = new ushort[1];
      OutputPort latch = new OutputPort((Cpu.Pin)FEZ_Pin.Digital.IO28, false);
      SPI.Configuration config = new SPI.Configuration(Cpu.Pin.GPIO_NONE, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
      SPI spi = new SPI(config);

      word[0] = value;

      latch.Write(false);
      spi.Write(word);
      latch.Write(true);
    }

  }
}


#4

Your config is correct, idle low with latch on high. ChipSelect can be automatically controlled by SPI drivers or you can control it manually using output port, either will work.

You problem maybe in how you write and read, not in setup. Some chips want CS low while writing/reading whole transactions, other want it to toggle on every byte!


#5

Hi Hallis,

we use components form Analog Devices a lot. Are you getting any data at all on the outputs? They often require you to reverse the bit order. This is what we use for a different dac from them (AD8803).

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

namespace VMC3.IO_Components
{
    class AD8803
    {
        private bool _ReverseData;
        private SPI.Configuration _Config;

        //Maak een nieuw component aan van het type AD8803
        // 1 parameter :  byte omdraaien
        public AD8803(SPI.Configuration Config, bool ReverseData)
        {
            this._Config = Config;
            this._ReverseData = ReverseData;
        }

        public void WriteOutput(byte Address, byte Value)
        {
            try
            {
                lock (Program._spi)
                {
                    Program._spi.Config = _Config;


                    byte[] cmdBuffer = new byte[2];

                    cmdBuffer[0] = Address;
                    cmdBuffer[1] = Value;

                    Program._spi.Write(cmdBuffer);

                }
            }
            catch (Exception ex)
            {
                Debug.Print("AD8803 line40 : " + "WriteOutput error: " + ex.Message);
            }

        }

        //Reverse bits in the byte. MSB becomes LSB
        private byte ReverseBits(byte data)
        {
            int output, mask;
            output = 0;
            for (int i = 0; i < 8; i++)
            {
                output <<= 1;
                mask = (int)System.Math.Pow(2, i);
                output |= (data & mask) >> i;
            }

            return (byte)output;
        }
    }
}

It is a separate class. We then initialize it with the following something like this:

   //SPI object
        public static SPI _spi;
        // SPI Configuratie declareren voor x DAC
        static private SPI.Configuration _DAC1_Config;
         //SPI instellen met de enable pins
        _DAC1_Config = new SPI.Configuration(EMX.Pin.IO31, false, 0, 0, false, true, 1000, SPI.SPI_module.SPI1);
        
        AD8803 DAC = new AD8803(_DAC1_Config, true);

Is there a reason why you choose this version (the AD420)?

Regards,

Per

EDIT : Sorry for the dutch words in the comments, but i think the code is pretty easy to understand :wink:


#6

Turns out that my code was working all the time. It was just me making som wrong calculations while testing. :-[

BTW, I’m using the AD420 because I need 4 - 20 mA current output to control a mixing valve actuator in a heating system.


#7

aaah, wel it is great to here that it works at least! But are you powering that valve directly from the DAC then? If a valve goes broken or gets a bit stuck it will start to draw more power and kill your dac. And isn’t your valve going to use a bit more then 20ma? I design a lot of electronics for HVAC and cooling systems, and our specs need te be a bit larger. But then again i don’t know the type of valve you are using ofcourse.

But good that it is working now!


#8

The actuator is the ESBE ARA639. http://www.esbe.se/gb/products/?prodid=4044
The DAC is not used to power the device.