CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

pic spi and ad8400

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
cyril_fr



Joined: 25 Sep 2005
Posts: 1

View user's profile Send private message

pic spi and ad8400
PostPosted: Sun Sep 25, 2005 12:07 pm     Reply with quote

hi i need your help

I want to write a value from a pic to an AD8400 (digital potentiometer) via spi but that doesn't work i have the correct signals but the ad8400 doesn't work correctely

doc of the
AD8400

my code
Code:

#use delay (clock = 4194304) //Using 4Mhz External clock
#fuses HS, NOWDT, NOPROTECT, NOLVP
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#define CS_SPI      PIN_B2


void main ()
{

int8 Data0,Data1,Analog;
int16 Data;

setup_spi (SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_64);

output_high(CS_SPI);

analog= 0x00;


while(TRUE){
   {
   data=0;
   data=data | analog;
   data=data << 6;

   data1=data & 0xff;//lsb
   data0=(data >> 8) & 0xff;//msb

         output_low(CS_SPI);
         delay_us(100);
         spi_write(Data0);
         delay_us(150);
         spi_write(Data1);
         delay_us(150);
         output_high(CS_SPI);

   delay_ms(5000);
   analog = analog + 0x10;

}
}
}


thanks
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Sep 25, 2005 12:20 pm     Reply with quote

Why don't you use the CCS driver, AD8400.C ?
It's in this folder:
c:\Program Files\Picc\Drivers


If just have the demo compiler, then you won't have the drivers. In that
case, then use http://www.google.com to search for these keywords:
AD8400 CCS

Then you will find it.
akworob
Guest







PostPosted: Thu May 21, 2009 6:09 am     Reply with quote

Just remove line

Code:
data=data << 6;


This because device takes 10 last bits as value (not first 10bits!)
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group