-2

The code below produces the error:

ssPin was not declared in this scope

This error is repeated for all elements of DDS, i.e. ssPin, resetPin, updatePin, ps0, ps1 and osk

Can anyone spot the problem?

#include <SPI.h>
#include <AD9954.h>
AD9954 DDS(ssPin, resetPin, updatePin, ps0, ps1, osk);

void setup() {
SPI.begin();
SPI.setClockDivider(4);
SPI.setDataMode(SPI_MODE0);
delay(500); // let things get set up...

DDS.initialize(400000000); // initialize DDS with 400 MHz clock

}

void loop() {

 DDS.setFreq(25000000); // set DDS to 25 MHz
  delay(2000);

}
0

The line:

AD9954 DDS(ssPin, resetPin, updatePin, ps0, ps1, osk);

does not have any content above it which declares that those variables exist. You can declare them like

const uint8_t ssPin, resetPin, updatePin, ps0, ps1, osk;

You'll likely also want to assign values to them, corresponding to the pins being used:

const uint8_t ssPin=4, resetPin=5, updatePin=6, ps0=7, ps1=8, osk=9;

(the actual values should be the pin numbers being used in your particular case.)

The file AD9954.h declares these variable names as private inside the class. They aren't available for use outside the class. The call to DDS(...) is the constructor, where you pass in pin definitions, and the values get assigned to those variables inside the class. But you can pass in literals or other variables in the constructor. You could even declare the same variable names in your main source file, but you can't ever directly access private variables from outside the class.

  • Thanks. However, when I look through AD9954.h I see that the variables have been declared as private within the AD9954 class but it doesn't seem to pick these up. – Mike Richards Aug 23 '18 at 19:26
  • Right, they are private to the class. They aren't available for use outside the class. The call to DDS(...) is the constructor, where you pass in pin definitions, and the values get assigned to those variables inside the class. But you can pass in literals or other variables in the constructor. You could even declare the same variable names in your main source file, but you can't ever directly access private variables from outside the class. – jose can u c Aug 23 '18 at 19:30
  • Ok, thanks for the very clear explanation, I understand the problem now. I've not done any Arduino work for a while so need to get my brain back in gear. Thanks. – Mike Richards Aug 23 '18 at 19:45
  • As a final comment on this, the line in question (AD9954 DDS(ssPin, resetPin, updatePin, ps0, ps1, osk);) is used to pass the actual Arduino pin numbers for those pin assignments to the object. In the working version I used the following line: AD9954 DDS(2, 3, 4, 5, 6, 7); – Mike Richards Aug 27 '18 at 21:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.