Page 1 of 1

Function generator using AD9835 with Raspberry Pi

Posted: Sun Dec 23, 2012 10:28 pm
by SiddharthSharma
I have a breakout board for AD9835 by sparkfun. I am trying to interface it with a Raspberry Pi. Since the chip has 5V SPI, I am using a level shifter(3.3v of Rpi to 5V). All other pins(SS,SCK) work fine, but when i connect the MOSI pin of RPi to the input of level shifter, it inverts the MOSI logic. Gives HIGH on a 0 and LOW on a 1. Why is this happening?

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);
}

Re: Function generator using AD9835 with Raspberry Pi

Posted: Wed Dec 26, 2012 4:11 pm
by techpaul
How are you powering the Sparkfun board?

I have used it before and it needs a 6V to 9V power in. Unless like me you are willing to modify the board.
Unlkess you modify the board to get correct power in you will have stange effects.

Re: Function generator using AD9835 with Raspberry Pi

Posted: Thu Jan 03, 2013 4:08 pm
by SiddharthSharma
after reading your post I gave it 9V by using a 7809 voltage regulator. Still the frequency getting latched is random and does not vary according to the code.

I also tried to use the AD75019, which is a 16x16 crosspoint switch matrix through the raspberry pi. i send 16x16 = 256 bits through SPI to program the 256 switch states. Its works well when i use arduino. But does not work if i use the raspberry pi. To program this chip the slaveselectpin has to give low pulse after 256 bits have been sent, and it remains high till all the 256 bits are sent. For this I use GPIO25 as slaveselectpin. But the slaveselectpin signal is incorrect.

Is anyone else getting problems with SPI in the RPi? Could it be a fault in the arduPi library??