Ad7787 Questions on setup and usage

Hi people,

I have just bought an AD7787 and am looking to interface it to a Microcontroller.   Does anyone have any example code for getting the device up and running. 

I have had a look at the datasheet and there isn't a section with some example code.  I also couldn't find what SPI mode the device is - I'm guessing it's mode 2 (CPOL=1 and CPHA = 0) from the timing diagrams.  What is the Bit order - MSB or LSB first?

What I would like is some example code to do the following:

1.  Set the SPI Mode, Bit order and SPI clock speed for the AD7787

2.  Set the device up for unipolar operation with the buffer activated.

3.  Read from the AN0 input and display the result in decimal.

I am using an Atmel AVR328p with an arduino bootloader as the micro with a 2.5V reference supplied from a REF03. 

Cheers

Alex

  • Hi Alex,

    I do not have sample code for the AD7787. However, attached is some sample code for the AD7791 which is very similar to the AD7787. The AD7791 has one diff input only while the AD7787 has one diff input and one single ended input. However, the register layout is very similar on the 2 parts.

    Regards,

    Mary.

    ExampleCode_ADC_AD7791.zip
  • Hi people!

    I just bought an ad7787 and I cant get it running.I have read the code you attached but Im having some troubles understanding it, probably because my knowledge about C is not that good. Anyway, I have connected the device to a atmega1281 that I have used a lot, by the SPI. I can see in my oscilloscope that when I send my commands to comm register the sclk and cs lines are correct but the data is not.

    Then I try to read the data register but the value I get is 0x80 no matter what value is on the AIN2.

    I attached my scheme and my code.

    Cheers,

    Dan.

    /*

    * Prueba del ADC con el mote

    * Created: 30/07/2012 10:05:44

    * Author: Daniel

    */

    #include <avr/io.h>

    #include <avr/interrupt.h>

    #include <avr/power.h>

    #include <util/delay.h>

    #define F_CPU 4000000UL //4 MHz

    #include <avr/sfr_defs.h>

    //Variables globales

    unsigned char data=0x3D,aux2,aux4;

    int adc=0x00;

    //Mis funciones

    void SPI_MasterInit(void);

    void _delay_ms (double __ms);

    writetoreg(unsigned char data);

    int readfromreg();

    int main(void)

    {

    //Configurar puertos e inicializar

                 SPI_MasterInit();

                 sei();

                

           while(1)

        {

                 data=0x3D; //continuous mode - ain2(single ended)

                 writetoreg(data); //write to comm register

                 adc = readfromreg();//read data

                 }

    }

    void SPI_MasterInit(void)

    {

    /* Set MOSI,SS and SCK output, all others input */

    DDRB = (1<<DDB1)|(1<<DDB2)|(1<<DDB0)|(1<<DDB4)|(1<<DDB5);

    PORTB = (1<<PB0)|(1<<PB4)|(1<<PB2);//fsync disp1

    /* Enable SPI, Master, set clock rate fck/16 , MSB first*/

    SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0)|(0<<DORD)|(1<<CPOL)|(0<<CPHA);

    }

    writetoreg(unsigned char data)

    {

           PORTB = (0<<PB0)|(1<<PB4)|(1<<PB5);//cs low

                 // Start transmission

                 SPDR = data;

                 // Wait for transmission complete

                 while(!(SPSR & (1<<SPIF)));

                 aux2 = SPSR;

           PORTB = (1<<PB0)|(1<<PB4)|(1<<PB5);// cs high

    }

    int readfromreg()

    {

           PORTB = (0<<PB0)|(1<<PB4)|(1<<PB5);//cs low

           // Start transmission

           while(!(SPSR & (1<<SPIF)));

           adc = SPSR;

           PORTB = (1<<PB0)|(1<<PB4)|(1<<PB5);// cs high

           return adc;

    }