Go Down

Topic: Function generator using AD9835 with Raspberry Pi (Read 2440 times) previous topic - next topic

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. All other pins 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?

#1
Dec 23, 2012, 11:09 pm Last Edit: Dec 23, 2012, 11:15 pm by siddharthsharma52 Reason: 1
PS.: the same code works perfect on arduino.
     I am using arduPi library in rpi.


::::::The Code::::::

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) {

 digitalWrite(SlaveSelectPin, LOW);
 SPI.transfer(byte1);
 SPI.transfer(byte2);
 digitalWrite(SlaveSelectPin,HIGH);
}




PaulS

You have an Arduino problem you want to talk about?

the code works for arduino, but not for raspberry pi.

Boffin1

Quote
PS.: the same code works perfect on arduino.


thats cool then  ( this is an Arduino forum.......... )


michael shiloh

You might ask this question on a Raspberry Pi forum or mailing list. There may be some esoteric behavior of the SPI port on the Pi that we Arduino users are less likely to know about.

Good luck!

I did. waiting for replies.

I have been stuck on this problem for more than a week now! The library i use makes arduino codes compatible on raspberry pi. I have no idea why the MOSI pin is behaving this way!

robtillaart

Quote
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.

so obvious this is not the solution.

The source you provided does compile (after an #include and creating a global int for slaveselect) on my 1.0 but as I have no ad9835 I connet test it further.
Do you have the link to the datasheet you used? of the ad9835 ?
There might be a bug in the arduPi library which does "flip" the MOSI ?
Have you got other SPI based sketches running properly?


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)


Quote
The source you provided does compile (after an #include and creating a global int for slaveselect) on my 1.0 but as I have no ad9835 I connet test it further.



The source code i uploaded was is the arduino code. for raspberry pi i removed the # define SlaveSelectPin, actually it does not make a difference because the slaveselect pin is fixed on the pi.

Even I thought the ardupi may have some bugs. but i tested it for other basic SPI, and SPI works fine!
I have used a npn transistor as inverter to get the original MOSI signal back and the signal now is correct. Now i am getting correct signals of MOSI,SCLK,SS. So basically all signals are as required, but still no ouput. I am guessing the problem might be with the frequency of SPI. will try all permutations and combinations. Hope it works. Will update,

here the llink to AD9835 datasheet ::  http://www.analog.com/static/imported-files/data_sheets/AD9835.pdf

Go Up