AnsweredAssumed Answered

What is wrong with my code regarding spi interface with AD7190 pLease Help?

Question asked by Mayer on Feb 23, 2013
Latest reply on Mar 5, 2013 by J.Gealon

Dear All

 

I have a problem interfacing with the part AD7190

 

which is a 4 wire spi interfacing analog to digital converter with a 4.8 khz data output rate and a 24 bit ultra low noise resolution

 

The problem is that i donot have an automatic function in my controller that can generate the spi strokes and write and read my data automatically so i have to implement it myself and i did it with a simple c function on Keil burnt on a cypress semiconductor usb interface with a 8051 core.....but the problem is whenever i read what i have just written i read zeros which indicates that the writing process didnot go successfully

 

i implemented this write fun

 

with a four bytes to be written which are temp, temp1,temp2,temp3. temp is for the communication register and it carries 0x08 to write on the mode register and the rest are just settings on the mode register

and k and i are just integers

 

{

                            cs=1;

                            cs=0;

 

                                             for(i=0;i<8;i++)

                                           {

                                           clk=0 ;

                                           clk=1 ;

                                           if((temp)&0x80)

{din=1;}

else{din=0;}

                                        temp=temp<<1;

                                        k++;           }

 

                                                     for(i=0;i<8;i++)

                                           {

                                           clk=0 ;

                                           clk=1 ;

                                           if((temp1)&0x80)

{din=1;}

else{din=0;}

                                        temp1=temp1<<1;

                              k++;                     }

 

                                                     for(i=0;i<8;i++)

                                           {

                                           clk=0 ;

                                           clk=1 ;

                                           if((temp2)&0x80)

{din=1;}

else{din=0;}

                                        temp2=temp2<<1;

                              k++;                     }

 

                                                     for(bn=0;bn<8;bn++)

                                           {

                                           clk=0 ;

                                           clk=1 ;

                                           if((temp3)&0x80)

{din=1;}

else{din=0;}

                              temp3=temp3<<1;

                                        k++;           } cs=1;

                                                       }

 

 

and i implemented this function to read the mode register by writting 0x48 first to the communication register and then read a 24 bit mode register  and that when the problem happens it reads zeros.......!!!!!!

{  cs=0;

 

   for(i=0;i<8;i++)




   {




   clk=0 ;




   clk=1 ;




   if((temp)&0x80)

{din=1;}

else{din=0;}






temp=temp<<1;

k++; }

  

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein1 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein2 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein3 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein4 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein5 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein6 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein7 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein8 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein9 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein10 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein11 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein12 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein13 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein14 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein15 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein16 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein17 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein18 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein19 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein20 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein21 = dout ;

clk = 0 ;

k++;

 

 

clk = 1;

k++;

 

 

takein22 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein23 = dout ;

clk = 0 ;

k++;

 

 

clk = 1 ;

k++;

 

 

takein24 = dout ;


  

b1=(((takein1)*128)+((takein2)*64)+((takein3)*32)+((takein4)*16)+((takein5)*8)+((takein6)*4)+((takein7)*2)+((takein8)*1));

b2=(((takein9)*128)+((takein10)*64)+((takein11)*32)+((takein12)*16)+((takein13)*8)+((takein14)*4)+((takein15)*2)+((takein16)*1));

b3=((((takein17)*128)+((takein18)*64)+((takein19)*32)+((takein20)*16)+((takein21)*8)+((takein22)*4)+((takein23)*2)+((takein24)*1))); 


  

cs=1;   }

 

and whenever i receive b1 or b2 or b3 they are always zeros .....?

 

Any help suggested ? did i write or read in a wrong sequence please any help is highly appreciated

 

Thank you,

Outcomes