AD9910 External control With Arduino

Hey people ,

I'm try load the registers of AD9910 with a Mbed but isn't work. Now i'm try with Arduino uno, anyone knows a code for a load control AD9910 !?

Thanks a lot

Hetan

The AD9910 seems to have an I2C interface by default, usable with the Wire library.

The AD9910 Have SPI , but i dont known how programing !

You can use the SPI library. You transfer a command byte, then read or write the required number of bytes for that command.

How can i send a 32 bits word through SPI ?

Do 4 transfers:

digitalWrite (ssPin, LOW);
SPI.transfer (byte0);
SPI.transfer (byte1);
SPI.transfer (byte2);
SPI.transfer (byte3);
digitalWrite (ssPin, HIGH);

or
digitalWrite (ssPin, LOW);
SPI.transfer (dataArray[0]);
SPI.transfer (dataArray[1]);
SPI.transfer (dataArray[2]);
SPI.transfer (dataArray[3]);
digitalWrite (ssPin, HIGH);
or use other methods to break up an unsigned or signed long,
or ...

But 4 transfers no matter what.

Hetan97:
The AD9910 Have SPI , but i dont known how programing !

#define SPI_MOSI_PIN MOSI
#define SPI_MISO_PIN MISO
#define SPI_SCK_PIN SCK
#define DDS_CS SS
#define MASTER_RESET 11
#define IO_RESET 6
#define IO_UPDATE 4

SPISettings spiSettings;

#define CFR1 0x00
#define CFR2 0x01
#define CFR3 0x02

static void digitalWriteDirect(int pin, boolean val)
{
digitalWrite(pin, val);
}

static inline int digitalReadDirect(int pin)
{
return digitalRead(pin);
}

void update()
{
digitalWriteDirect(IO_UPDATE, LOW);
//Special update used to maximize speed of update
digitalWriteDirect(IO_UPDATE, HIGH);
// if (!fastUpdate)
{
delayMicroseconds(1);
}
digitalWriteDirect(IO_UPDATE, LOW);
}

void set4Wire()
{
//CFR1 values needed for 4 wire mode
byte set4Wire[4] = {0x00, 0x00, 0x00, 0x02};

resetSPI(); //Reset physical communications (precautionary)
writeReg(CFR1, set4Wire, sizeof(set4Wire)); //Write values to buffer
update(); //Update buffer values into register
}

void sendWriteAddr(int addr)
{
SPI.beginTransaction(spiSettings);
digitalWrite(DDS_CS, LOW);
SPI.transfer(addr);
}

void sendReadAddr(int addr)
{
SPI.beginTransaction(spiSettings);
digitalWrite(DDS_CS, LOW);
SPI.transfer(0x80 | addr);
}

void writeBytes(byte addr, byte *data, byte length, byte start)
{
int tmp = 3;

sendWriteAddr(addr);
if (length <= 4)
tmp = len;

for (byte i = start; i < tmp-1; i++)
{
SPI.transfer(data*);*

  • }*
  • SPI.transfer(data[length - 1]);*
  • if (length > 4)*
  • {*
  • //32 bit register length*
  • digitalWrite(DDS_CS, HIGH);*
  • SPI.endTransaction();*
  • writeBytesREndian(data, byte length, 4); //to be test*
  • }*
  • digitalWrite(DDS_CS, HIGH);*
  • SPI.endTransaction();*
    }
    void writeBytesREndian(byte *data, byte length, byte start)
    {
  • for (byte i = start; i > start - (length - 1); i--)*
  • {*
    _ SPI.transfer(data*);_
    _
    }_
    _
    SPI.transfer(data[start - (length - 1)]); _
    _
    }_
    void readReg(byte addr, byte *data, int length)
    _
    {_
    _
    sendReadAddr(addr);_
    _
    for (byte i = 0; i < length - 1; i++)_
    _
    {_
    _ data = SPI.transfer(0);
    }
    data[length - 1] = SPI.transfer(0);_
    digitalWrite(DDS_CS, HIGH);
    _ SPI.endTransaction();
    }
    void DDSdefaultReset()
    {_
    digitalWrite(MASTER_RESET, HIGH);
    _ delay(100);_
    digitalWrite(MASTER_RESET, LOW);
    _ delay(1);
    }
    void resetSPI()
    {_
    digitalWrite(IO_RESET, HIGH);
    _ delay(10);_
    digitalWrite(IO_RESET, LOW);
    _ delay(1);
    }
    void setup() {
    ....._
    pinMode(DDS_CS, OUTPUT);
    digitalWrite(DDS_CS, HIGH);
    pinMode(SPI_MISO_PIN, INPUT);
    pinMode(SPI_MOSI_PIN, OUTPUT);
    pinMode(SPI_SCK_PIN, OUTPUT);
    _ SPI.begin(); //Start SPI on chip select pin for AD9910*
    * spiSettings = SPISettings(40000000UL, MSBFIRST, SPI_MODE0);*
    * DDSdefaultReset();
    set4Wire(); //Function to put AD9910 in wire SPI mode*
    * resetSPI(); //Reset physical communications (precautionary)
    .....*_