AD7322 + SPI

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.

  • 0
    •  Analog Employees 
    on Nov 8, 2011 9:20 PM

    Hi-

    I moved this question related to the AD7322 to the Precision ADCs community.  Please continue the discussion here.

    Thanks,

    AndyR

    EngineerZone Community Manager

  • 0
    •  Analog Employees 
    on Nov 14, 2011 11:18 PM

    Can you confirm the configuration for the SPI interface is as per Figure 2 in the datasheet?

    The address bit, ADD2, is propagated on the /CS falling edge and the subsequent bits on the SCLK falling edges. The data must therefore be read on an SCLK falling edge.

    For the plot you posted the data may I believe be 0x101F not 0x203F.

    The sequence mode you are setting up is "10" from the code in your post. This mode stops at the channel programmed in the channel address bit in the control register which in you case is programmed as channel 0. This means the device is not setup to sequence through both channels.

    You should program ADD0 to be "1" in the control register.

  • I think the SPI mode is correct as data is ready when the falling edge occurs.

    See graph for the Range register (10V Range) (0xA000) and the Control register (0x820C) (Fully Differential mode, Channel 0, Twos complements coding, Sequencer disable)

    But it is for the reading part which I am unsure.

    My first ADC (Fully Differential mode) seems to give convincing results:

    - +100mV => 0x0020 => +93.75mV

    - -100mV => 0x3FE0 => -93.72mV

    But the second one (Single Ended mode)

    - +100mV => 0x7FE4

    - -100mV => 0x7F60

    As the first bit is clocked out on the falling edge of /CS does the 16 read bit need to be shifted to right?

    But even shifted, the results of the second one don't make any sense...

  • 0
    •  Analog Employees 
    on Nov 15, 2011 9:45 PM

    For the AD7322 when reading the result the first 2 MSBs should always be zero. So there is definitely something wrong if you are reading back 0x7FE4.

    You should verify your SPI interface settings.