AnsweredAssumed Answered

AD7322 + SPI

Question asked by Flanbix on Nov 8, 2011
Latest reply on Dec 16, 2011 by ShaneO

Hi,

 

I am trying to have these ADC working with my PIC but I am having trouble doing it.

Here is my code:

 

ADCs Init

 

 

void Init_ADC(void)
{
CS_AD7322_0=0;
Nop();
Nop();
WriteSPI2(0b10100000);     // Range register  -12/+12
WriteSPI2(0b00000000);    
Nop();
Nop();
CS_AD7322_0=1;
Nop();
Nop();
CS_AD7322_0=0;
Nop();
Nop();
WriteSPI2(0b10000000);     // Control register, Single Ended
WriteSPI2(0b00101000);     // Binary Coding, Sequencer enabled, External reference
Nop();
Nop();
CS_AD7322_0=1;
CS_AD7322_1=0;
Nop();
Nop();
WriteSPI2(0b10100000);      // Range register  -12/+12
WriteSPI2(0b00000000);
Nop();
Nop();
CS_AD7322_1=1;
Nop();
Nop();
CS_AD7322_1=0;
Nop();
Nop();
WriteSPI2(0b10000100);     // Control register, Single Ended
WriteSPI2(0b00101100);     // Binary Coding, Sequencer disabled, External reference
Nop();
Nop();
CS_AD7322_1=1;
}

 

 

 

And to read my ADCs

 

 

if(Channel==0)

          {

          SDO2=0;

          CS_AD7322_0=0;                         // CS ON

          Nop();

          Nop();

          Nop();

          result[0]=ReadSPI2();

          result[1]=ReadSPI2();

          Nop();

          Nop();

SDO2=1;

          Nop();

          CS_AD7322_0=1;                         // CS OFF

          Delay100TCYx(1);

          putc2USART(result[0]);

          while(Busy2USART());

          putc2USART(result[1]);

          while(Busy2USART());

          }

          else if(Channel==1)

          {

          SDO2=0;

          CS_AD7322_1=0;                         // CS ON

          Nop();

Nop();

          Nop();

          result[0]=ReadSPI2();

          result[1]=ReadSPI2();

          Nop();

          Nop();

SDO2=1;

          Nop();

          CS_AD7322_1=1;                         // CS OFF

          Delay100TCYx(1);

          putc2USART(result[0]);

          while(Busy2USART());

          putc2USART(result[1]);

          while(Busy2USART());

          }

 

At the moment the result form the ADC with the sequencer enabled are 1F 71 which is strange as the channel number should be changing. Also the voltage I have at the moment is IN0 is 1.3mV and IN1 is 184.5mV. F71 => 3963 in decimal is way to big then.

 

For the second ADC as I select IN0 or IN1 in the control register, it gave me 20 3F.

See the image for the read (1=> SCK, 2=> SDI, 3=> CS)

 

Any ideas?

 

Regards.

Attachments

Outcomes