AnsweredAssumed Answered

AD5231 with AVR

Question asked by north on Aug 6, 2013
Latest reply on Aug 9, 2013 by musach

Hi,

 

I am trying to connect AD5231 with ATmega128 but there is no response to commands and resistance stays always at mid scale...

My hardware connections are:

Vcc-#WP, #PR and Vdd

GND - Gnd, Vss, T, B

SDI- DAT

CLK - SCK

#CS - #CS

 

here is my code

 

sbit CLK at PORTA1_bit;

sbit CLK_Direction at DDA1_bit;

sbit DAT at PORTA2_bit;

sbit DAT_Direction at DDA2_bit;

sbit CS at PORTA0_bit;

sbit CS_Direction at DDA0_bit;

 

void set_pot(void)

{

   unsigned char i = 0;

   unsigned long send = 0xb00300;

   send = 0x00b00300;

   CLK = 1;

   asm nop;

   CS = 0;

   asm nop;

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

   {

    if(send & 0x800000)

    {

    DAT = 1;

    asm nop;

    }

    else

    {

    DAT = 0;

    asm nop;

    }

    CLK = 0;

    asm nop;

    send = send << 1;

    CLK=1;

    asm nop;

    }

CS = 1;

asm nop;

}

 

void main()

{

  DAT_Direction = 1;     // define as output

  CLK_Direction = 1;     // define  as output

  CS_Direction = 1;     // define as output

  delay_ms(50);

  set_pot();

  while(1)

  {

  }

}

Outcomes