I am trying to communicate with a AD9834 DDS, after banging my head against the wall all weekend I connected the SPI lines to the scope and found that the MOSI line is outputing less than 1V P-P. See image. I have checked my probes they are all 10:1 and set correctly in the scope. I have tried not initializing MOSI, SS, and SCLK and I have tried initializing them. I have set there state and then initialized and then vice versa, still nothing. I have tried with the AD9834 connected and disconnected also, to no avail.
Also, ive tried with different ATMEGA328's and still have had no luck.
I have also tried running the code once in the setup, and then I have tried in the main loop with an if statement.
I should note that this is my first time using SPI and there may be something totally obvious im missing.
Any help?
#include <SPI.h>
int i =0;
void setup() {
Serial.begin(9600);
SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV32);
digitalWrite(SCK, LOW);
digitalWrite(MOSI, LOW);
digitalWrite(SS, HIGH);
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
pinMode(SS, OUTPUT);
//pinMode(ss, OUTPUT);
//pinMode(11, OUTPUT);
//pinMode(10,OUTPUT);
//hpinMode(13,OUTPUT);
SPI.setDataMode(SPI_MODE1);
SPI.setBitOrder(MSBFIRST);
delay(100);
Serial.println("Initilized");
}
void loop() {
if(i <2){
delay(100);
digitalWrite(SS, LOW);
//delay(50);
SPI.transfer(0x21); //Write MSB to control reg
SPI.transfer(0x00); //Write lsb to control register
digitalWrite(SS, HIGH);
delay(10);
digitalWrite(SS, LOW);
//delay(50);
SPI.transfer(0x50);
SPI.transfer(0xC7);
SPI.transfer(0x40);
SPI.transfer(0x00);
// digitalWrite(SS, HIGH);
delay(10);
//digitalWrite(SS, LOW);
SPI.transfer(0x82);
SPI.transfer(0x7E);
SPI.transfer(0xBE);
SPI.transfer(0x3F);
// digitalWrite(SS, HIGH);
delay(10);
//digitalWrite(SS, LOW);
// delay(50);
SPI.transfer(0x20);
SPI.transfer(0x00);
digitalWrite(SS, HIGH);
i++;
Serial.println("In if");
//delay(100);
// put your main code here, to run repeatedly:
}
delay(10);
//Serial.println("loops!");
}