Hi everyone, so I have been banging my head on this for a couple days and I cant figure it out. Pretty much I want a 3MHz sine wave output (but at this point will take any frequency).
I think that my problem is in the initialization, because I can see the SPI data on the SDATA pin, but I just dont get any output.
Any help with this would be great.
My code is shown below
#include <SPI.h>
//const int On_Board_LED = 25;
const int RST = 2;
const int FSYNC1 = 10; // 5 on the pico
void setup() {
// put your setup code here, to run once:
pinMode(LED_BUILTIN, OUTPUT);
pinMode(RST, OUTPUT);
pinMode(FSYNC1, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
digitalWrite(RST, HIGH); //set reset high (1) as per data sheet
digitalWrite(FSYNC1, HIGH);
SPI.begin();
SPI.beginTransaction(SPISettings(5000000, MSBFIRST, SPI_MODE2));
AD_RESET();
AD_FREQ();
AD_ENABLE();
delay(500);
digitalWrite(RST, LOW); //Now that we are ready to generate output set to 0 (LOW)
}
void AD_RESET(){
digitalWrite(FSYNC1, LOW);
SPI.transfer(0x21); //MSB These 2 are for control register
SPI.transfer(0x00); //LSB
digitalWrite(FSYNC1, HIGH);
delay(10);
digitalWrite(FSYNC1, LOW);
SPI.transfer(0x50); //These 2 are for frequency register 0 LCB
SPI.transfer(0xC7);
SPI.transfer(0x40); //These 2 are for frequency register 0 MSB
SPI.transfer(0x00);
delay(10);
SPI.transfer(0x82);
SPI.transfer(0x7E); //These were a test from some code I saw online
SPI.transfer(0xBE); //Not sure where the values come from though
SPI.transfer(0x3F);
SPI.transfer(0x20); //These two Lines Exit Reset
SPI.transfer(0x00);
}
void AD_FREQ(){
//digitalWrite(On_Board_LED, HIGH);
digitalWrite(FSYNC1, LOW);
//These 4 SPI trasfer lines are for setting the frequency
//Refer to the Data sheet for how this is done
SPI.transfer(0x7B);
SPI.transfer(0x60);
SPI.transfer(0x7F);
SPI.transfer(0x7C);
//This is setting the phase of the signal to 0 phase adjustment
SPI.transfer(0x00);
SPI.transfer(0x00);
digitalWrite(FSYNC1, HIGH);
}
void AD_ENABLE(){
digitalWrite(FSYNC1, LOW);
SPI.transfer(0x22);
SPI.transfer(0x00);
digitalWrite(FSYNC1, HIGH);
}
void loop() {
// put your main code here, to run repeatedly:
digitalWrite(LED_BUILTIN, HIGH);
}
just for your info FSYNC1 IS CS/SS
and RST is reset
Edit: Here is a link to the AD9834 Application Note which is where I got the HEX values, page 3 table 1: https://www.analog.com/media/en/technical-documentation/application-notes/an-1070.pdf