AnsweredAssumed Answered

Ad9957 writing registers issue?

Question asked by anurag2508 on May 25, 2017
Latest reply on Sep 21, 2017 by LouijieC

I am trying to interface AD9957 with Arduino Due. I am supposed to sweep frequencies from 136MHz to 174MHz. 

Trying to write registers using Arduino SPI actually data is getting transferred with SPI but the responsible registers are not getting written. When I tried to read the values from registers its showing total number of bits which we are writing but not the values which we have transferred with SPI.

 

Being a beginner, i am not able to figure out, what the actual problem is? Please guide me.

 

#include <SPI.h>
#define IO_Update 6
#define IO_Reset 7

void setup()
{
Serial.begin(9600);
pinMode(IO_Update,OUTPUT);
delay(1);
digitalWrite(IO_Reset, HIGH);
delay(1);
digitalWrite(IO_Reset, LOW);

SPI.begin();
writeRegister(0x19,0x00);
writeRegister(0x19,0x00);
// SPI.setClockDivider(4);
// SPI.setDataMode(SPI_MODE0);
//SPI.setDataMode(MSBFIRST);
}
void loop()
{
//Register 19 Write
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x19); // Address 
SPI.transfer(0x00); //rest part is Data   sAme in every case
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// //Register 18 Write
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x18); //Address
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 16 Write
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x16); //Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 15 Write
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x15); //Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 14 write
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x14); //Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 13 Write
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x13);//Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 12
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x12);//Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 11
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x11);//Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 10
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x10);//Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 0F
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x0F);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 0E
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x0E);Address
SPI.transfer(0x3F);
SPI.transfer(0xFF);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x14);
SPI.transfer(0x7A);
SPI.transfer(0xE1);
SPI.transfer(0x48);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 0D
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x0D);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 0C
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x0C);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 0B
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x0B);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 0A
digitalWrite(IO_Update, HIGH);
SPI.transfer(0x0A);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 09
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x09);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0xFF);
SPI.transfer(0xFC);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 08
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x08);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 07
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x07);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 06
digitalWrite(IO_Update, HIGH);
SPI.transfer(0x06);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 05
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x05);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 04
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x04);Address
SPI.transfer(0xFF);
SPI.transfer(0xFF);
SPI.transfer(0xFF);
SPI.transfer(0xFF);
digitalWrite(IO_Update,LOW);
delay(1);

//Register 03
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x03);Address
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x7F);
SPI.transfer(0x7F);
digitalWrite(IO_Update,LOW);
delay (1);

//Register 02
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x02);Address
SPI.transfer(0x1D);
SPI.transfer(0x3F);
SPI.transfer(0x41);
SPI.transfer(0xC8);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 01
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x01);//Address

SPI.transfer(0x01);
SPI.transfer(0x40);
SPI.transfer(0x00);
SPI.transfer(0x20);
digitalWrite(IO_Update,LOW);
delay(1);

// Register 00
digitalWrite(IO_Update,HIGH);
SPI.transfer(0x00);//Address
SPI.transfer(0x01);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(IO_Update,LOW);
delay(1);
}

Outcomes