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 support@ccsinfo.com

AD5258 digital pot driver

 
Post new topic   Reply to topic    CCS Forum Index -> Code Library
View previous topic :: View next topic  
Author Message
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

AD5258 digital pot driver
PostPosted: Sun Mar 09, 2008 5:01 pm     Reply with quote

A small driver for the AD5258 digital potentiometer with I2C interface.

Code:

void i2c_init(
   int8 iAddr)      // [in] address of the target I2C device with R/W# bit
// PURPOSE:        Initiate the I2C transaction
// PRECONDITIONS:  I2C bus is free.
// POSTCONDITIONS: I2C transaction is initiated.  The target chip is addressed.
//                 The code, which has called i2c_init(), is responsible for ending the i2c transaction w/ i2c_stop().
//                 If i2c transaction didn't initialize, the error flag is set.
//                 The code, which has called i2c_init(), has to check the error flags at some point.
{
   int8 i;   // loop counter

   i = 0;
   do
   {
      i2c_start();
      ++i;
      delay_ms(1);
   }
   while (i < I2C_TIMEOUT && i2c_write(iAddr) == 1); // 0 returned for ACK

   if (i >= I2C_TIMEOUT)
   {
      g_sSystemValues.Errors |= E_I2C;
   }
}  // i2c_init()


void set_pot_AD5258(
   int8 iAddr,       // [in] I2C slave address of the AD5258 digital pot
   int8 iPotVal)     // [in] potentiometer position (AD5258 has 64 positions)
// PURPOSE: Set the value of the AD5258 digital pot
{
   i2c_init(iAddr | I2CWRITE);
   i2c_write(0x00);        // instruction byte
   i2c_write(iPotVal);     // wiper position
   i2c_stop();
}

_________________
Read the label, before opening a can of worms.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> Code Library 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