north2012
Member level 3
- Joined
- Apr 1, 2013
- Messages
- 63
- Helped
- 1
- Reputation
- 2
- Reaction score
- 1
- Trophy points
- 1,288
- Activity points
- 1,813
Hi all,
I am using AD5231 with ATmega32 but I have problem to set wiper. Here is my code. Does anyone can see where is error because the resistance does not change whatever I send as command for wiper. I checked all hardware connections and everything seems to be good.
Thanks in advance.
I am using AD5231 with ATmega32 but I have problem to set wiper. Here is my code. Does anyone can see where is error because the resistance does not change whatever I send as command for wiper. I checked all hardware connections and everything seems to be good.
Code:
//#include<built_in.h>
sbit CLK at PORTB7_bit;
sbit CLK_Direction at DDB7_bit;
sbit DAT at PORTB5_bit;
sbit DAT_Direction at DDB5_bit;
sbit CS at PORTA4_bit;
sbit CS_Direction at DDA4_bit;
void set_pot(void)
{
unsigned char i = 0;
unsigned char cmd[3];
unsigned long send = 0xb00300;
CLK = 1; CLK = 1;
CS = 0; CS = 0;
for(i=0; i<24; i++)
{
if(send & 0x800000)
{
DAT = 1;
}
else
{
DAT = 0;
}
CLK = 0; CLK = 0;
send = send << 1;
CLK=1; CLK=1;
}
CS = 1; CS = 1;
}
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)
{
}
}
Thanks in advance.