To solve this I connect the MOSI pin directly to the ad9835 SDATA pin. No matter whatever frequency word i send(32 bit word), the frequency is stuck on 5MHz. Is it because MOSI level is 3.3v and its not getting detected?
The code i use works perfectly fine for arduino.
PS.: i am using arduPi library.
Code: Select all
//Include ArduPi library
#include "arduPi.h"
//Needed for Serial communication
SerialPi Serial;
//Needed for accesing GPIO (pinMode, digitalWrite, digitalRead, I2C functions)
WirePi Wire;
//Needed for SPI
SPIPi SPI;
void AD9835write(unsigned long frequency);
void SPIwrite(int byte1, int byte2);
void setup() {
Serial.begin(9600);
SPI.begin();
SPI.setDataMode(SPI_MODE1);
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV64);
SPIwrite(0xF8, 0x00);
AD9835write(10000);
}
void loop(){
}
void AD9835write(unsigned long frequency) {
unsigned long temp = 0;
temp = 0xFFFFFFFF/50000000*frequency;
SPIwrite(0xC0, 0x00);
SPIwrite(0x90, 0x00);
SPIwrite(0x33, ((temp & 0xFF000000) >> 24));
SPIwrite(0x22, ((temp & 0x00FF0000) >> 16));
SPIwrite(0x31, ((temp & 0x0000FF00) >> 8));
SPIwrite(0x20, ((temp & 0x000000FF)));
SPIwrite(0x50, 0x00);
}
void SPIwrite(int byte1, int byte2) {
SPI.transfer(byte1);
SPI.transfer(byte2);
}
int main (){
setup();
while(1){
loop();
}
return (0);
}